Reputation: 25
Can someone help me please, I am trying to implement a simple php MySQL survey, but I am stuck on this, how do I store the specific selection in MySQL that users select.
How satisfied are you:
<table id="table1" rules="all" border="1" cellpadding="3" cellspacing="0" width="70%">
<colgroup width="70%"></colgroup>
<colgroup width="6%">
</colgroup>
<thead>
<tr align="center">
<th></th>
<th font="" style="font-size:9pt;" size="2"><b>Dissatisfied</b></th>
<th font="" style="font-size:9pt;" size="2"><b>Satisfied</b></th>
<th font="" style="font-size:9pt;" size="2"><b>Very Satisfied</b></th>
</tr>
</thead>
<tbody>
<tr align="center">
<td align="left"><font style="font-size:10pt;"><b>Technician's ability to understand the unique nature of your problem?</b></font></td>
<td><input name="satisfaction" value="Dissatisfied" type="radio"></td>
<td><input name="satisfaction" value="Satisfied" type="radio"></td>
<td><input name="satisfaction" value="Very Satisfied" type="radio"></td>
</tr>
<tr align="center">
</tbody>
</table>
Upvotes: 1
Views: 1409
Reputation: 297
As simple as :
1st, Add this line before the table tag:
<form method="post" action="">
2nd, this one at the end of your code:
<input type="submit" name="submit" value="Submit">
</form>
Then you can have this code for inserting in the DB.
if ($stmt = $mysqli->prepare("INSERT INTO TABLENAME(COLUMN NAME) values (?)")) {
$stmt->bind_param('s', $satisfaction);
$satisfaction=$_POST['satisfaction'];
$stmt->execute();
$stmt->close();
}
Upvotes: 1
Reputation: 589
for this what you need will need a form to submit data selection. You will need two php files
The first one is to built a form of radio buttons. I had removed table's elements for neat view then we set the URL of the second page .Can also be a single page if you want but this is more easier.
feedback.php
<form action="add.php" method="post" accept-charset="utf-8">
<input name="satisfaction" value="Dissatisfied" type="radio">Dissatisfied<br>
<input name="satisfaction" value="Satisfied" type="radio">Satisfied<br>
<input name="satisfaction" value="Very Satisfied" type="radio">Very Satisfied<br>
<input type='submit' value="submit">
</form>
In the second page we catch what we had posted from first page.
add.php
$result= $_POST['satisfaction'];
echo $result;
using $result to store in your database. Good luck
Upvotes: 2