Jump to content

Archived

This topic is now archived and is closed to further replies.

RTS

help with script

Recommended Posts

can someone tell me whats wrong with this script?
[code]<?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);
?>[/code]
I get [code]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /Library/WebServer/Documents/Blogs/test.php on line 7[/code]

Share this post


Link to post
Share on other sites
you have
[code]$result = mysql_query('SELECT * FROM blogs WHERE Name=sada');[/code]

try

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

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

Share this post


Link to post
Share on other sites
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

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

hope that helps,
Cold

Share this post


Link to post
Share on other sites
I also have a feeling that you capitalized the N on 'Name' on this line by accident:
$result = mysql_query('SELECT * FROM blogs WHERE [b]Name[/b]=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.
[code]while($row = mysql_fetch_array($result))
  {
  echo '<table border=10 width=400 cellpadding=0 cellspacing=3>[/code]


but you close the table [i]after[/i] the while loop
[code]  }
echo '</table>';[/code]

probably not what you want.
You are opening/starting a bunch of tables, and not closing them.

Share this post


Link to post
Share on other sites

×

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.