Navajo Posted February 24, 2009 Share Posted February 24, 2009 Hey all, this is my code, I'm getting: james - Edit Notice: Undefined index: cmd in E:\Apache2\htdocs\2007\productupdates\Untitled-3.php on line 56 Notice: Undefined index: cmd in E:\Apache2\htdocs\2007\productupdates\Untitled-3.php on line 56 How do I get rid of these errors? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <? //connect to mysql //change user and password to your mySQL name and password mysql_connect ("serverxxx","usernamexxx","passwordxxx"); //If cmd has not been initialized if (! @mysql_select_db("simpcom_pn")) { echo( "<P>Unable to locate the simpcom_pn database at this time.</P>" ); exit(); } if(!isset($cmd)) { //display all the news2 $result = mysql_query("select * from news2 order by id"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } //run the while loop that grabs all the news2 scripts while($r = mysql_fetch_array($result)) { //grab the title and the ID of the news2 $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 news2 WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <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 news2 SET title='$title',message='$message',who='$who' WHERE id=$id"; //replace news2 with your table name above $result = mysql_query($sql); echo "Thank you! Information updated."; } } ?> </body> </html> Note my database code is this: CREATE TABLE `news` ( `id` int(11) NOT NULL auto_increment, `title` text NOT NULL, `message` longtext NOT NULL, `who` text NOT NULL, `date` text NOT NULL, `time` text NOT NULL, PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=4 ; Thanks! Quote Link to comment Share on other sites More sharing options...
andy_b42 Posted February 24, 2009 Share Posted February 24, 2009 on quick glance i would say this line: <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> needs a ";" after echo $myrow["id"] Quote Link to comment Share on other sites More sharing options...
andy_b42 Posted February 24, 2009 Share Posted February 24, 2009 and also the two similar ones below: <?php echo $myrow["title"] ?> <?php echo $myrow["who"] ?> Quote Link to comment Share on other sites More sharing options...
Navajo Posted February 24, 2009 Author Share Posted February 24, 2009 thanks, but that made no difference to the problem I have, the error is with this line: if ($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit"){ Quote Link to comment 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.