Hydrian Posted September 7, 2012 Share Posted September 7, 2012 When i load my page. i get Warning: mysql_fetch_array(): 9 is not a valid MySQL result resource in /home/a1761169/public_html/a40g/index.php on line 46 Here is my script <?php session_start(); error_reporting(-1);ini_set('display_errors', 1); $myServer = ""; $myUser = ""; $myPass = ""; $myDB = ""; //Connection to the database $dbhandle = mysql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); //Select a database to work with $selected = mysql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); $where = ""; if(isset($_GET['id'])){ $id = $_GET['id']; $where = " WHERE id = $id"; } //Declare the SQL statement that will query the database $query = "SELECT * FROM `topics`$where"; //Execute the SQL query and return records $result = mysql_query($query) or die('A error occured: ' . mysql_error()); //Show result //Free result set memory mysql_free_result($result); //Close the connection mysql_close($dbhandle); ?> <html> <head> </head> <body> <br> <div style="background-color:#CCCCCC; color:#; border-radius:5px;" align=''> <a href='create_topic.php'><b>New Topic<b></a> </div> <br><br> <?php while ( $record = mysql_fetch_array($result) ) { echo '<div id="content" >' . '<div style="background-color:#CCCCCC; color:#; border-radius:5px;">' . '<a href="index.php?id=' . $record["id"] . ' ">'. $record["topic_username"] .'</a>' . ' ' . '<a href="index.php?id=' . $record["id"] . ' ">'. $record["topic_name"] .'</a>' . '</div> ' . "<br>" . '<div style="word-wrap:break-word;div-layout:fixed; background-color:#CCCCCC; color:#; border-radius:5px;" width="500px" border="1">'; if(isset($_GET['id'])){echo $record['topic_date']; echo "<br><br>"; echo $record['topic_input']; } else { echo ""; } echo '</div></div>'; } ?> </body> </html> What have i done wrong? Link to comment https://forums.phpfreaks.com/topic/268112-warning-on-page-load/ Share on other sites More sharing options...
Jessica Posted September 7, 2012 Share Posted September 7, 2012 You're calling mysql_free_result($result); then trying to use the $result. Link to comment https://forums.phpfreaks.com/topic/268112-warning-on-page-load/#findComment-1376039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.