Hi All,
Help me please.
I want insert to people_go table using checkbox.

data.sql

CREATE TABLE `people` (
  `id` int(11) NOT NULL auto_increment,
  `p_id` varchar(20) NOT NULL,
  `name` varchar(50) NOT NULL,
  PRIMARY KEY  (`p_id`),
  KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;

INSERT INTO `people` VALUES (1, 'P001', 'Ana');
INSERT INTO `people` VALUES (2, 'P002', 'Ani');
INSERT INTO `people` VALUES (3, 'P003', 'Anu');
INSERT INTO `people` VALUES (4, 'P004', 'Tina');
INSERT INTO `people` VALUES (5, 'P005', 'Tini');
INSERT INTO `people` VALUES (6, 'P006', 'Tinu');


CREATE TABLE `people_go` (
  `id` int(11) NOT NULL auto_increment,
  `p_id` varchar(20) NOT NULL,
  `name` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  PRIMARY KEY  (`p_id`),
  KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

index.php

<html>
<head>
  <title>Going to City</title>  
</head>
<body>
<h1>Insert to People_go Table</h1>
<?php
mysql_connect("localhost", "root", "blabla");
mysql_select_db("smsd");

$query = "SELECT * FROM people";
$hasil = mysql_query($query);

echo "<form name='myform' method='post' action='".$_SERVER['PHP_SELF']."?action=submit'>";
echo "<table border='1'>";
echo "<tr><td></td><td><b>p_id</b></td><td><b>Name</b></td><td><b>Go to City</b></td></tr>";
$i = 0;
while($data = mysql_fetch_array($hasil))
{
  echo "<tr><td><input type='checkbox' name='p_id".$i."' value='".$data['p_id']."' /></td><td>".$data['p_id']."</td><td>".$data['name']."</td>

  <td>
  <select name='karena' >
  <option value=''>Select City<selected></option>
  <option value='A'>City A</option>
  <option value='B'>City B</otion>
  <option value='C'>City C</option>
  <option value='D'>City D</option>
  <option value='E'>City E</option>
  </select>
  </td>
  </tr>";
}
echo "</table>";
echo "<p><input type='submit' value='Submit' name='submit'> <input type='reset' value='Reset' name='reset'></p>";
echo "</form>";


// I Want Insert to people_go table using checkbox.
// Insert Into people_go (p_id,name,city).
// Help me, How to create php code.
// thank you.
?>

</body>
</html>

Thank you.

Member Avatar for LastMitch

I want insert to people_go table using checkbox.

I don't understand your question? Did you write this code?

I don't seen to see an INSERT statement. Was there any error when you ran the code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.