2014-09-24 59 views
0

你好我有一個問題,選擇一個值形成我的表到在PHP中的變量,這樣我可以計算的東西選擇值到

這裏的成本利用表單輸入變量是我到目前爲止的代碼我希望能夠從表C_price中選擇「成本」值,其中值I_typea_type匹配

例如表結構看起來像這樣

ID=1,A_type=line,I_type=Head,cost=5 

如果我輸入線和頭 我需要能夠在獲得價值5到古老的,我可以在計算中使用,並插入到另一個表AKA表單上我需要獲得成本到一個變量在某種程度上

以下是我的嘗試,我需要幫助即時通訊新的這一切,請幫助

$E_C; 
$T_cost = "1"; 
$date = date("d.m.y"); 
$name = $_POST["from"]; 
$email = $_POST["email"]; 
$ref = $_POST["link"]; 
$i_type = $_POST["i_type"]; 
$a_type = $_POST["a_type"]; 
$extra = $_POST["extra"]; 
$des = $_POST["description"]; 
$BG = $_POST["BG"]; 
$bg_type = $_POST["BGtype"]; 
$msg = $_POST["message"]; 
$auto_reply = ("thanks for the email we will get back to you as soon as we can about the cost and how you can pay"); 
$msg = wordwrap($msg, 70); 


$host = "localhost";// hostname 
$USER = "root";// username 
$PASS = "Password";// password 
$DBNAME = "andrea";// databace name 
$tbl_name = "c_price";// table name 

$con = mysqli_connect("localhost", $USER, $PASS, $DBNAME)or die("mySQL server connection failed"); 


$all = "SELECT cost FROM C_price WHERE a_type=$a_type,i_type=$i_type"; 
$result = mysqli_query($con,$all) or die("Error getting total storse"); 
while($row = mysqli_fetch_array($result)) 
{ 
echo $row['cost']; 
} 

if ($a_type = 'waist' && $extra='Y') 
{ 
$E_C = $cost * .3; 
} 
elseif ($a_type = 'knee' && $extra='Y') 
{ 
$E_C = $cost * .35; 
} 
elseif ($a_type ='full' && $extra='Y') 
{ 
$E_C = $cost * .4; 
} 
else 
{ 
$E_C = 0; 
} 

$T_cost = $cost + $E_C; 

if ($BG = 'y') 
{  
$T_cost = $T_cost + 10; 
} 
+0

詩對不起我的拼寫IM dislexic和spell feneticaly – crages1111 2014-09-24 05:18:51

+0

混合'mysqli'和'mysql'是錯誤的 – 2014-09-24 05:20:40

+0

'a_type = $ a_type'應該是'a_type ='$ a_type'' – Anthony 2014-09-24 05:24:27

回答

0

你不能在同一時間使用的mysqli和mysql .. Mysqli是一堂課...所以首先改變這一點GS ......

while($row = mysqli_fetch_array($result)) 
{ 
    echo $row['cost']; 
} 
    $news1 = mysqli_result($result, 0); // 0 is the index of the field, not the row 
    echo $news1; 
    echo $cost;` 

查詢應該是這樣的......

$all = "SELECT cost FROM C_price WHERE a_type='$a_type'and i_type='$i_type'"; 
+0

謝謝我解決它接縫在$ result = mysqli_query($ con,$ all)或死亡(「死於結果」);即使它不死我仍然不能得到成本的價值,我把表格拉成一個變量,所以我可以使用值 – crages1111 2014-09-25 00:00:10

+0

我已經刪除了news1線和下面的劑量沒有真的我能夠得到一個值,如果我添加實際值$ all =「SELECT cost FROM C_price WHERE a_type ='$ a_type ='line'i_type ='Head'」;問題是我需要使用我從窗體中獲得的值 – crages1111 2014-09-25 02:10:36

0

你不能混mysql和mysqli的

改變這一行while循環,並添加錯誤mysqli_error

$news1 = mysql_result($result, 0); 

$news1 = mysqli_result($result) or die(mysqli_error()); 

並且您的查詢也是錯誤的 A_type不一樣A_type和同樣適用於I_TYPE以及

$all = "SELECT cost FROM C_price WHERE a_type=$a_type,i_type=$i_type"; 
//Change it to 
$all = "SELECT cost FROM C_price WHERE A_type='$a_type'and I_type='$i_type'"; 

//和A_type不一樣a_type和同樣適用於I_TYPE以及