Jump to content

Radio button value not passed onto mySQL table


aftab_jii

Recommended Posts

Hi,

I am having a little bit of trouble passing the value of radio-button into a mySQL database.

The script below (compose.php) reads the value of article_category from table article_category

But the values does not pass on to mySQL table..the column category in table articles (transact-article.php) remains empty.

Can anyone tell me what i am missing?

<?php
//compose.php
require_once ('files/configure_impressions.php');

$title = '';
$body = '';
$article = '';
$authorid = '';
if (isset($_GET['a'])
    and $_GET['a'] == 'edit'
    and isset($_GET['article'])
    and $_GET['article']) {
  $sql = "SELECT category,title,body,author_id FROM articles " .
         "WHERE article_id=" . $_GET['article'];
  $result = mysql_query($sql, $mylink)
    or die('Could not retrieve article data; ' . mysql_error());

  $row = mysql_fetch_array($result);

  $title = $row['title'];
  $body = $row['body'];
  $article = $_GET['article'];
  $authorid = $row['author_id'];

}
?>



<h2>Compose Article</h2>

<?php

  $sql = "SELECT * FROM article_category ORDER BY article_category ASC";
  $result = mysql_query($sql)
    or die('Could not list access levels; ' . mysql_error());
  while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {

echo '<input type="radio" name="category" value="' . $row['article_category'] . '">';
echo ' ' . $row['article_category'];
echo '   ';
}

?>

<form method="post" action="transact-article.php?category="<?php echo $row['article_category']; ?>" \>
<p>
  Title:<br>
  <input type="text" class="title" name="title" maxlength="255"
    value="<?php echo htmlspecialchars($title); ?>">
</p>
<p>
  Body:<br>
  <textarea class="body" name="body" rows="10" cols="60"><?php
    echo htmlspecialchars($body); ?></textarea>
</p>
<p>
<?php
echo '<input type="hidden" name="article" value="' .
     $article . "\">\n";

if ($_SESSION['access_lvl'] < 2) {
  echo '<input type="hidden" name="authorid" value="' .
       $authorid . "\">\n";
}

if ($article) {
  echo '<input type="submit" class="submit" name="action" ' .
       "value=\"Save Changes\">\n";
} else {
  echo '<input type="submit" class="submit" name="action" ' .
       "value=\"Submit New Article\">\n";
}
?>
</p>
</form>

 

<?php
.
.
.
.
.
//transact-article.php
case 'Submit New Article':
      if (isset($_GET['article_category'])
          and isset($_POST['title'])
          and isset($_POST['body'])
          and isset($_SESSION['user_id']))
      {
        $sql = "INSERT INTO articles " .
               "(category, title, body, author_id, date_submitted) " .
               "VALUES ('" . $_GET['article_category'] .
               "','" . $_POST['title'] .
               "','" . $_POST['body'] .
               "'," . $_SESSION['user_id'] . ",'" .
               date("Y-m-d H:i:s", time()) . "')";

        mysql_query($sql, $mylink)
          or die('Could not submit article; ' . mysql_error());
      }
      //redirect('cpl.php');
      break;
.
.
.
.
?>

Link to comment
Share on other sites

okey..managed to solve it..

here is how:

 

//compose.php
[b]<h2>Compose Article</h2>

<form method="post" action="transact-article.php?category=" . <?php echo $row['article_category']; ?> \>

<?php

if ($row['category'] != "") {
?>
<p><br> Article curretly published in <font color='red'><?php echo $category;?></font> </p></br>
<?php
} else {
echo "";
 }

  $sql = "SELECT * FROM article_category WHERE status = '1' ORDER BY article_category ASC";
  $result = mysql_query($sql)
    or die('Could not list access levels; ' . mysql_error());
  while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
  $c = $row['article_category'];
echo '<input type="radio" name="category" value="' . $c . '" checked \>';
echo ' ' . $c;
echo '   ';
}
[/b]?>

<p>
  Title:<br>
  <input type="text" class="title" name="title" maxlength="255"
    value="<?php echo htmlspecialchars($title); ?>">
</p>
<p>
  Body:<br>
  <textarea class="body" name="body" rows="10" cols="60"><?php
    echo htmlspecialchars($body); ?></textarea>
</p>
<p>
<?php
echo '<input type="hidden" name="article" value="' .
     $article . "\">\n";

if ($_SESSION['access_lvl'] < 2) {
  echo '<input type="hidden" name="authorid" value="' .
       $authorid . "\">\n";
}

if ($article) {
  echo '<input type="submit" class="btn" name="action" ' .
       "value=\"Save Changes\">\n";
} else {
  echo '<input type="submit" class="btn" name="action" ' .
       "value=\"Submit New Article\">\n";
}
?>
</p>
</form>

 

and the changes in transact-aticle.php

 

case 'Submit New Article':
      if ([b]isset($_POST['category'])[/b]
          and isset($_POST['title'])
          and isset($_POST['body'])
          and isset($_SESSION['user_id']))
      {
        $sql = "INSERT INTO articles " .
               "(category, title, body, author_id, date_submitted) " .
               "VALUES ('" . [b]$_POST['category'][/b] .
               "','" . $_POST['title'] .
               "','" . $_POST['body'] .
               "'," . $_SESSION['user_id'] . ",'" .
               date("Y-m-d H:i:s", time()) . "')";

        mysql_query($sql, $mylink)
          or die('Could not submit article; ' . mysql_error());
      }
      redirect('cpl.php');
      break;

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.