2014-05-06 40 views
-3

美好的一天,如果你能幫助我,我會很高興。 我有一個項目。其餘部分是我可以從數據庫中提取數據的地方。 它的一個跟蹤應用程序。我想要這樣一種情況,即如果用戶輸入他/她的參考號碼,它將以 參考號碼,發貨日期,船舶重量,預期交貨,船舶國家,船舶狀態,城市,郵編,e.t.c等表格顯示結果。我有以下的html代碼:從數據庫中檢索值並導入表格行

<form id="track" name="track" method="post" action="tester.php"> 
     <h2>Track your shipment Here</h2> 

     <p><label> Tracking Reference: 
     <input type="text" id="reference" name="reference" value="" maxlength="40" required="required" /></label></p> 


     <div class="button_holder"> 

     <p> <input type="submit" id="track" value="Track Now" maxlength="40" required="required" /></label> 
     </label></p> 

     </div> 

和我的PHP代碼:

<?php 

$ref = mysql_real_escape_string($_POST['reference']); 

// conmnecting to the database 
if(isset($ref)){ 
$connection = mysql_connect('localhost', 'root', 'wisdom'); 
mysql_select_db('gday'); 

$query = "SELECT * FROM shipment WHERE id = '".$ref."' "; 
$row = mysql_query($query); 


echo "<table border=\"1\"; width='550px'>"; // start a table tag in the HTML 


//Creates a loop to loop through results 
    echo "<tr><td>" . $row['id'] . "</td><td>" . $row['ship_type'] . "</td><td>" . $row['ship_ref'] . "</td><td>" . $row['ship_date'] . "</td><td>" . $row['ship_weight'] . "</td><td>" . $row['expected_delivery'] . "</td></tr>" . $row['ship_country'] . "</td></tr>" . $row['ship_state'] . "</td></tr>" . $row['ship_city'] . "</td></tr>" . $row['ship_zip'] . "</td></tr>" . $row['remark'] . "</td></tr>"; 




echo "</table>"; //Close the table in HTML 

mysql_close(); //Make sure to close out the database connection 



} 
else{echo " Enter a valid Reference Number"; 
exit;} 


?> 

現在,我的主要問題是:下面的代碼只輸出表中沒有任何信息插入,請問可以做些什麼來確保行充滿從數據庫中檢索的數據? 感謝

+1

取回取指....................... –

+0

這是PHP/Mysql 101.非常初學者的東西。你需要查看mysql函數的工作方式。而且,不要使用它們,它們會被棄用並被認爲是有害的。 – Andrew

+0

@Andrew是的,我同意並接受它是一個初學者課程,但你怎麼能幫助我的代碼呢?我會很感激 –

回答

0

取取取.......

改變這樣的:

$res= mysql_query($query); 
$row=mysql_fetch_assoc($res); 

mysqli_功能已被棄用,不再使用它們。改用MySQLi或PDO庫。

+0

我得到一個未定義的變量,並且mysql_fetch_assoc()期望參數1是資源,當我實現代碼時,在C:\ wamp \ www \ gday2 \ tester.php中給出了null。請問什麼是正確的用法?謝謝 –

+0

這意味着你的查詢沒有工作 –

+0

你好,那麼什麼可能是正確的查詢?請幫忙 !!! –