aftab_jii Posted April 14, 2010 Share Posted April 14, 2010 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 https://forums.phpfreaks.com/topic/198570-radio-button-value-not-passed-onto-mysql-table/ Share on other sites More sharing options...
predator12341 Posted April 14, 2010 Share Posted April 14, 2010 which of your values are the radio buttons? Link to comment https://forums.phpfreaks.com/topic/198570-radio-button-value-not-passed-onto-mysql-table/#findComment-1042037 Share on other sites More sharing options...
Pikachu2000 Posted April 15, 2010 Share Posted April 15, 2010 Your radio button array is echoed in the while loop outside the <form></form> tags. Thus, the values are not being passed. Link to comment https://forums.phpfreaks.com/topic/198570-radio-button-value-not-passed-onto-mysql-table/#findComment-1042195 Share on other sites More sharing options...
aftab_jii Posted April 15, 2010 Author Share Posted April 15, 2010 i have moved it inside the <form></form> but still nothing happens Link to comment https://forums.phpfreaks.com/topic/198570-radio-button-value-not-passed-onto-mysql-table/#findComment-1042358 Share on other sites More sharing options...
aftab_jii Posted April 15, 2010 Author Share Posted April 15, 2010 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 https://forums.phpfreaks.com/topic/198570-radio-button-value-not-passed-onto-mysql-table/#findComment-1042373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.