sandbudd Posted August 14, 2009 Share Posted August 14, 2009 Hey guys here is the form to retrieve the data but when it is changed it does not update the database.... <form enctype="multipart/form-data" action="test101.php" method="POST"><table border="1" cellpadding="3" cellspacing="0"> <?php // Fetch record rows in $result by while loop and put them into $row. while($row=mysql_fetch_assoc($result)){ ?> <tr> <td width="116" bgcolor="#FFFFCC">Company</td> <td width="371" bgcolor="#FFFFCC"><input name="company<?php echo $row['id']; ?>" type="text" id="company<?php echo $row['id']; ?>" value="<?php echo $row['company']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Company Bold</td> <td bgcolor="#FFFFCC"><input name="bold<?php echo $row['id']; ?>" type="text" id="bold<? echo $row['id']; ?>" value="<?php echo $row['bold']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Address</td> <td bgcolor="#FFFFCC"><input name="address<? echo $row['id']; ?>" type="text" id="address<? echo $row['id']; ?>" value="<? echo $row['address']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">City</td> <td bgcolor="#FFFFCC"><input name="city<? echo $row['id']; ?>" type="text" id="city<? echo $row['id']; ?>" value="<? echo $row['city']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">State</td> <td bgcolor="#FFFFCC"><input name="state<? echo $row['id']; ?>" type="text" id="state<? echo $row['id']; ?>" value="<? echo $row['state']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Phone</td> <td bgcolor="#FFFFCC"><input name="phone<? echo $row['id']; ?>" type="text" id="phone<? echo $row['id']; ?>" value="<? echo $row['phone']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Asian</td> <td bgcolor="#FFFFCC"><input name="asian<? echo $row['id']; ?>" type="text" id="asian<? echo $row['id']; ?>" value="<? echo $row['asian']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">American</td> <td bgcolor="#FFFFCC"><input name="american<? echo $row['id']; ?>" type="text" id="american<? echo $row['id']; ?>" value="<? echo $row['american']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Coffee</td> <td bgcolor="#FFFFCC"><input name="coffee<? echo $row['id']; ?>" type="text" id="coffee<? echo $row['id']; ?>" value="<? echo $row['coffee']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Fast Food</td> <td bgcolor="#FFFFCC"><input name="fastfood<? echo $row['id']; ?>" type="text" id="fastfood<? echo $row['id']; ?>" value="<? echo $row['fastfood']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Fun</td> <td bgcolor="#FFFFCC"><input name="fun<? echo $row['id']; ?>" type="text" id="fun<? echo $row['id']; ?>" value="<? echo $row['fun']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Italian</td> <td bgcolor="#FFFFCC"><input name="italian<? echo $row['id']; ?>" type="text" id="italian<? echo $row['id']; ?>" value="<? echo $row['italian']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Mexican</td> <td bgcolor="#FFFFCC"><input name="mexican<? echo $row['id']; ?>" type="text" id="mexican<? echo $row['id']; ?>" value="<? echo $row['mexican']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Pizza</td> <td bgcolor="#FFFFCC"><input name="pizza<? echo $row['id']; ?>" type="text" id="pizza<? echo $row['id']; ?>" value="<? echo $row['pizza']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Seafood</td> <td bgcolor="#FFFFCC"><input name="seafood<? echo $row['id']; ?>" type="text" id="seafood<? echo $row['id']; ?>" value="<? echo $row['seafood']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Fine Dining</td> <td bgcolor="#FFFFCC"><input name="upscale<? echo $row['id']; ?>" type="text" id="upscale<? echo $row['id']; ?>" value="<? echo $row['upscale']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Recommend</td> <td bgcolor="#FFFFCC"><input name="recommend<? echo $row['id']; ?>" type="text" id="recommend<? echo $row['id']; ?>" value="<? echo $row['recommend']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Email</td> <td bgcolor="#FFFFCC"><input name="email<? echo $row['id']; ?>" type="text" id="email<? echo $row['id']; ?>" value="<? echo $row['email']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Website</td> <td bgcolor="#FFFFCC"><input name="website<? echo $row['id']; ?>" type="text" id="website<? echo $row['id']; ?>" value="<? echo $row['website']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Photo</td> <td bgcolor="#FFFFCC"><input name="photo<? echo $row['id']; ?>" type="text" id="photo<? echo $row['id']; ?>" value="<? echo $row['photo']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Coupon</td> <td bgcolor="#FFFFCC"><input name="coupon<? echo $row['id']; ?>" type="text" id="coupon<? echo $row['id']; ?>" value="<? echo $row['coupon']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">Map</td> <td bgcolor="#FFFFCC"><input name="map<? echo $row['id']; ?>" type="text" id="map<? echo $row['id']; ?>" value="<? echo $row['map']; ?>" size="50" /></td> </tr> <tr> <td bgcolor="#FFFFCC">menu</td> <td bgcolor="#FFFFCC"><input name="menu<? echo $row['id']; ?>" type="text" id="menu<? echo $row['id']; ?>" value="<? echo $row['menu']; ?>" size="50" /></td> </tr> <tr> <td colspan="2" bgcolor="#FFFFFF"><hr></td> </tr> <? } // End while loop. ?> </table> <input type="submit" name="Submit" value="Update" /> </form> test101.php <?php if($_POST['Submit']){ // If receive Submit button variable. // Connect database. $host=""; // Host name. $db_user=""; // MySQL username. $db_password=""; // MySQL password. $database=""; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); $result=mysql_query("SELECT * FROM employees WHERE company LIKE 'a%'"); // Fetch record rows in $result by while loop and put them into $row. while($row=mysql_fetch_assoc($result)){ $company=$_POST["company".$row[id]]; $bold=$_POST["bold".$row[id]]; $address=$_POST["address".$row[id]]; $city=$_POST["city".$row[id]]; $state=$_POST["state".$row[id]]; $phone=$_POST["phone".$row[id]]; $asian=$_POST["asian".$row[id]]; $american=$_POST["american".$row[id]]; $coffee=$_POST["coffee".$row[id]]; $fun=$_POST["fun".$row[id]]; $italian=$_POST["italian".$row[id]]; $mexican=$_POST["mexican".$row[id]]; $seafood=$_POST["seafood".$row[id]]; $upscale=$_POST["upscale".$row[id]]; $recommend=$_POST["recommend".$row[id]]; $email=$_POST["email".$row[id]]; $website=$_POST["website".$row[id]]; $photo=$_POST["photo".$row[id]]; $coupon=$_POST["coupon".$row[id]]; $map=$_POST["map".$row[id]]; $fastfood=$_POST["fastfood".$row[id]]; $pizza=$_POST["pizza".$row[id]]; $menu=$_POST["menu".$row[id]]; // Update field "name", matching with "id" value by while loop. mysql_query("update employees set company='$company', bold='$bold', address='$address', city='$city', state='$state', phone='$phone', asian='$asian', american='$american', coffee='$coffee', fun='$fun', italian='$italian', mexican='$mexican', seafood='$seafood', upscale='$upscale', recommend='$recommend', email='$email', website='$website', photo='$photo', coupon='$coupon', map='$map', pizza='$pizza', fastfood='$fastfood', menu='$menu' where id='$row[id]'"); } echo "--- Update Complete ---"; } ?> Link to comment https://forums.phpfreaks.com/topic/170293-solved-wont-update-the-database/ Share on other sites More sharing options...
MatthewJ Posted August 14, 2009 Share Posted August 14, 2009 Add or die (mysql_error()) to see if it is giving any errors when trying to run the update. Link to comment https://forums.phpfreaks.com/topic/170293-solved-wont-update-the-database/#findComment-898287 Share on other sites More sharing options...
sandbudd Posted August 14, 2009 Author Share Posted August 14, 2009 I found the error duh.... Link to comment https://forums.phpfreaks.com/topic/170293-solved-wont-update-the-database/#findComment-898288 Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 you need single quotes around the keys of associate arrays. so this where id='$row[id]' shoule be where id='" . $row['id'] . "' Hope that helps! Link to comment https://forums.phpfreaks.com/topic/170293-solved-wont-update-the-database/#findComment-898291 Share on other sites More sharing options...
sandbudd Posted August 14, 2009 Author Share Posted August 14, 2009 $result=mysql_query("SELECT * FROM employees WHERE company LIKE 'a%'"); only needs to be $result=mysql_query("SELECT * FROM employees"); as it is searching the entire database Link to comment https://forums.phpfreaks.com/topic/170293-solved-wont-update-the-database/#findComment-898292 Share on other sites More sharing options...
sandbudd Posted August 14, 2009 Author Share Posted August 14, 2009 and that works like a charm...sorry for the post was just to close to see it until after I posted. Link to comment https://forums.phpfreaks.com/topic/170293-solved-wont-update-the-database/#findComment-898294 Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 oh, I wondered why you had that like at the end Link to comment https://forums.phpfreaks.com/topic/170293-solved-wont-update-the-database/#findComment-898295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.