Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Checkbox to what usergroup to save data.

Codes here !

Moderators: macek, egami, gesf

Checkbox to what usergroup to save data.

Postby faces » Mon Apr 22, 2013 4:01 am

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? ;)

Code: Select all
<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();
}
?>
Last edited by faces on Mon Apr 22, 2013 5:36 am, edited 1 time in total.
faces
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Mar 28, 2013 11:18 pm

Re: how choose table dropdown list where save form

Postby faces » Mon Apr 22, 2013 5:34 am

Checkboxes:
Code: Select all
<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:
Code: Select all
   $date = clear ($_POST['owner']);
   $date = clear ($_POST['worker']);


Database:
Code: Select all
   if(mysql_query("INSERT INTO news (id , postedby , news , subject , date) VALUES ('', '$postedby', '$news', '$subject', '$date', '$worker', '$owner')"))



Hmm its wrong i think.
faces
New php-forum User
New php-forum User
 
Posts: 11
Joined: Thu Mar 28, 2013 11:18 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.