imarockstar Posted May 25, 2007 Share Posted May 25, 2007 this is the error i am getting: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/seodev/public_html/clients/powerproperties/press_03.php on line 55 this is my code <?php mysql_connect('localhost','seodev_admin','admin1369'); mysql_select_db('powerp'); ?> <ul> <?php //select the table if($_GET['id']){$select="select * from press where id='$_GET[id]'";} else{$select="select * from press";} $result = mysql_query($select); //grab all the content while($r=mysql_fetch_array($result)) ///// this is line 55 { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $headline=$r["headline"]; $source=$r["source"]; $writer=$r["writer"]; $pik_link=$r["pik_link"]; $article=$r["article"]; $date=$r["date"]; $id=$r["id"]; echo "<li><b class='h_03'>$headline</b>, $source"; } ?> </ul> not sure why this is not working .... any suggestions .. Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/ Share on other sites More sharing options...
binindex Posted May 25, 2007 Share Posted May 25, 2007 I don't use the select_db function but I do put my connection into a $mysql variable then pass it in with my query. Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-261813 Share on other sites More sharing options...
imarockstar Posted May 25, 2007 Author Share Posted May 25, 2007 ya sometimes i do that ..but i hae no clue why im getting this error .... i want to throw my computer out the window .. Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-261816 Share on other sites More sharing options...
AndyB Posted May 25, 2007 Share Posted May 25, 2007 Change $result = mysql_query($select); to $result = mysql_query($select) or die("Error ". mysql_error(). " with query ". $select); // show problem Tell us what you see. Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-261818 Share on other sites More sharing options...
bubblegum.anarchy Posted May 25, 2007 Share Posted May 25, 2007 The GET id needs to be quoted at the end of the following line: if($_GET['id']){$select="select * from press where id='$_GET[id]'";} maybe even change the line to the following: if($_GET['id']){$select="select * from press where id='{$_GET['id']}'";} Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-261822 Share on other sites More sharing options...
imarockstar Posted May 26, 2007 Author Share Posted May 26, 2007 this is the error i got Error No database selected with query select * from press what does not make sense is that i am running the same exact code on my other server and it works fine .... is there a setting in php which could cause this error to happen ? thanks b Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-261941 Share on other sites More sharing options...
AndyB Posted May 26, 2007 Share Posted May 26, 2007 The error message says it all. The database powerp does not exist. Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-261957 Share on other sites More sharing options...
imarockstar Posted May 26, 2007 Author Share Posted May 26, 2007 thats the problem ... there is a data base ... idk .. i put a support ticket into my hosting ... seodev_admin (Privileges: ALL PRIVILEGES) Connection Strings Perl $dbh = DBI->connect("DBI:mysql:seodev_powerp:localhost","seodev_admin","<PASSWORD HERE>"); PHP $dbh=mysql_connect ("localhost", "seodev_admin", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("seodev_powerp"); Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-262163 Share on other sites More sharing options...
AndyB Posted May 26, 2007 Share Posted May 26, 2007 er, based on your last post isn't seodev_powerp the name of the database? Your code tried to select a database named powerp (which didn't exist). Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-262168 Share on other sites More sharing options...
imarockstar Posted May 27, 2007 Author Share Posted May 27, 2007 solved thanks guys !!!! Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-262868 Share on other sites More sharing options...
AndyB Posted May 28, 2007 Share Posted May 28, 2007 care to explain what solved it? And then use the SOLVED button to mark this thread as done. Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-262965 Share on other sites More sharing options...
imarockstar Posted May 28, 2007 Author Share Posted May 28, 2007 my host informed me of the wrong way to call the database .... i needed the username of my account in front of the USER and DATABASE not just the USER. 1/2 my fault and half theres. so technically there is nothting wrong with any of my code, jsut the wrong name for the DB. stupid error .... thanks guys ... i still learned somthing from your help !!!! Quote Link to comment https://forums.phpfreaks.com/topic/52997-solved-help-with-mysql-error/#findComment-263062 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.