SamohtVII Posted April 1, 2013 Share Posted April 1, 2013 I have a form that I want to insert values to update a table but all it does is delete all the data in the field.Also while I'm here how do you make it so when you submit a post to say insert.php it doesn't open a new page it just updates and stays on the same page. Mine at the moment goes to a new page that says '1 record added' <?php$con=mysql_connect('localhost','root','Wqqgdvo1');// Check connectionif (!$con) { echo "Failed to connect to MySQL: " . mysql_error(); }mysql_select_db("tutorials_blog2", $con);$one=$_POST['one'];$sql="UPDATE ladderSET first=('$one')";if (!mysql_query($sql, $con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con);?> form: <form action="insertLadder.php" method="postLadder"><p><label class="field">1st:</label><input type="text" name="one"></p><p><input type="submit"></p></form> Link to comment Share on other sites More sharing options...
Don E Posted April 1, 2013 Share Posted April 1, 2013 (edited) Check out this link and scroll down to where it says SQL UPDATE warning to see why most likely what you're experiencing when trying to UPDATE the table: http://www.w3schools.../sql_update.asp You can do it all on the same page as well like the following: <?php if(isset($_POST['submit'])) { //code to update table } ?><!doctype html><html><head></head> <body> <form action="set action to the current web page here" method="make sure method is post"> <p><label class="field">1st:</label><input type="text" name="one"></p> <p><input type="submit" name="submit"/></p> <!-- make sure you give input submit button attribute name a value like I did: name="submit" --> </form></body> </html> Edited April 1, 2013 by Don E Link to comment Share on other sites More sharing options...
justsomeguy Posted April 1, 2013 Share Posted April 1, 2013 If you don't want the page to refresh at all then you need to submit the form and handle the response with Javascript using ajax. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now