Jump to content

easy sql query issue


Eggzorcist

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.