jeudi 2 mars 2017

how i could save the checked data to be stored in a mysql table

i am trying to create a webpage displaying the products available in the mysql table. i created a code that helps me to display the mysql table data with in a table in a webpage in which the first table column contains checkboxes

so when user clicks the checkbox and click on submit button the values of the selected checkbox get stored in a another mysql table.

the below code helps me to display the content in a mysql table along with a checkbox for each row containing 5 fields what i should do to get the data selected from the checkbox to be stored in a another mysql table in which each check box contains multiple values pls any one provide me with a solution as soon as possible.

enter code here
# connect to mysql
$db_link = mysql_connect('localhost', 'root', '');
if (!$db_link)
die('Cannot connect : ' . mysql_error());

# select database`enter code here`
$db_selected = mysql_select_db('test_db', $db_link);
if (!$db_selected)
die ('Cannot select database : ' . mysql_error());

# execute search query
$sql = 'SELECT * FROM `test_table` ';
$result = mysql_query($sql);

# check result
if (!$result)
die('Could not successfully run query: ' . mysql_error());

# display returned data
if (mysql_num_rows($result) > 0)
{
?>
<form action="" method="post">
<table style="border: 1px solid black">
<table>
<tr>
<th></th>
<th>pid</th>
<th>pname</th>
<th>mfgdate</th>
<th>expdate</th>
<th>stock</th>
    ...
</tr>
<?php 
while ($row = mysql_fetch_assoc($result))
{
                echo '<tr><td>';
                echo '<input type="checkbox" name="selected[]" value="'.$row[selected].'"/>';
                echo '</td>';
                foreach ($row as $key => $value)
<td>{$row['pid']}</td>
    <td>{$row['pname']}</td>
<td>{$row['expdate']}</td>
<td>{$row['mfg date']}</td>
                    echo '<td>'.htmlspecialchars($value).'</td>';
                echo '</tr>';
            }
        ?>
    </table>
    <input type="submit"/>




Aucun commentaire:

Enregistrer un commentaire