faces3 Posted April 22, 2013 Share Posted April 22, 2013 I have one database where is table like "owner", "admin","worker". Now i want checkbox for that form where can choose what user group it save. Have someone idea how to do it? <form method="post" action="#"> Posted By:<br /><input name="postedby" id="postedby" type="Text" size="50" maxlength="50"><br /> Subject:<br /><input name="subject" id="subject" type="Text" size="50" maxlength="50"><br /> <textarea name="news" id="news" cols="50" rows="5"></textarea><br /> <input type="Submit" name="submit" id="submit" value="Enter News"> </form> <?php function clear($message) { if(!get_magic_quotes_gpc()) $message = addslashes($message); $message = strip_tags($message); $message = htmlentities($message); return trim($message); } if ($_POST['submit']) { if (empty($_POST['postedby'])) die('Enter a name.'); else if (empty($_POST['subject'])) die('Enter a subject.'); else if (empty($_POST['news'])) die('Enter an article.'); $postedby = clear($_POST['postedby']); $subject = clear($_POST['subject']); $news = clear($_POST['news']); $date = mktime(); mysql_connect('localhost','username','password'); mysql_select_db('db'); if(mysql_query("INSERT INTO news (id , postedby , news , subject , date) VALUES ('', '$postedby', '$news', '$subject', '$date')")) echo 'News Entered.'; mysql_close(); } ?> I try do it... but its wrong.... Checkboxes: <input type="checkbox" name="worker" id="worker">Send news to worker<br> <input type="checkbox" name="owner" id="owner">Send news to owner<br> Submit: $date = clear ($_POST['owner']); $date = clear ($_POST['worker']); Save to database: if(mysql_query("INSERT INTO news (id , postedby , news , subject , date) VALUES ('', '$postedby', '$news', '$subject', '$date', '$worker', '$owner')")) Quote Link to comment Share on other sites More sharing options...
Solution lemmin Posted April 22, 2013 Solution Share Posted April 22, 2013 With your HTML, $_POST['owner'] and $_POST['worker'] will either contain 'on' or not be set at all. Assuming you want to set a boolean flag in your database, you could put this before your query: $owner = isset($_POST['owner']) ? 1 : 0; $worker = isset($_POST['worker']) ? 1 : 0; Quote Link to comment Share on other sites More sharing options...
faces3 Posted April 22, 2013 Author Share Posted April 22, 2013 Thank you very much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.