HaZaRd420 Posted April 21, 2006 Share Posted April 21, 2006 Ok Heres the problem, I got to edit it, click the link, I edit the textarea, i click submit, and nothing happends. Its suppose to use the echo "Thank you! Information updated" When i click the submit button but it doesnt, it just goes back to the link to edit again. Please Help me.[code] <? //connect to mysql//change user and password to your mySQL name and passwordmysql_connect("localhost","DB","password"); //select which database you want to editmysql_select_db("DB"); //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 $subject=$r["subject"];//take out the title $id=$r["id"];//take out the id $author=$r["author"]; $date=$r["date"]; $content=$r["content"]; //make the title a link echo "<a href='edit.php?cmd=edit&id=$id'>$subject - 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); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Subject:<INPUT TYPE="subject" NAME="suject" VALUE="<?php echo $myrow["subject"] ?>" SIZE=30><br> Content:<TEXTAREA NAME="content" ROWS=10 COLS=30><? echo $myrow["content"] ?></TEXTAREA><br> Author:<INPUT TYPE="author" NAME="author" VALUE="<?php echo $myrow["author"] ?>" SIZE=30><br> Date:<INPUT TYPE="date" NAME="date" VALUE="<?php echo $myrow["date"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?><? if ($_POST["$submit"]) { $subject = $_POST["subject"]; $content = $_POST["content"]; $author = $_POST["author"]; $date = $_POST["date"]; $sql = "UPDATE news SET subject='$subject',content='$content',author='$author', date='$date' WHERE id=$id"; //replace news with your table name above $result = mysql_query($sql); echo "Thank you! Information updated."; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8023-edit-mysql-row-problem/ Share on other sites More sharing options...
gizmola Posted April 21, 2006 Share Posted April 21, 2006 [!--quoteo(post=367111:date=Apr 20 2006, 10:46 PM:name=HaZaRd420)--][div class=\'quotetop\']QUOTE(HaZaRd420 @ Apr 20 2006, 10:46 PM) [snapback]367111[/snapback][/div][div class=\'quotemain\'][!--quotec--]Ok Heres the problem, I got to edit it, click the link, I edit the textarea, i click submit, and nothing happends. Its suppose to use the echo "Thank you! Information updated" When i click the submit button but it doesnt, it just goes back to the link to edit again. Please Help me.[code] <? if ($_POST["$submit"]) { $subject = $_POST["subject"]; $content = $_POST["content"]; $author = $_POST["author"]; $date = $_POST["date"]; $sql = "UPDATE news SET subject='$subject',content='$content',author='$author', date='$date' WHERE id=$id"; //replace news with your table name above $result = mysql_query($sql); echo "Thank you! Information updated."; }}?>[/code][/quote]My first question is... does this work at all? And if so, is that because you have register globals turned on? The reason I ask is because you look to see if $cmd isset, but you don't assign that variable. If you have register globals on, well you shouldn't, and the use ofthe $_GET and $_POST superglobs is very confusing.Pick an approach and stay with it. Probably this line explains part of your problem:[code] if ($_POST["$submit"])[/code]$submit isn't what you want to index $_POST by. probably you meant 'submit' as you used it previously. However, it's obvious from your code, that what you want is an if - else situation based on the value of submit, which you check at the top of the block, so you probably should just rewrite your code to go with the implicit if- else condition.[code]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"] ?>"> Subject:<INPUT TYPE="subject" NAME="suject" VALUE="<?php echo $myrow["subject"] ?>" SIZE=30><br> Content:<TEXTAREA NAME="content" ROWS=10 COLS=30><? echo $myrow["content"] ?></TEXTAREA><br> Author:<INPUT TYPE="author" NAME="author" VALUE="<?php echo $myrow["author"] ?>" SIZE=30><br> Date:<INPUT TYPE="date" NAME="date" VALUE="<?php echo $myrow["date"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } else { $subject = $_POST["subject"]; $content = $_POST["content"]; $author = $_POST["author"]; $date = $_POST["date"]; $sql = "UPDATE news SET subject='$subject',content='$content',author='$author', date='$date' WHERE id=$id"; //replace news with your table name above $result = mysql_query($sql); echo "Thank you! Information updated."; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8023-edit-mysql-row-problem/#findComment-29255 Share on other sites More sharing options...
HaZaRd420 Posted April 21, 2006 Author Share Posted April 21, 2006 Hey man, that worked, but now when i go to edit it, the subject just dissapears and doesnt insert it. :( Quote Link to comment https://forums.phpfreaks.com/topic/8023-edit-mysql-row-problem/#findComment-29256 Share on other sites More sharing options...
gizmola Posted April 21, 2006 Share Posted April 21, 2006 [!--quoteo(post=367114:date=Apr 20 2006, 11:20 PM:name=HaZaRd420)--][div class=\'quotetop\']QUOTE(HaZaRd420 @ Apr 20 2006, 11:20 PM) [snapback]367114[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hey man, that worked, but now when i go to edit it, the subject just dissapears and doesnt insert it. :([/quote]Yes, notice the typo you made in the name of your form element for subject. Anytime something "sorta" works, you need to check for those types of errors. Quote Link to comment https://forums.phpfreaks.com/topic/8023-edit-mysql-row-problem/#findComment-29258 Share on other sites More sharing options...
HaZaRd420 Posted April 21, 2006 Author Share Posted April 21, 2006 O so sorry man. Thanks so much dude. I added your AIM if thats cool with you! Quote Link to comment https://forums.phpfreaks.com/topic/8023-edit-mysql-row-problem/#findComment-29259 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.