Jump to content

php and mysql - database problem


gingercrock

Recommended Posts

hey guys, i am doing a project at the moment which is basically a friends reunited type of website.. i have created a database but the searches do not work.. this is the code i have for when the 'search' button is pressed:

<?php
$connection = mysql_connect("sentinel.cs.cf.ac.uk","scm5sjc",
"put_password_here");

mysql_select_db("sjcdb",$connection) or die("failed!");

$result = mysql_query("SELECT * FROM info", $connection);

while($row = mysql_fetch_row($result)) {

$title = $row[1];
$first = $row[2];
$last = $row[3];
$age = $row[4];
$subject = $row[5];
$initial=$row[6];
$email=$row[7];

for ($i=0; $i<mysql_num_fields($result); $i++) print $row[$i]." ";
echo "\n";
print $title." ";
print $first." ";
print $last ." ";
print $age ." ";
print $subject." ";
print $initial." ";
print $email." ";

}

mysql_close($connection);
?>

</pre>


all that appears when the button is pressed is this code, any advice of where i may have gone wrong would be great, thanks.
steve
Link to comment
https://forums.phpfreaks.com/topic/3437-php-and-mysql-database-problem/
Share on other sites

First, you might consider using mysql_fetch_assoc($result) instead, so that you don't have to do those variable assignments -- you'd get back $row['title'], etc.

Second, are you sure there's no query error? You have no mysql_error() call.

Hope that helps.

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.