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
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
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.
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