Newbie

Reply

Join Date: Nov 2007
Posts: 4
Reputation: emarkus is an unknown quantity at this point 
Solved Threads: 0
emarkus emarkus is offline Offline
Newbie Poster

Newbie

 
0
  #1
Nov 22nd, 2007
Can someone please help, I have this code below and every time i execute it i get this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/dbconnect1.php on line 14

I can work out what i am doin wrong.


<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpassword= "spewguts";
$dbdatabase - "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $db);

$sql = "SELECT * FROM products;";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
echo $row['product'];
}

?>
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Newbie

 
0
  #2
Nov 22nd, 2007
this is your error dude:


$sql = "SELECT * FROM products;";


change that one to this one:


$sql = "SELECT * FROM products";
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: Newbie

 
0
  #3
Nov 22nd, 2007
if i may ask why is using a semi colon at the end of an SQL statement a problem ? this is valid sql markup
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 4
Reputation: TheZert is an unknown quantity at this point 
Solved Threads: 0
TheZert's Avatar
TheZert TheZert is offline Offline
Newbie Poster

Re: Newbie

 
0
  #4
Nov 23rd, 2007
Originally Posted by Fungus1487 View Post
if i may ask why is using a semi colon at the end of an SQL statement a problem ? this is valid sql markup
The problem is that he has a semicolon inside the quotation marks and at the end of the statement. Check it out.
Last edited by TheZert; Nov 23rd, 2007 at 3:17 am.
One of the problems the internet has introduced is that in the electronic village all the village-idiots have internet access. -Peter Nelson
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: Newbie

 
0
  #5
Nov 23rd, 2007
i realise there is a semi colon inside the sql statement and after which is correct syntax for sql string then he appends the php line with a semi colon ?

does this affect the way php reads it?
if so then i have learned something new today.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 15
Reputation: black_ip82 is an unknown quantity at this point 
Solved Threads: 0
black_ip82's Avatar
black_ip82 black_ip82 is offline Offline
Newbie Poster

Re: Newbie

 
0
  #6
Nov 24th, 2007
i realise there is a semi colon inside the sql statement and after which is correct syntax for sql string then he appends the php line with a semi colon ?
does this affect the way php reads it?
Yes, php's mysql_query "automaticaly adds semicolon" after the query string.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Newbie

 
0
  #7
Nov 24th, 2007
i saw someother errors in the code. did you solve the problem?
Last edited by kkeith29; Nov 24th, 2007 at 4:10 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 561
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: Newbie

 
0
  #8
Nov 24th, 2007
yeah,this one:


$dbdatabase - "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $db);


should be:


$dbdatabase = "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 4
Reputation: emarkus is an unknown quantity at this point 
Solved Threads: 0
emarkus emarkus is offline Offline
Newbie Poster

Re: Newbie

 
0
  #9
Dec 8th, 2007
No i still have the same problem.
I have made some changes but sill the same error.

  1. <?php
  2.  
  3. $dbhost = "localhost";
  4. $dbuser = "root";
  5. $dbpassword= "spewguts";
  6. $dbdatabase = "productsdb";
  7.  
  8. $db = mysql_connect($dbhost, $dbuser, $dbpassword);
  9. mysql_select_db($database, $db);
  10.  
  11. $sql = "SELECT * FROM products";
  12. $result = mysql_query($sql);
  13.  
  14. while ($row = mysql_fetch_assoc($result)) {
  15. echo $row['product'];
  16. }
  17.  
  18. ?>

Any suggestions would be great.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 129
Reputation: hacker9801 is on a distinguished road 
Solved Threads: 15
hacker9801 hacker9801 is offline Offline
Junior Poster

Re: Newbie

 
0
  #10
Dec 8th, 2007
use mysql_error()...

oh, and you named your vars wrong....
see if it works now

  1. <?php
  2. $dbhost = "localhost";
  3. $dbuser = "root";
  4. $dbpassword = "spewguts";
  5. $dbdatabase = "productsdb";
  6.  
  7. $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Error: ".mysql_error());
  8. mysql_select_db($dbdatabase, $db);
  9.  
  10. $sql = "SELECT * FROM products";
  11. $result = mysql_query($sql) or die("Error: ".mysql_error());
  12.  
  13. while ($row = mysql_fetch_assoc($result)) {
  14. echo $row['product'];
  15. }
  16. ?>
Last edited by hacker9801; Dec 8th, 2007 at 8:13 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC