Nimbuz Posted January 19, 2009 Author Share Posted January 19, 2009 ah, I was looking at the line mentioned, not above it. Thanks for the tip. So it was a semicolon and it did fix the error, but, the record doesn't update although there are no errors. Quote Link to comment Share on other sites More sharing options...
chronister Posted January 19, 2009 Share Posted January 19, 2009 Well, the final piece of the puzzle is missing. Once you have the data there, you have to have a block of code to check if the update form has been submitted, and if so, grab the data and run an update query. When it comes to editing mysql data, you have 2 parts to it. Grab the desired row and display it in the form so it can be edited, then when that form is submitted, run an update query to update that row. Make sure you have the WHERE fieldID='$fieldID' part or you will update all your records to the data in the query.... that sucks when you have a lot of stuff to go back and correct. Luckily I only did this once or twice before I learned to check for that WHERE clause before running the query to test it. <?php if(isset($_POST['update_event'])) { // grab $_POST data and set in friendly var names // create update query $query = "UPDATE events SET fieldName='$fieldValue', fieldName2='$fieldValue2'..... WHERE eventId='$eventId'"; // run query if(mysql_affected_rows() > 0) { echo 'Row Updated'; } } ?> Notice I did not actually create the code for you. I gave you the skeleton, you will have to finish it out. I also noticed something here.... <?php /* these need to go inside the if statement below */ $eventName = mysql_real_escape_string($_POST['event_name']); $eventLocation = mysql_real_escape_string($_POST['event_location']); $eventDate = date('Y-m-d H:i:s', strtotime($_POST['event_date']) ); // FORMAT: 05/30/09 1:35 am /* these need to go inside the if statement below */ if(isset($_POST['create_event'])) { // Insert Values in a Row $insert_sql = "INSERT INTO events (eventName, eventLocation, eventDate) VALUES ('$eventName', '$eventLocation', '$eventDate')"; $result = mysql_query($insert_sql, $connection) or die("Row insert failed: " . mysql_error()); // If (or not) successful... if(mysql_affected_rows() > 0) { echo "1 record added"; } } ?> See what you can do with that. I will check back tomorrow morning. Nate Quote Link to comment Share on other sites More sharing options...
Nimbuz Posted January 20, 2009 Author Share Posted January 20, 2009 Figured it. All done. :-) Thanks for everything. :-) Quote Link to comment Share on other sites More sharing options...
chronister Posted January 20, 2009 Share Posted January 20, 2009 Mark as solved if it is indeed solved. Your welcome. Nate 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.