jarv Posted July 13, 2013 Share Posted July 13, 2013 I am trying to submit a form and then run an update but its not working, please help here is my page: <?php session_start(); mysql_connect("xxx", "xxx", "xxx"); mysql_select_db("xxx"); $id = $_REQUEST['id']; $query1 = "SELECT * FROM app1_blog"; $result1 = mysql_query($query1); $qry="SELECT id,title,date,article,image1,image2,image3 FROM app1_blog WHERE id = '$id'"; $cur=mysql_query($qry); while($i=mysql_fetch_row($cur)) {$id=$i[0]; $title=$i[1]; $date=$i[2]; $article=$i[3]; $image1=$i[4]; $image2=$i[5]; $image3=$i[6]; } if(isset($_POST['submit'])){ echo 'hello'; $new_title=mysql_real_escape_string(stripslashes($_POST["title"])); $new_article=mysql_real_escape_string(stripslashes($_POST["article"])); echo $new_title; } //$sql = "UPDATE app1_blog SET title='$new_title',article='$new_article' WHERE id = '$id'"; //$msg = 'Blog edited'; //$result = mysql_query($sql,$link) or die('Error: ' . mysql_error() . '<br>SQL: ' . $sql); //header("Location: edit.php?msg=$msg&id=$id"); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <title></title> <link rel="stylesheet" href="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.css"> <!-- Extra Codiqa features --> <link rel="stylesheet" href="codiqa.ext.css"> <!-- jQuery and jQuery Mobile --> <script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script> <script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script> <!-- Extra Codiqa features --> <script src="https://d10ajoocuyu32n.cloudfront.net/codiqa.ext.js"></script> </head> <body> <!-- Home --> <div data-role="page" id="page<?php echo $id;?>"> <div data-theme="a" data-role="header"> <h3> Edit blog post </h3> </div> <div data-role="content"> <h2> Blog </h2> <form method="post" action="<?php print $_SERVER["PHP_SELF"]; ?>" name="form"> <div data-role="fieldcontain"> <label for="textinput1"> Title </label> <input name="title" id="textinput1" placeholder="" value="<?php echo $title;?>" type="text"> <input name="id" placeholder="" value="<?php echo $id;?>" type="hidden"> </div> <div data-role="fieldcontain"> <label for="textinput2"> Date </label> <input name="date" id="textinput2" placeholder="" value="<?php echo $date;?>" type="text"> </div> <div data-role="fieldcontain"> <label for="textinput3"> Article </label> <textarea name="article" id="textarea1" placeholder=""><?php echo $article;?></textarea> </div> <img src="<?php echo $image1;?>" alt="image" width="288" > <img src="<?php echo $image2;?>" alt="image" width="288" > <img src="<?php echo $image3;?>" alt="image" width="288" > <input data-theme="b" value="Submit" type="submit"> </form> </div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/280132-submit-form-to-same-page-and-then-update-not-working/ Share on other sites More sharing options...
mac_gyver Posted July 13, 2013 Share Posted July 13, 2013 if(isset($_POST['submit'])){ your form doesn't have a field named 'submit' and as a result your form processing code is being skipped over. Link to comment https://forums.phpfreaks.com/topic/280132-submit-form-to-same-page-and-then-update-not-working/#findComment-1440632 Share on other sites More sharing options...
jarv Posted July 13, 2013 Author Share Posted July 13, 2013 thanks but I added name="submit" to my form and still 'hello' is not being output ?! Link to comment https://forums.phpfreaks.com/topic/280132-submit-form-to-same-page-and-then-update-not-working/#findComment-1440640 Share on other sites More sharing options...
mac_gyver Posted July 13, 2013 Share Posted July 13, 2013 and did you refresh your form to get the change to take effect in the html in the browser? Link to comment https://forums.phpfreaks.com/topic/280132-submit-form-to-same-page-and-then-update-not-working/#findComment-1440641 Share on other sites More sharing options...
jarv Posted July 14, 2013 Author Share Posted July 14, 2013 yes, here is my site: http://www.jbiddulph.com/worthing/ Link to comment https://forums.phpfreaks.com/topic/280132-submit-form-to-same-page-and-then-update-not-working/#findComment-1440718 Share on other sites More sharing options...
mac_gyver Posted July 14, 2013 Share Posted July 14, 2013 i would guess your current problems is that you are redirecting at some point in the code and any output you might be sending is being buffered and discarded so you never see it. two things - 1) you need to make sure output_buffering is turned off in your php.ini 2) comment out any header() redirects until after you get your code to do what you want. Link to comment https://forums.phpfreaks.com/topic/280132-submit-form-to-same-page-and-then-update-not-working/#findComment-1440720 Share on other sites More sharing options...
Yohanne Posted July 15, 2013 Share Posted July 15, 2013 if(isset($_POST['submit']) && 'submit' === $_POST['submit']) { echo 'hello'; .............. .............. .............. } else { echo 'hi' } try sample one, above.. if the output is "hi". your post is working else your code inside the open parenthesis are wrong.. Link to comment https://forums.phpfreaks.com/topic/280132-submit-form-to-same-page-and-then-update-not-working/#findComment-1440738 Share on other sites More sharing options...
White_Lily Posted July 15, 2013 Share Posted July 15, 2013 name="submit" should be on the submit button, nothing else. Otherwise it would never be "set". Link to comment https://forums.phpfreaks.com/topic/280132-submit-form-to-same-page-and-then-update-not-working/#findComment-1440749 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.