Eggzorcist Posted June 4, 2009 Share Posted June 4, 2009 Here is my code: <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "tgj4u"; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die(mysql_error()); $id = $_GET['id']; $id = mysql_real_escape_string($id); $query = "SELECT * FROM maildata WHERE id = '$id'"; if ($qry_result = mysql_query($query) or die(mysql_error())){ while($info = mysql_fetch_array($qry_result)){ echo "Sent by: " . $info['sender'] . "<br>"; echo "Recipient: " . $info['recipient'] . "<br>"; echo "Departed: " . $info['depart'] . "<br>"; echo "Satus: " . $info['depart'] . "<br>"; echo "Current Location: " . $info['currentlocation'] . "<br>"; echo "Arrival Location: " . $info['finallocation'] . "<br>"; echo "Expected on: " . $info['expected'] . "<br>"; } } ?> What I am trying to do is from the ID get information in maildata, but for some reason the while command isnt working and if I dont have while all I get from the echos is the text not the variables. Also if I were to add that if it doesnthave that ID to echo out something how could I do tht? thanks Link to comment https://forums.phpfreaks.com/topic/160863-easy-sql-query-issue/ Share on other sites More sharing options...
Eggzorcist Posted June 4, 2009 Author Share Posted June 4, 2009 I've also tried to use mysql_fetch_assoc but didnt work. Link to comment https://forums.phpfreaks.com/topic/160863-easy-sql-query-issue/#findComment-848981 Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 or die() statement needs to ... well die. Try this - <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "tgj4u"; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die(mysql_error()); $id = intval($_GET['id']); $query = "SELECT * FROM maildata WHERE id = $id"; $qry_result = mysql_query($query) or trigger_error('Select SQL failed.', E_USER_ERROR); while($info = mysql_fetch_assoc($qry_result)){ echo "Sent by: " . $info['sender'] . "<br>"; echo "Recipient: " . $info['recipient'] . "<br>"; echo "Departed: " . $info['depart'] . "<br>"; echo "Satus: " . $info['depart'] . "<br>"; echo "Current Location: " . $info['currentlocation'] . "<br>"; echo "Arrival Location: " . $info['finallocation'] . "<br>"; echo "Expected on: " . $info['expected'] . "<br>"; } Link to comment https://forums.phpfreaks.com/topic/160863-easy-sql-query-issue/#findComment-848986 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.