Jump to content


Photo

News module where can change usergroup.


Best Answer lemmin, 22 April 2013 - 02:12 PM

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;
Go to the full post


  • Please log in to reply
2 replies to this topic

#1 faces3

faces3

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 22 April 2013 - 01:27 PM

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')"))


#2 lemmin

lemmin

    Advanced Member

  • Members
  • PipPipPip
  • 1,906 posts

Posted 22 April 2013 - 02:12 PM   Best Answer

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;


#3 faces3

faces3

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 22 April 2013 - 04:38 PM

Thank you very much :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com