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