
Loading ...
November24
Ok,
I create 3 files and 1 database with 1 table.
select3.php this is the form
select4.php this is the function for sending to the database
display.php this is to display result from database
MySQL Database structure:
Table structure for table `multiple`
CREATE TABLE `multiple` (
`id1` int(4) NOT NULL auto_increment,
`id` varchar(4) default '1',
`test` varchar(255) default '2',
PRIMARY KEY (`id1`)
) TYPE=MyISAM AUTO_INCREMENT=45 ; |
|
select3.php
<html>
<head>
<title>Select Multiple Box</title>
</head>
<body>
<table width=”300″ cellpadding=”5″ cellspacing=”0″ border=”2″>
<tr align=”center” valign=”top”>
<td align=”left” bgcolor=”#FFFFFF”>
<h3>Insert Record <a href=”display.php”>Display result </a></h3>
<form method=”POST” action=”select4.php”>
<!–The hidden fields are provided to maintain state. They are used to pass the username and password from script to script.–>
<input type=”hidden” name=”username” value=”<? print $_POST['id']?>“>
<?php
print “Enter name: <input type=text name=id size=20><br>\n”;
print “Select Items: <select name=test[] size=5 multiple >
<option value=item1 >item1</option>
<option value=item2 >item2</option>
<option value=item3 >item3</option>
<option value=item4 >item4</option>
<option value=item5 >item5</option>
<option value=item6 >item6</option>
<option value=item7 >item7</option>
</select><br>\n”;
print “<br>\n”;
print “(Shif+Right Mouse) for multiple selection<br>\n”;
print “<br>\n”;
print “<input type=submit value=Submit><input type=reset>\n”;
?>
</form></td></tr></table>
</body>
</html> |
|
select4.php
<html>
<head>
<title>Birthdays Insert Record</title>
</head>
<body>
<?php
$id=$_POST['id'];
$test=$_POST['test'];
$db=“select”;
$link = mysql_connect(“localhost”,“root”,“”);
//$link = mysql_connect(”localhost”,$_POST['username'],$_POST['password']);
if (! $link)
die(“Couldn’t connect to MySQL”);
mysql_select_db($db , $link) or die(“Select Error: “.mysql_error());
//for($i=0;$i<sizeof($_POST["test"]);$i++)
//{
//$sql = “insert into tbl_name values ($_POST["test"][$i])”; }
//sql = “INSERT INTO table_name VALUES (’” . join(”,”,$_POST["test"]) . “‘)”;
$result=mysql_query(“INSERT INTO multiple (id, test) VALUES (’$id’,'” . join(“,”,$_POST["test"]) . “‘)”)or die(“Insert Error: “.mysql_error());
mysql_close($link);
print “Record added\n”;
?>
<a href=”display.php”>Display Records</a>
<form method=”POST” action=”select3.php”>
<input type=”submit” value=”Insert Another Record”>
</form>
</body>
</html> |
|
display.php
<html>
<head>
<title>(Title Here)</title>
</head>
<body>
<?php
$db=“select”;
$link = mysql_connect(“localhost”,“root”,“”);
if (! $link)
die(“Couldn’t connect to MySQL”);
mysql_select_db($db , $link)
or die(“Couldn’t open $db: “.mysql_error());
$result = mysql_query( “SELECT * FROM multiple” )
or die(“SELECT Error: “.mysql_error());
$num_rows = mysql_num_rows($result);
print “There are $num_rows records.<P>”;
print “<table width=200 border=1>\n”;
while ($get_info = mysql_fetch_row($result)){
print “<tr>\n”;
foreach ($get_info as $field)
print “\t<td><font face=arial size=1/>$field</font></td>\n”;
print “</tr>\n”;
}
print “</table>\n”;
mysql_close($link);
?>
<a href=”select3.php”>Back</a>
</body>
</html> |
data is missing, cant get your point