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> Quote Link to comment 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. Quote Link to comment 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 ?! Quote Link to comment 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? Quote Link to comment 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/ Quote Link to comment 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. Quote Link to comment 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.. Quote Link to comment 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". 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.