English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

This is what I have so far:


(connection, and database strings erased)
$result = mysql_query("SELECT name,age,desc FROM contact WHERE ID = '$idno'");
$row = mysql_fetch_array($result);
echo 'Name: '.$row['name'].'
';
echo 'Age: '.$row['age'].'
';
echo 'Description: '.$row['desc'].'
';
?>

When I view the page in a browser, I change the url to .com/display.php?ID=7

The only thing that shows up is the Name:, Age:, Description:, not the actual values of the data in my table. Anyone know why?

2006-09-19 09:38:12 · 4 answers · asked by detroitkid17 2 in Computers & Internet Programming & Design

4 answers

That is because you need to add spaces here's a revised code -
(connection, and database strings erased)
$result = mysql_query("SELECT name,age,desc FROM contact WHERE ID = '$idno'");
$row = mysql_fetch_array($result);
echo 'Name: ' . $row['name'] . '
';
echo 'Age: ' . $row['age'] . '
';
echo 'Description: ' . $row['desc'] . '
';
?>

Also do you see that in your index page? If so and you don't have a record id in your database for 7 then know that PHP will automaticaly put any $_GET['page'] as index. (i'm sorta sick and tired so sorry if this is poorly worded)

Try posting the entire script as it might be more than that. One last thing -

Remember after select put parenthasise around name, age, date as well as spaces. One other thing you can try is putting the query in a $query variable then using it in the result variable. It seems for some weird reason to run smoother for me.

2006-09-19 09:50:51 · answer #1 · answered by mattmaul92 3 · 0 0

Perhaps the entire code is not shown, where are you assigning the $idno variable a value? You should add some error loops to get a better idea what is going on.

2006-09-19 09:49:04 · answer #2 · answered by Interested Dude 7 · 0 0

I see no initialization of the variable $idno.
You should set $idno = $_GET["ID"];

For testing purposes put an echo on the sql statement and check it on the database (using phpmyadmin for example) and see if it returns any data.

Regards,
Daniel - www.mind-spinner.com

2006-09-19 09:50:32 · answer #3 · answered by danielbuca 1 · 1 0

Wel, you forgot to set $idno. Try adding this to the beginning of your script:

$idno = (int) $_GET['ID'];

Do not drop the (int) part. Forcing $idno to be an integer helps prevent SQL injection attacks.

2006-09-21 04:51:44 · answer #4 · answered by NC 7 · 0 0

fedest.com, questions and answers