Jump to content

Simple Example of Check Box to update MySQL Field NeededMy Links


Recommended Posts

I have an HTML Form the is to be filled out by a user...the Form already includes one radio button and one checkbox....this form is an emample form I grabbed from a sample website to use as a testing ground.

 

When I tried editing the form by adding another checkbox, i couldn't get it to work at all......Can anyone please tell give me a very simple set of code( HTML & PHP ) to update a MySQL field. My goal is to have a user decide if he like Pepsi.

 

So do you like Pepsi? checkbox for yes

 

and that's it......then the php updates the MySQL value to 1 for yes otherwise leave as default 0 for no...

 

 

Any help would be very much appreciated....

 

Thank You

 

<?php

if (isset($_POST['submit'])){

   //check if they put yes to pepsi
   if (isset($_POST['y_pepsi'])){
      //update DB to '1'
   }

}
?>

<form>
   Do you like Pepsie? 
   <input type="checkbox" name="y_pepsi"> Yes
   <input type="checkbox" name="n_pepsi"> No <p>
   <input type="submit" name="submit">
</form>

 

Is that what your looking for?

To update / modify pocobueno1388's example:

 

<?php

if (isset($_POST['submit'])){

   //check if they put yes to pepsi
   if ($_POST['pepsi_checkbox']) == 1){
      //update DB to '1'
   }

}
?>

<form>
   I like pepsi <input type="checkbox" name="pepsi_checkbox" value="1">
   <input type="submit" name="submit">
</form>

Is it possible to use:

 

mysql_query("update 'insert table here' set site_id = $id");

}

$query = "update 'insert table here' set ";

 

And then use the concat to hold everything together like this:

 

$query .= "blurb = \"$blurb\", ";

 

$query .= "banner = '$banner', ";

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.