Web Hosting Talk







View Full Version : php code error


lordaya
09-29-2007, 11:35 AM
hi all

i have an error in my code.

the code is :


$query1 = "SELECT * from setting WHERE id = 1";
$sql1 = @mysql_query($query1);
$results2 = array();
$c=0;
while ($row2=mysql_fetch_array($sql1)) {
$tmp2 = array(

'sitename' => $row2['sitename'],
'siteslogan' => $row2['siteslogan'],
'footermsg' => $row2['footermsg']
);
$results2[$c++] = $tmp2;
}
@mysql_free_result($sql1);


the error message is :


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/public_html/eqary/index.php on line 63


line 63 is :


while ($row2=mysql_fetch_array($sql1)) {


im just checking my code and the setting table is not set i think

so any thing related to that?

whats wrong out there!??

No1Resource
09-29-2007, 12:17 PM
Run this and see if you get a different error.

That error generally means that the query wasn't successful.. such as a row not actually existing.


<?php
/* Disable error output.. you should use a log */
error_reporting(0);

$query = mysql_query("SELECT * FROM `setting` WHERE `id` = '1'") or die(mysql_error());
$results2 = array();
$c = 0;
while ($row2 = mysql_fetch_array($query)) {
$tmp2 = array(
'sitename' => $row2['sitename'],
'siteslogan' => $row2['siteslogan'],
'footermsg' => $row2['footermsg']
);
$results2[$c++] = $tmp2;
}
mysql_free_result($query);
?>

lordaya
09-29-2007, 02:46 PM
"row not actually existing."

i think this is it because i didnt make the setting stable

i was just checking my code

web_design_sydney
10-02-2007, 11:00 PM
You need to add something along the lines of -


or die(mysql_error(Could not find row));

for

or die(mysql_error());

Which will stop it from printing a generic error message (unless you are sure the row will always be there). Otherwise use the mysql client or a gui like PHPMyAdmin to make sure the row actually exists where the php is looking for it.