MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

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 January 1st, 2005, 12:42 PM
new_php new_php is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 new_php User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Updating array to database from php

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>

Reply With Quote
  #2  
Old January 1st, 2005, 03:29 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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'];

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Updating array to database from php


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 6 hosted by Hostway
Stay green...Green IT