|
 |
|
การส่งไฟล์ถึงหลายๆ คนโดยใช้ check box นี่โค้ดเลือกรายชื่อจาก check box ครับแล้วมันจะส่งค่าไปอีกหน้าหนึ่ง |
|
 |
|
|
 |
 |
|
นี่โค้ดเลือกรายชื่อจากcheck boxครับแล้วมันจะส่งค่าไปอีกหน้าหนึ่ง
<?php
$sql = "select * from i_member";
$res = mysql_db_query($db,$sql);
while($arr = mysql_fetch_array($res))
{
?>
<input name="Qto" type="checkbox" id="Qto"value="<? echo $arr[name] ?>" />
php echo $arr[name] ?>
<?php
}
ส่งมาหน้านี้ครับโค้ดเก็บลงฐานข้อมูล
mysql_connect($host, $username, $password) or die(mysql_error());
$sql = "INSERT INTO `i_book_user` ( `book_id` , `story` , `sendto` , `refer` , `description` , `iupdate` , `Datafile1` , `Datafile2` , `Datafile3` , `Datafile4` , `Datafile5`, `name`, `Category`, `Email` ) VALUES ( '$Qbook_id', '$Qstory', '$Qto', '$Qrefer', '$Qdescription', '$mdate', '$QDatafile_name1', '$QDatafile_name2', '$QDatafile_name3', '$QDatafile_name4', '$QDatafile_name5', '$Qname', '$QCategory','$QEmail' )";
คือผมอยากจะให้มันวนลูปเก็บรายชื่อจากcheck boxแล้วเก็บข้อมูลของแต่ล่ะคนลงในฐานข้อมูลแยกกันต้องทำยังไงครับตอนนี้เก็บลงแค่คนแรกที่เราเลือก
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-05-13 17:46:38 |
By :
anamasus |
View :
1026 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (form.php)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<script language="JavaScript">
function onSave()
{
if(confirm('Do you want to save ?')==true)
{
return true;
}
else
{
return false;
}
}
</script>
<form name="frmMain" action="save.php" method="post" OnSubmit="return onSave();">
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
<th width="30"> <div align="center">Select </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
<td align="center"><input type="checkbox" name="chkEmail[]" value="<?=$objResult["Email"];?>"></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
<input type="submit" name="btnSave" value="Save">
</form>
</body>
</html>
Code (save.php)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
for($i=0;$i<count($_POST["chkEmail"]);$i++)
{
if($_POST["chkEmail"][$i] != "")
{
$strSQL = "INSERT INTO table_name (Mail) VALUES ('".$_POST["chkEmail"][$i]."')";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
}
}
echo "Record Insert.";
mysql_close($objConnect);
?>
</body>
</html>
Go to : PHP Multiple Checkbox
|
 |
 |
 |
 |
Date :
2011-09-18 17:17:32 |
By :
tc |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|