General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 16th, 2003, 12:47 AM
lisa_alias lisa_alias is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 lisa_alias User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi! need help with inserting multiple records via checkboxes

hi there..
i'm a newbie in PHP. i need some help to insert multiple new records by checking the checkboxes - choose desired items, and save each of them into the database.

what i have done, only the last record in the array been saved into the table. what about the first, second.. etc..??

i guess i have problem with the looping part. is there any function in PHP or simple looping codes to resolve this looping problem?

please help... thanks...

here's my code:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<? require 'connectgitn.inc';
$proj_code = 'HRM';
?>

<form name="form1" method="post" action="<?=$PHPSELF?>">
<table width="60%" border="1">
<tr>
<td><b>site_code</b></td>
<td><b>proj_code</b></td>
<td><b></b></td>
</tr>
<?
$sql = "select * from site";
$db = mysql_db_query($dbname,$sql,$dblink);
//$row = mysql_fetch_array($db);
$countRow = 0;
while($row = mysql_fetch_array($db))
{
++$countRow; $site_code = $row["site_code"];
?>
<tr>
<td><? echo $site_code; ?></td>
<td><? echo $proj_code; ?></td>
<td>
<input type="checkbox" name="add" value="<? echo $site_code?>">
</td>
</tr> <? } mysql_free_result($db);
?>

</table>
<p>
<input type="submit" name="Submit" value="ADD">
</p>
<p>&nbsp;</p>

<?
if(isset($Submit))
{
if($Submit == "ADD")
{
//for($i = 0; $i < '10'; $i++)
//{
if(isset($add))
{
$sql1 = "select max(sbp_code) from site_by_project";
$db1 = mysql_db_query($dbname,$sql1,$dblink);
while($nilai = mysql_fetch_array($db1))
{
$current_sbp = $nilai[0] + 1;
}
mysql_free_result($db1);
echo "YTYGUHJBHJJHG---".$site_code;
$sql2 = "insert into site_by_project set sbp_code = '$current_sbp', site_code = '$site_code', proj_code = '$proj_code'";
if(mysql_db_query($dbname,$sql2,$dblink)){ echo "SAVE!!!"; }
}
//}
}
}
?>


</form>
</body>
</html>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > hi! need help with inserting multiple records via checkboxes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT