morrisbol2 Posted June 24, 2012 Share Posted June 24, 2012 Notice: Undefined index: marriageid in C:\wamp\view.php on line 5 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\view.php on line 7 require("db.php"); $id =$_REQUEST['marriageid']; <--error line 5 $result = mysql_query("SELECT * FROM parish WHERE marriageid = '$id'"); $test = mysql_fetch_array($result); <--error line 7 i dont know why have an error pls help me guys Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/ Share on other sites More sharing options...
Guber-X Posted June 24, 2012 Share Posted June 24, 2012 change your $_REQUEST to $_GET try that out Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356654 Share on other sites More sharing options...
morrisbol2 Posted June 24, 2012 Author Share Posted June 24, 2012 i change it to $_GET but it the same error. Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356657 Share on other sites More sharing options...
Guber-X Posted June 24, 2012 Share Posted June 24, 2012 oh, yeah im an idiot... the use of $_GET will get the "marriageod" from the URL bar when the address bar has something like view.php?marriageid=2 Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356658 Share on other sites More sharing options...
morrisbol2 Posted June 24, 2012 Author Share Posted June 24, 2012 yes it appears in the url /view.php?marriageID=5. can you identify why am having an error at the line 7? Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356662 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2012 Share Posted June 24, 2012 $_REQUEST['marriageid'] is NOT the same as $_REQUEST['marriageID'] Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356666 Share on other sites More sharing options...
Barand Posted June 24, 2012 Share Posted June 24, 2012 that error indicates an error with the query. try $result = mysql_query("SELECT * FROM parish WHERE marriageid = '$id'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356667 Share on other sites More sharing options...
Guber-X Posted June 24, 2012 Share Posted June 24, 2012 the way i always use mysql_fetch_array is like this... <?php while($row = mysql_fetch_array($test)){ !echo results from database here! } ?> Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356669 Share on other sites More sharing options...
morrisbol2 Posted June 24, 2012 Author Share Posted June 24, 2012 thanks for the reply sir.. ill try your format code. Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356671 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2012 Share Posted June 24, 2012 $_REQUEST['marriageid'] is NOT the same as $_REQUEST['marriageID'] Did you fix this? ^^^ Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356672 Share on other sites More sharing options...
Guber-X Posted June 24, 2012 Share Posted June 24, 2012 just remember when echoing in the "while" to display items from you database it will be something like this "$row[id]" if you want it like this "$id" you need to add in this right below the "while(){" list($id, $someotherstuff) = $row; inside the brackets must be listed exactly the same order how your database is laid out. Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356673 Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2012 Share Posted June 24, 2012 inside the brackets must be listed exactly the same order how your database is laid out. What do you mean by that? Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356674 Share on other sites More sharing options...
Guber-X Posted June 24, 2012 Share Posted June 24, 2012 inside the brackets must be listed exactly the same order how your database is laid out. What do you mean by that? ill show an example of one of my database... Table: blogs rows: id, date, blog, user so for the "list" it would be something like this <?php $r_blog = mysql_query('SELECT * FROM blogs DECS') or die('Blog Query Failed: '.mysql_error()); while($row = mysql_fetch_array($r_blog){ list($id, $date, $blog, $user) = $row; echo $date."<br>".$blog."<br>- ".$user; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356676 Share on other sites More sharing options...
Barand Posted June 24, 2012 Share Posted June 24, 2012 inside the brackets must be listed exactly the same order how your database is laid out. What do you mean by that? Only if you use "SELECT *", but then you should always specify the columns you want and not use '*'. In that case the list() should reflect the order specified in the SELECT clause. Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356680 Share on other sites More sharing options...
Guber-X Posted June 24, 2012 Share Posted June 24, 2012 im sorry morrisbol2 i threw this topic off topic :/ Only if you use "SELECT *", but then you should always specify the columns you want and not use '*'. In that case the list() should reflect the order specified in the SELECT clause. i always use "*" cuz most of the time I use all colums in my database Quote Link to comment https://forums.phpfreaks.com/topic/264703-mysql_fetch_array-error/#findComment-1356683 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.