Buttero Posted December 4, 2006 Share Posted December 4, 2006 I upload this script to my server at Seski with all the username and pass updated. It worked fine until I clicked the news article I wanted to edit. Then this error message showed up:[quote]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/blah/public_html/q/edit.php on line 36[/quote]Here is edit.php[code]<? //connect to mysql//change user and password to your mySQL name and passwordmysql_connect("localhost","user","password"); //select which database you want to editmysql_select_db("spoono_sections"); //If cmd has not been initializedif(!isset($cmd)) { //display all the news $result = mysql_query("select * from news order by id"); //run the while loop that grabs all the news scripts while($r=mysql_fetch_array($result)) { //grab the title and the ID of the news $title=$r["title"];//take out the title $id=$r["id"];//take out the id //make the title a link echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>"; echo "<br>"; }}?><?if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit"){ if (!isset($_POST["submit"])) { $id = $_GET["id"]; $sql = "SELECT * FROM news WHERE id=$id"; $result = mysql_query($sql); [b] $myrow = mysql_fetch_array($result);[/b] ?> <form action="edit.php" method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br> Message:<TEXTAREA NAME="message" ROWS=10 COLS=30><? echo $myrow["message"] ?></TEXTAREA><br> Who:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["who"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?><? if ($_POST["$submit"]) { $title = $_POST["title"]; $message = $_POST["message"]; $who = $_POST["who"]; $sql = "UPDATE news SET title='$title',message='$message',who='$who' WHERE id=$id"; //replace news with your table name above $result = mysql_query($sql); echo "Thank you! Information updated."; }}?>[/code]The bold part is line 36 like the error said. Link to comment https://forums.phpfreaks.com/topic/29414-mysql-edit-row-with-php/ Share on other sites More sharing options...
Psycho Posted December 4, 2006 Share Posted December 4, 2006 Then change line 35 to this to see what the error is:$result = mysql_query($sql) or die ("The query<br>".$sql."<br>Caused the following error<br>".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/29414-mysql-edit-row-with-php/#findComment-134984 Share on other sites More sharing options...
Buttero Posted December 4, 2006 Author Share Posted December 4, 2006 ah ok, now i get a better explained error:[quote]The query SELECT * FROM frontpage_news WHERE id= Caused the following error You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1[/quote] ??? Link to comment https://forums.phpfreaks.com/topic/29414-mysql-edit-row-with-php/#findComment-134989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.