Jump to content

[SOLVED] Checkbox not being passed to database


rkstevens

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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.