at0mic Posted April 24, 2007 Share Posted April 24, 2007 I'm having trouble editing a row. The existing data echoed into the form ok but if I try to change anything and click submit, the error message at the end of the script is echoed. Can anybody help? <? include ('inc/config.php'); ?> <? 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); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> start_date:<TEXTAREA NAME="start_date" ROWS=10 COLS=30><? echo $myrow["start_date"] ?></TEXTAREA><br> headline:<INPUT TYPE="TEXT" NAME="headline" VALUE="<?php echo $myrow["headline"] ?>" SIZE=30><br> article:<INPUT TYPE="TEXT" NAME="article" VALUE="<?php echo $myrow["article"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? }?> <? if ($_POST["$submit"]) { $name = $_POST["name"]; $start_date = $_POST["start_date"]; $headline = $_POST["headline"]; $article = $_POST["article"]; $sql = "UPDATE news SET name='$name',start_date='$start_date',headline='$headline',article='$article' WHERE id=$id"; $result = mysql_query($sql); echo "Thank you! Information updated."; } else {echo 'error';} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/48439-editing-a-row-in-a-table/ Share on other sites More sharing options...
willpower Posted April 24, 2007 Share Posted April 24, 2007 is the $id being set with this proces. echo out your sql to check. Will Quote Link to comment https://forums.phpfreaks.com/topic/48439-editing-a-row-in-a-table/#findComment-236917 Share on other sites More sharing options...
at0mic Posted April 24, 2007 Author Share Posted April 24, 2007 which part should I echo? Quote Link to comment https://forums.phpfreaks.com/topic/48439-editing-a-row-in-a-table/#findComment-236983 Share on other sites More sharing options...
at0mic Posted May 30, 2007 Author Share Posted May 30, 2007 Hi please can anyone help me? if I click submit I don't get any error, however, the row isn't updated. If I turn on error reporting, I get: Notice: Undefined index: submit in H:\xampplite\htdocs\pages\news\editNews.php on line 48 When I make my changes and click submit, I get: Notice: Undefined index: cmd in H:\xampplite\htdocs\pages\news\editNews.php on line 21 Notice: Undefined index: id in H:\xampplite\htdocs\pages\news\editNews.php on line 62 I assume its to do with register_globals being turned off by default in later versions of PHP but I dont know how to solve it. Here's the code I used: <? 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); $myrow = mysql_fetch_array($result); ?> <form action="editNews.php" method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> Start_date:<INPUT TYPE="TEXT" NAME="start_date" VALUE="<?php echo $myrow["start_date"] ?>" SIZE=30><br> Headline:<INPUT TYPE="TEXT" NAME="headline" VALUE="<?php echo $myrow["headline"] ?>" SIZE=30><br> Article:<TEXTAREA NAME="article" ROWS=10 COLS=30> <? echo $myrow["article"] ?></TEXTAREA><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? }?> <? if ($_POST["submit"]) { $name = $_POST["name"]; $start_date = $_POST["start_date"]; $headline = $_POST["headline"]; $article = $_POST["article"]; $sql = "UPDATE news SET name = '".$_POST['name']."', start_date = '".$start_date."', headline = '".$headline."', article = '".$article."' WHERE id = '".$_GET['id']."' "; $result = mysql_query($sql) or die('Could not edit row '.mysql_error()); } } ?> I hope you can help Quote Link to comment https://forums.phpfreaks.com/topic/48439-editing-a-row-in-a-table/#findComment-265033 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.