|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
This is my first programming assigment i... can anyone help. I want to update an array(red color code) to mysql from php here below is the code:and the code doesn;t work.
<? session_start(); $this_memberid =$_SESSION['memberid']; require_once("DB.php"); require_once("PEARConnect.php"); if (is_null ($buttonClicked)){ $this_memberid =$_SESSION['memberid']; echo $this_memberid; $stm= " select f.facDesc, f.facCost, m.facType, m.memberid from facilitytype as f, memberfacility as m where f.facType = m.facType && m.memberid='anadom' order by memberid"; echo $stm.'<br>'; $qry1 =$db->query($stm); if (DB::isError($qry1)) die($qry1->getMessage()); while ($record = $qry1->fetchRow()){ //********retrieve and display customer record $memberid=$record['memberid']; $facCost =$record['facCost']; $facDesc =$record['facDesc']; $facType =$record['facType']; echo $memberid.'<br>'; echo $facCost.'<br>'; echo $facDesc.'<br>'; echo $facType.'<br>'; if($record['facType']=='SP') {$checked1 ="checked"; } if($record['facType']=='GY'){ $checked2 = "checked"; echo $checked2.'<br>'; } if($record['facType']=='TC'){ $checked3 = "checked"; echo $checked3.'<br>'; } if($record['facType']=='BC'){ $checked4 = "checked"; echo $checked4.'<br>'; } if($record['facType']=='SC'){ $checked5 = "checked"; echo $checked5.'<br>'; } } $qry1->free(); $db->disconnect(); ?> <body> <tr> <td> <Form Action ="<?php echo$php_self; ?>" method ="post"> <table width ="700"> <tr> <td COLSPAN=5>Please choose type of Facility that you wish to cover in your membership::<br /></td> </tr> <tr> <td width>Swimming Pool:</td> <td> <input type="checkbox" value="SP" name="swim"<?echo $checked1; ?>>:<br /><td> <td width=>Gym: <td><input type="checkbox" value="GY" name="gym"<? echo $checked2; ?>>:<br /></td> <td width=>Tennis Court:</td> <td><input type="checkbox" value="TC" name="tennis" <? echo $checked3; ?>>:<br/></td> <td width=>Badminton Court: <td><input type="checkbox" value="BC" name="bad"<? echo $checked4; ?>>:<br/></td> <td width=>Squash Court:</td> <td><input type="checkbox" value="SC" name="squash"<? echo $checked5; ?>>:<br/><td> </tr> <tr><td> Select a Level of Grade:<br /> <select name="Grade Level"> <option value="GOLD">GOLD</option> <option value="SILVER">SILVER</option> <option value="BRONZE">BRONZE</option></select>:<br /> </td></tr> <tr> <td><input type="submit" name ="submit_ query" value"Update"/></td> </tr> </table> </form> </td> </tr> <? } else { // ********** here is the data i wants to update into the database. // and the code doesn;t work. require_once('DB.php'); requre_once('PEARConnect.php'); $Fac_record['0'] = $HTTP_POST_VARS['swim']; $Fac_record['1']= $HTTP_POST_VARS['gym']; $Fac_record['2'] = $HTTP_POST_VARS['tennis']; $Fac_record['3'] = $HTTP_POST_VARS['badminton']; $Fac_record['4']= $HTTP_POST_VARS['squash']; for($i=0 ; $i<5 ; $i++){ $sql ="Update memberfacility set facType ='$fac_record[$i]' Where memberID='anadom'"; echo $sql; $qry2 =$db->query($sql); } echo "complete"; $qry2->free(); $db->disconnect(); } ?> </body> </html> |
|
#2
|
||||
|
||||
|
Notice: $Fac_record['0'] and $fac_record[0] will not provide the same results...
You try adding quotes around $i in your $sql line. Second thought, that might not work the way you intend it to... Try taking away the quotes from the actual array declarations. Example: $Fac_record[0] = $HTTP_POST_VARS['swim']; |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Updating array to database from php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|