DeanWhitehouse Posted April 21, 2008 Share Posted April 21, 2008 this is my code, does anyone no why it isn't working <?php require_once 'db_connect.php'; require_once 'config_table.inc.php'; $sql="SELECT * FROM $forum_quest ORDER BY id DESC"; // OREDER BY id DESC is order result by descending $result=mysql_query($sql); ?> <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td> <td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td> <td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> <td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ // Start looping table row ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> </tr> <?php // Exit looping and close connection } mysql_close(); ?> <tr> <td colspan="5" align="right" bgcolor="#E6E6E6"><a href="create_topic.php"><strong>Create New Topic</strong> </a></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/ Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Query must be bad. You did no error checking to make sure the query went through. Put this after $result = whatever, and tell me what it outputs: if (is_resource($result)) { echo '$result set correctly'; } else { die("ERROR in querying."); } Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523037 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 ERROR in querying. Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523040 Share on other sites More sharing options...
wildteen88 Posted April 21, 2008 Share Posted April 21, 2008 Use mysql_error() function to see why your query is failing. Rather than using DarkWaters code I'd chnage this line: $result=mysql_query($sql); to: $result=mysql_query($sql) or die('Query Error: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523042 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 ERROR in querying. Use this: $result=mysql_query($sql); or die (mysql_error()); Instead of: $result=mysql_query($sql); And tell me if it gives a mysql error. Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523043 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Ha, wildteen88 beat me to it. Just to let you know, wildteen88, I told him to do that just so I could make sure it was a resource problem with the result and not something really stupid like a bad connection. =) Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523046 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 i get this error Unknown column 'id' in 'order clause' Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523048 Share on other sites More sharing options...
wildteen88 Posted April 21, 2008 Share Posted April 21, 2008 Make sure you have a column called id in the table you're querying Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523050 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Yeah, make sure an 'id' column exists. Make sure it's not like, user_id or something. Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523051 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 ok, found the error thanks Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523055 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Any time. Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523058 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 with this code, i get the else function, how can i find where the error is? <?php require_once 'db_connect.php'; require_once 'config_table.inc.php'; // get data that sent from form $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_POST['name']; $email=$_POST['email']; $datetime=date("d/m/y h:i:s"); //create date time $sql="INSERT INTO $forum_quest(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')"; $result=mysql_query($sql); if($result){ echo "Successful<BR>"; echo "<a href=main_forum.php>View your topic</a>"; } else { echo "ERROR"; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523063 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 <?php require_once 'db_connect.php'; require_once 'config_table.inc.php'; // get data that sent from form $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_POST['name']; $email=$_POST['email']; $datetime=date("d/m/y h:i:s"); //create date time $sql="INSERT INTO $forum_quest(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')"; $result=mysql_query($sql); if(is_resource($result)){ echo "Successful<BR>"; echo "<a href=main_forum.php>View your topic</a>"; } else { echo "ERROR in query:" . mysql_error(); } mysql_close(); ?> Should display errors now. Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523068 Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Author Share Posted April 21, 2008 SOLVED Quote Link to comment https://forums.phpfreaks.com/topic/102186-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-523069 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.