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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.