Web Hosting Talk







View Full Version : Need help with php + mysql??


HostFX-UK
02-02-2009, 12:55 PM
Can anyone see anything wrong with this code, I have checked everything in the database and there is nothing wrong with that, all the tables exist etc.
The error I am getting is:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/whmaster/public_html/clientarea/activetickets.php on line 136
The code is:
<?php
$dblink = mysql_connect($sqlhost,$sqlusr,$sqlpw);
mysql_select_db($sqldb,$dblink);
$usrnmes = $_SESSION['username'];
$query = "SELECT * FROM support WHERE username='$usrnmes'";
while($result = mysql_fetch_array($query)) {
?>
<table width="100%" border="0">
<tr>
<td><strong><?php echo $result['subject']; ?></strong></td>
<td><strong><?php echo $result['status']; ?></strong></td>
<td><strong>Date</strong></td>
</tr>
</table>
<?php
}
?>

HostFX-UK
02-02-2009, 01:12 PM
Can anyone help?
Thanks

Adam-AEC
02-02-2009, 01:52 PM
You need to execute the query then fetch a row from it.
<?php
$dblink = mysql_connect($sqlhost,$sqlusr,$sqlpw);
mysql_select_db($sqldb,$dblink);
$usrnmes = $_SESSION['username'];
$query = "SELECT * FROM support WHERE username='$usrnmes'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
?>
<table width="100%" border="0">
<tr>
<td><strong><?php echo $row['subject']; ?></strong></td>
<td><strong><?php echo $row['status']; ?></strong></td>
<td><strong>Date</strong></td>
</tr>
</table>
<?php
}
?>
You should also remember to sanitize your data before you start dumping it into a SQL query (even if its' from a session).

HostFX-UK
02-02-2009, 02:07 PM
Thanks, worked perfect :D