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

 

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]' , '' , '');

 

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.