Jump to content

help with script


RTS

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]
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.