Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old May 31, 2006, 02:24   #1
safeasfcuk
SitePoint Guru
 
safeasfcuk's Avatar
 
Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
mysql error msg

im getting this msg when im trying to display a list of items in my database any ideas why?

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/safeasfc/public_html/work/client/admin/index.php on line 220


Code:
 <p>Select the product range you want to edit<br>
 <input type=radio name=table value=clarice checked=checked> Clarice Cliff<br />
<input type=radio name=table value=welsh> Welsh Gaudy<br />
<input type=radio name=table value=deco> Deco Antique<br />
<input type=radio name=table value=royal> Royal Doulton<br />
<input type=Submit name="submit" value=Edit>
<?php

 if ($_POST['submit']) {

include ("dbconnect.php");

$sql="SELECT * FROM" . $_POST['table'];
$result=mysql_query($sql);
?>

<table width=293 border=1>
  <tr>
    <td width=171>Product Name</td>
    <td width=106>Update</td>
  </tr>
  <tr>
  <?php
  
while($rows=mysql_fetch_array($result)){    <-------------line 220
?>
	<td><?php echo $rows['name']; ?></td>
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
  </tr>
  <?php
  }
	?>
</table>
<?php
mysql_close();
}
}
safeasfcuk is offline   Reply With Quote
Old May 31, 2006, 02:30   #2
spikeZ
dooby dooby doo
silver trophybronze trophy
 
spikeZ's Avatar
 
Join Date: Aug 2004
Location: Manchester UK
Posts: 11,239
It means your query failed to return any results probably because of an error.
Change your query line to:
PHP Code:

$result=mysql_query($sql) or die(mysql_error()); 

and post back the resulting message if there is one.
Also sanitise your post data before using it in your query.
PHP Code:




$sql
="SELECT * FROM" . mysql_real_escape_string($_POST['table']);
Spike
spikeZ is offline   Reply With Quote
Old May 31, 2006, 02:42   #3
safeasfcuk
SitePoint Guru
 
safeasfcuk's Avatar
 
Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
arr getting this error now m8 any ideas?

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROMdeco' at line 1

deco being the table name??
safeasfcuk is offline   Reply With Quote
Old May 31, 2006, 02:54   #4
egomac
SitePoint Member
 
Join Date: Feb 2006
Posts: 19
your query is returning false.

var_dump the $sql variable and paste the printed output in your phpmyadmin and see the explanation of the error.
egomac is offline   Reply With Quote
Old May 31, 2006, 02:57   #5
safeasfcuk
SitePoint Guru
 
safeasfcuk's Avatar
 
Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
what you mean var_dump sorry ??

im a little confussed because its thinking the table name is FROMdeco not just deco?
safeasfcuk is offline   Reply With Quote
Old May 31, 2006, 03:02   #6
foofoonet
is_empty(2);
 
foofoonet's Avatar
 
Join Date: Mar 2006
Posts: 1,000
Online man is pretty clever: http://www.php.net/var_dump
foofoonet is offline   Reply With Quote
Old May 31, 2006, 03:07   #7
safeasfcuk
SitePoint Guru
 
safeasfcuk's Avatar
 
Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
ok now im more confussed why do i need to var dump?
safeasfcuk is offline   Reply With Quote
Old May 31, 2006, 03:10   #8
spikeZ
dooby dooby doo
silver trophybronze trophy
 
spikeZ's Avatar
 
Join Date: Aug 2004
Location: Manchester UK
Posts: 11,239
lol, you don't need to var_dump!
you just need to add a space between the from and the variable!
PHP Code:

$sql="SELECT * FROM " . mysql_real_escape_string($_POST['table']); 

should do you

Spike
spikeZ is offline   Reply With Quote
Old May 31, 2006, 03:12   #9
safeasfcuk
SitePoint Guru
 
safeasfcuk's Avatar
 
Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
il try that spike thank
safeasfcuk is offline   Reply With Quote
Old May 31, 2006, 03:13   #10
bitbytes
Non-Member
 
bitbytes's Avatar
 
Join Date: May 2006
Posts: 218
try to print the query by echo on ur browser . for ex : select * from usermaster . after successfull output copy this query in mysql and try to run it. what will be the output ?
bitbytes is offline   Reply With Quote
Old May 31, 2006, 03:13   #11
safeasfcuk
SitePoint Guru
 
safeasfcuk's Avatar
 
Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
that worked a treat m8 thank lol so silly of me!
safeasfcuk is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 16:20.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved