Jump to content


Photo

help with script


  • Please log in to reply
3 replies to this topic

#1 RTS

RTS
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 14 October 2006 - 05:58 PM

can someone tell me whats wrong with this script?
<?php 
$con = mysql_connect('localhost','ZackBabtkis','');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db('test', $con);
$result = mysql_query('SELECT * FROM blogs WHERE Name=sada');

while($row = mysql_fetch_array($result))
  {
  echo '<table border=10 width=400 cellpadding=0 cellspacing=3>

<tr>

<td background=table.jpg>';
  echo '<div align=left><font size=5><b>From:</b> '. (ucfirst($row['username']));
  echo '<br>';
  echo '<b>On:</b> ' . (ucfirst($row['Date']));
  echo '<br>';
  echo '<b>Subject:</b> ' . (ucfirst($row['Subject']));
  echo '</font>';
  }
echo '</table>';

mysql_close($con);
?>
I get
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Library/WebServer/Documents/Blogs/test.php on line 7


#2 Stooney

Stooney
  • Members
  • PipPipPip
  • Advanced Member
  • 1,093 posts
  • LocationLas Cruces, NM

Posted 14 October 2006 - 06:10 PM

you have
$result = mysql_query('SELECT * FROM blogs WHERE Name=sada');

try

$result = @mysql_query("SELECT * FROM blogs WHERE Name='sada'");

Also, might try checking that your table name is 'Name', might be 'name'.

<embed src='.wav' autostart='true' loop='false'
width='2' height='0'>
</embed>
i found that ERMMMMM thats called PHP!!!!


#3 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 14 October 2006 - 06:14 PM

The result resource is probably returned FALSE on a falure. This could be due to the name being incorrect on the table or database etc.

To check wether to query found anything use this

if( mysql_num_rows( $result ) == 0 )
{
    echo'Query failed to execute';
}

hope that helps,
Cold


You can learn alot from reading the manual

#4 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 14 October 2006 - 06:21 PM

I also have a feeling that you capitalized the N on 'Name' on this line by accident:
$result = mysql_query('SELECT * FROM blogs WHERE Name=sada');

i tend to do that alot.

maybe it's just 'name' ?

I also just noticed that you started a table inside the while loop.
while($row = mysql_fetch_array($result))
  {
  echo '<table border=10 width=400 cellpadding=0 cellspacing=3>


but you close the table after the while loop
  }
echo '</table>';

probably not what you want.
You are opening/starting a bunch of tables, and not closing them.
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users