|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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> </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> |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > hi! need help with inserting multiple records via checkboxes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|