Jump to content


Photo

php and mysql - database problem


  • Please log in to reply
1 reply to this topic

#1 gingercrock

gingercrock
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 15 February 2006 - 03:21 PM

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

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 15 February 2006 - 05:26 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users