Jump to content

Archived

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

gingercrock

php and mysql - database problem

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.