Jump to content

News module where can change usergroup.


faces3
Go to solution Solved by lemmin,

Recommended Posts

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')"))
Link to comment
Share on other sites

  • Solution

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;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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