Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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.

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...