Php Help

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
I need help with a script that displays my mysql table. I keep getting this error.

PHP:
Parse error: syntax error, unexpected $end in /home/leafy/public_html/roster.php on line 31


Here is the code:

PHP:
<?php
$username="leafy_admin";
$password="removed";
$database="leafy_roster";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM leafy_clanemail";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Night Assassins Clan Roster</center></b><br><br>";
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"field1-name");
$email=mysql_result($result,$i,"field2-name");
$rank=mysql_result($result,$i,"field3-name");

echo "<b>$field1-name 
$field2-name2</b><br>$field3-name<br>;
$i++;
}
?>

Can you find out anything wrong with it?
 
Last edited:

knightcon

New Member
Messages
69
Reaction score
0
Points
0
Your missing a closing quotation marks. Try this code instead...

PHP:
 <?php 
$username="leafy_admin"; 
$password="nightassassins"; 
$database="leafy_roster"; 
mysql_connect(localhost,$username,$password); 
@mysql_select_db($database) or die( "Unable to select database"); 
$query="SELECT * FROM leafy_clanemail"; 
$result=mysql_query($query); 
$num=mysql_numrows($result); 
mysql_close(); 
echo "<b><center>Night Assassins Clan Roster</center></b><br><br>"; 
$i=0; 
while ($i < $num) { 
$name=mysql_result($result,$i,"field1-name"); 
$email=mysql_result($result,$i,"field2-name"); 
$rank=mysql_result($result,$i,"field3-name"); 

echo "<b>$field1-name  
$field2-name2</b><br>$field3-name<br>"; 
$i++; 
}
?>
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
thanks, ill check it out, and can you remove my pass from the script, lol, I forgot to take it out.
Edit:
It just gave me another error. Meanwhile, I tried this script from w3schools:

PHP:
<?php
$con = mysql_connect("localhost","leafy_admin","*REMOVED*");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("leafy_roster", $con);

$result = mysql_query("SELECT * FROM leafy_clanemail");

echo "<table border='1'>
<tr>
<th>Name</th>
<th>Email</th>
<th>Rank</th>
</tr>";
while($row=mysql_fetch_array($result));
  {
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td>" . $row['rank'] . "</td>";
  echo "</tr>";
  }
echo "</table>";mysql_close($con);
?>

I get this error:

HTML:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/leafy/public_html/rosterw3schools.php on line 18
 
Last edited:

xbeto78

New Member
Messages
5
Reaction score
0
Points
0
The while loop does not need a semicolon at the end of the line. It only needs an opening and closing brace.


while(
$row=mysql_fetch_array($result
))
{
echo
"<tr>"
;
echo
"<td>" . $row['name'] . "</td>"
;
echo
"<td>" . $row['email'] . "</td>"
;
echo
"<td>" . $row['rank'] . "</td>"
;
echo
"</tr>"
;
}
echo
"</table>";mysql_close($con
);
?>
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
changed that, now getting this:

PHP:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/leafy/public_html/rosterw3schools.php on line 2
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Temporery or do I need to link it to the new MYSQL server.
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Are you by any chance, on stoli?

If you are, link yourself to the new mysql server
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
yeah Im on Stoli. What is the new IP?
Edit:
I changed the server for MYSQL but I am still getting the
PHP:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/leafy/public_html/rosterw3schools.php on line 18
error
 
Last edited:
Top