rkstevens Posted March 17, 2008 Share Posted March 17, 2008 I have the following line in my form: <input type="checkbox" name="AudioClip" checked="checked" /> but when I send this to the database INSERT INTO Songs (... , AudioClip , ...) VALUES (... , '$_POST[AudioClip]' , ...) the value inserted into the AudioClip field in the database is 0, if the checkbox is checked or not checked. AudioClip in my database is BOOL type [TINYINT(1)] Thank you for your assistance. Ron Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/ Share on other sites More sharing options...
revraz Posted March 17, 2008 Share Posted March 17, 2008 Try '{$_POST['AudioClip']}' Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494012 Share on other sites More sharing options...
rkstevens Posted March 17, 2008 Author Share Posted March 17, 2008 change did not do anything. Still get a '0' stored in database no matter if checked or not Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494017 Share on other sites More sharing options...
revraz Posted March 17, 2008 Share Posted March 17, 2008 Lets see the form. Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494018 Share on other sites More sharing options...
rkstevens Posted March 17, 2008 Author Share Posted March 17, 2008 Form: <form action='processsonginfo.php' method='post'> <table> <tr> <td>Song Title</td> <td><input type="text" name="SongName" size="40" /></td> </tr> <tr> <td>Song Author</td> <td><input type="text" name="SongAuthor" size="40" /></td></tr> <tr><td>Song Copyright</td> <td><input type="text" name="SongCopyright" size="40" /></td></tr> <tr><td>Footnote</td> <td><input type="text" name="AlbumFootnote" size="40" /></td></tr> <tr><td>About the Song Title</td> <td><input type="text" name="AboutSongTitle" size="40" /></td></tr> <tr><td>About the Song Text</td> <td><textarea name="AboutSongText" rows="8" cols="40"></textarea></td></tr> <tr><td>Lyrics for song?</td> <td><input type="checkbox" name="SongLyrics" checked="checked" /></td></tr> <tr><td>Audio clip for song?</td> <td><input type="checkbox" name="AudioClip" checked="checked" /></td></tr> </table> <center> <input type="submit" /> </center> </form> Query in processsonginfo.php: $doquery = mysql_query( "INSERT INTO Songs (SongID,SongName,Songurl,SongAuthor,SongCopyright,SongLyrics,AboutSongTitle,AboutSongText,AudioClip,AlternateLyrics,AlbumFootnote) VALUES ( '' , '$_POST[songName] , 'trimAll($_POST[songName]' , '$_POST[songAuthor]' , '$_POST[songCopyright]' , '$_POST[songLyrics] , '$_POST[AboutSongTitle]' , '$_POST[AboutSongText]' , '$_POST[AudioClip]' , '' , ''); Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494024 Share on other sites More sharing options...
revraz Posted March 17, 2008 Share Posted March 17, 2008 If that query is a cut and paste, you are missing two single quotes. Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494027 Share on other sites More sharing options...
moon 111 Posted March 17, 2008 Share Posted March 17, 2008 Check boxes return 'on' or 'off'. Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494029 Share on other sites More sharing options...
rkstevens Posted March 17, 2008 Author Share Posted March 17, 2008 So I would have to add something like this before I INSERT? $isAudioClip = 0; if ($_POST[AudioClip]=='on') { $isAudioClip = 1; } Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494034 Share on other sites More sharing options...
moon 111 Posted March 17, 2008 Share Posted March 17, 2008 Yes Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494035 Share on other sites More sharing options...
pauleth Posted March 17, 2008 Share Posted March 17, 2008 It looks like the database is expecting a binary value of 1 or 0, and is receiving a string value. I agree that you should explicitly set the value to binary 1 or 0 in your PHP depending on whether or not it meets a particular condition, before inserting it into the DB... Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494037 Share on other sites More sharing options...
craygo Posted March 17, 2008 Share Posted March 17, 2008 well first thing is you never gave a value to the checkbox, so the value when checked will be "on". if you would like to pass a 1 then use <input type="checkbox" name="AudioClip" value="1" checked="checked" /> Ray Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494039 Share on other sites More sharing options...
rkstevens Posted March 17, 2008 Author Share Posted March 17, 2008 Got it working. Thanks for all of your help. I'll probably have more issues later as I convert a 100% static site into a dynamic one. Link to comment https://forums.phpfreaks.com/topic/96538-solved-checkbox-not-being-passed-to-database/#findComment-494046 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.