woocha Posted September 21, 2007 Share Posted September 21, 2007 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 Link to comment https://forums.phpfreaks.com/topic/70171-simple-example-of-check-box-to-update-mysql-field-neededmy-links/ Share on other sites More sharing options...
pocobueno1388 Posted September 21, 2007 Share Posted September 21, 2007 <?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? Link to comment https://forums.phpfreaks.com/topic/70171-simple-example-of-check-box-to-update-mysql-field-neededmy-links/#findComment-352442 Share on other sites More sharing options...
woocha Posted September 21, 2007 Author Share Posted September 21, 2007 Thank you very much for your reply, but I realy just want one checkbox.....MySQL defaults to "0" which means Pepsi stinks....if users check box then update DB to "1" which means Pepsi is cool.... Link to comment https://forums.phpfreaks.com/topic/70171-simple-example-of-check-box-to-update-mysql-field-neededmy-links/#findComment-352445 Share on other sites More sharing options...
Wuhtzu Posted September 21, 2007 Share Posted September 21, 2007 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> Link to comment https://forums.phpfreaks.com/topic/70171-simple-example-of-check-box-to-update-mysql-field-neededmy-links/#findComment-352452 Share on other sites More sharing options...
woocha Posted September 21, 2007 Author Share Posted September 21, 2007 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', "; Link to comment https://forums.phpfreaks.com/topic/70171-simple-example-of-check-box-to-update-mysql-field-neededmy-links/#findComment-352511 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.