PDA

View Full Version : check box form sending info to a mysql db


losse
04-17-2006, 10:24 PM
Hi there
Just have a question, I have a checkbox on a form where the user can check on or off and I would like to store that check into a database.

I was wondering how that field would look like in the database and how it would be quiered on the form.

Ideally I would like the database field to say YES if they checked it and NO if they didn't?

So on the form I would have

contact me: <input type="checkbox" name="contact"/>

and what would the "INSERT into" script look like to input whether they checked it or not be so that in my DB it would say YES if they did and NO if they didn't?

Thanks

DoNNo
04-18-2006, 08:24 AM
what you mean by "I would like the database field to say YES if they checked it and NO if they didn't?"??
you want an alert message or just wanna keep YES or NO in your database??

losse
04-18-2006, 01:11 PM
So let's say you have a check box on an HTML form that asks the user if he would like to be contacted for future mailings and they check it off, it enters a YES in the DB in that field. And if they don't check it, it keeps a NO in the DB...

Let me know if you want me to clarify more...

Thanks

degsy
04-18-2006, 04:04 PM
You need to give your checkbox a value. That is basic HTML.



<input type="checkbox" name="contact" value="YES" />



if(isset($_POST['contact'])){
$contact = 'YES';
}
else{
$contact = 'NO';
}
sql="UPDATE table SET field = '$contact' WHERE id=$user_id"