Jump to content

Recommended Posts

Hello again guys,

 

I'm using this code to retrieve information from a MySQL Database.

<?php
$username="safetyfi_secure";
$password="HIDDEN";
$database="safetyfi_students";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tablename";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$field1-name = mysql_result($result,$i,"ID");
$field2-name = mysql_result($result,$i,"ParentFirstName");
$field3-name = mysql_result($result,$i,"ParentLastName");
$field4-name = mysql_result($result,$i,"StudentName");
$field5-name = mysql_result($result,$i,"Class");
$field6-name = mysql_result($result,$i,"Address");
$field7-name = mysql_result($result,$i,"City");
$field8-name = mysql_result($result,$i,"State");
$field9-name = mysql_result($result,$i,"Zip");
$field10-name = mysql_result($result,$i,"Phone");
$field11-name = mysql_result($result,$i,"BirthMonth");
$field12-name = mysql_result($result,$i,"BirthDay");
$field13-name = mysql_result($result,$i,"BirthYear");
$field14-name = mysql_result($result,$i,"School");
$field15-name = mysql_result($result,$i,"PaymentMethod");

echo "Student
ID: $field1-name<p>Enrolled in Class: $field5-name</p>
<p>$field4-name $field3-name</p>
<p>$field14-name</p>
<p>$field6-name</p>
<p>$field7-name, WI $field9-name</p>
<p>$field10-name</p>
<p>Parent Name: $field2-name $field3-name</p>
<p>Payment Method: $field15-name</p>
<hr>";

$i++;
}

?>

 

When using it, I'm getting the error

 

Parse error: syntax error, unexpected '=' in /home2/safetyfi/public_html/secure/directory.php on line 20

 

Can anyone tell me how I could fix this?

 

Thanks,

 

Anthony

Link to comment
https://forums.phpfreaks.com/topic/175734-solved-unexpected/
Share on other sites

The Words "Database Output". I don't think I did.

 

I changed some things in the script in hopes of making it working.

 

<?php
$username="safetyfi_secure";
$password="Hidden";
$database="safetyfi_students";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Students";
$result=mysql_query($query);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$field1_name = mysql_result($result,$i,"ID");
$field2_name = mysql_result($result,$i,"ParentFirstName");
$field3_name = mysql_result($result,$i,"ParentLastName");
$field4_name = mysql_result($result,$i,"StudentName");
$field5_name = mysql_result($result,$i,"Class");
$field6_name = mysql_result($result,$i,"Address");
$field7_name = mysql_result($result,$i,"City");
$field8_name = mysql_result($result,$i,"State");
$field9_name = mysql_result($result,$i,"Zip");
$field10_name = mysql_result($result,$i,"Phone");
$field11_name = mysql_result($result,$i,"BirthMonth");
$field12_name = mysql_result($result,$i,"BirthDay");
$field13_name = mysql_result($result,$i,"BirthYear");
$field14_name = mysql_result($result,$i,"School");
$field15_name = mysql_result($result,$i,"PaymentMethod");

echo "Student
ID: $field1_name<br>Enrolled in Class: $field5_name
<br>$field4_name $field3_name
<br>$field14_name
<br>$field6_name
<br>$field7_name, WI $field9_name
<br>$field10_name
<br>Parent Name: $field2_name $field3_name
<br>Payment Method: $field15_name
<hr>";

$i++;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/175734-solved-unexpected/#findComment-926086
Share on other sites

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/safetyfi/public_html/secure/directory.php on line 11

 

That's the error that comes up now.

well that part was also running your loop

$num=mysql_numrows($result);

[...]

while ($i < $num) {

 

now you don't have a $num to be greater than $i

 

Also..there is a

 tag for displaying code

Link to comment
https://forums.phpfreaks.com/topic/175734-solved-unexpected/#findComment-926094
Share on other sites

When you get that error it means you need to do this

$result=mysql_query($query) or die(mysql_error());

 

it will tell you why $result is not a valid mysql result resource

Found out the error and fixed it. Thank you guys again for helping a n00b!
Link to comment
https://forums.phpfreaks.com/topic/175734-solved-unexpected/#findComment-926100
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.