php - Storing database value into variable -
my table category has these columns:
idcategory categorysubject users_idusers
i have form simple radio buttons , textbox. have select statement category , need idcategory stored variable ($getcatid) can use statement:
$sql="insert topic(subject, topicdate, users_idusers, category_idcategory, category_users_idusers) values('($_post[topic])', '$date', '$_session[userid]', '$getcatid', '$_session[userid]');";
what best way , store categoryid?
if($_server['request_method'] != 'post') //show form if not posted { $sql = "select * category;"; $result = mysqli_query($conn,$sql); ?> <form method="post" action="createtopic.php"> choose category: </br> </br> <?php while ($row = mysqli_fetch_assoc($result)) { echo "<div class= 'choice'><input type='radio' name='category' value='". $row['idcategory'] . "'>" . $row['categorysubject'] ."</div></br>"; } echo 'topic: <input type="text" name="topic" minlength="3" required> </br></br> <input type="submit" value="add topic" required> </form>'; } if ($_post){ if(!isset($_session['signedin']) && $_session['signedin'] == false) { echo 'you must signed in contribute'; } else{ $sql="insert topic(subject, topicdate, users_idusers, category_idcategory, category_users_idusers) values('($_post[topic])', '$date', '$_session[userid]', '$getcatid', '$_session[userid]');"; $result = mysqli_query($conn,$sql); echo "added!";
if understand question correctly, you'll have $getcatid
(id of category) in $_post['category']
(after sending form) in case
Comments
Post a Comment