markvs Posted October 18, 2013 Report Posted October 18, 2013 Hello, I have a one row table that's being populated using a HTML form with several fields. I'm needing the database fields to be UPDATED only if the form fields have been filled in. I can do this in PHP, but would prefer to do this using MySQL. Below is an example of the PHP code. Keep in mind that I'm a green at both PHP/MySQL, so any suggestions are appreciated. if($user_name == 'user' && $password == 'password') { if(!empty($_POST['location'])) { mysqli_query($con, "UPDATE gig_date SET location='$location' WHERE gig_id=1"); } if(!empty($_POST['band_name'])) { mysqli_query($con, "UPDATE gig_date SET band_name='$band_name' WHERE gig_id=1"); } if(!empty($_POST['start_time'])) { mysqli_query($con, "UPDATE gig_date SET start_time='$start_time' WHERE gig_id=1"); } } Thanks, Mark Quote
administrator Posted October 18, 2013 Report Posted October 18, 2013 Hi Mark, I'm needing the database fields to be UPDATED only if the form fields have been filled in .. This is something you should do on the PHP level. Why do you want to do this validation of user input with MySQL? Stef Quote
markvs Posted October 18, 2013 Author Report Posted October 18, 2013 Hi Mark, This is something you should do on the PHP level. Why do you want to do this validation of user input with MySQL? Stef I'm not sure? I'm just trying to limit the number of calls to the database and I'm not sure how to do this within PHP. I just thought I could send it all to MySQL and then filter out the empty fields somehow. Quote
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.
Note: Your post will require moderator approval before it will be visible.