clanstyles Posted June 30, 2007 Share Posted June 30, 2007 $values[0] = $_REQUEST['name']; $values[1] = $_REQUEST['email']; $values[2] = $_REQUEST['address']; $values[3] = $_REQUEST['state']; $values[4] = $_REQUEST['city']; $values[5] = $_REQUEST['zip']; $values[6] = $_REQUEST['type']; $values[7] = $_REQUEST['footage']; $values[8] = $_POST['approved']; mysql_query("update `houses` set `name`='".$values[0]."', `email`='".$values[1]."', `address`='".$values[2]."', `state`='".$values[3]."', `city`='".$values[4]."', `zip`='".$values[5]."', `type`='".$values[6]."', `footage`='".$values[7]."', `enabled`='".$values[8]."' WHERE `id`='".$_POST['id']."'") or die(mysql_error()); I can't get this to work. It doesn't update anything. Quote Link to comment Share on other sites More sharing options...
corbin Posted June 30, 2007 Share Posted June 30, 2007 Does it show any form of error? Also, why are you using REQUEST? That leaves the script open to all kinds of SQL injection. Edit: To correct my self, that speciffically doesn't open it up to SQL injection, but it can be harder to clean data if you don't know where it's coming from. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 30, 2007 Author Share Posted June 30, 2007 $_REQUEST because $_POST doesn't always work. Its a form i'm updating. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 30, 2007 Author Share Posted June 30, 2007 bump :-/ Quote Link to comment Share on other sites More sharing options...
corbin Posted June 30, 2007 Share Posted June 30, 2007 Some where in your code echo out the query, and tell us what it says. And ummmm why isn't POST always working? Do you have POST set as the method on the form? If you don't, then that could be the problem since it could be sending it through GET, and you're trying to update based off of a $_POST variable. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 30, 2007 Author Share Posted June 30, 2007 <form id="admin" enctype="multipart/form-data" name="admin" method="post" action="?page=admin&action=edit&id=<?php echo $_REQUEST['id']; ?>"> <table border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td>Name:</td> <td><label> <input type="text" name="name" id="name" value="<?php echo $f['name']; ?>" /> </label></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" value="<?php echo $f['email']; ?>" /></td> </tr> <tr> <td>Address:</td> <td><input type="text" name="address" id="address" value="<?php echo $f['address']; ?>" /></td> </tr> <tr> <td>State:</td> <td><input type="text" name="state" id="state" value="<?php echo $f['state']; ?>" /></td> </tr> <tr> <td>City:</td> <td><input type="text" name="city" id="city" value="<?php echo $f['city']; ?>" /></td> </tr> <tr> <td>Zip:</td> <td><input type="text" name="zip" id="zip" value="<?php echo $f['zip']; ?>" /></td> </tr> <tr> <td>Type:</td> <td><input type="text" name="type" id="type" value="<?php echo $f['type']; ?>" /></td> </tr> <tr> <td>Square Feet:</td> <td><input type="text" name="footage" id="footage" value="<?php echo $f['footage']; ?>" /></td> </tr> <tr> <td>Approved:</td> <td><select name="approved" size="2" id="approved"> <option value="1" <?php if($f['enabled'] == "1") echo "selected=\"selected\""; ?>>approved</option> <option value="0" <?php if($f['enabled'] == "0") echo "selected=\"selected\""; ?>>unapproved</option> </select></td> </tr> <tr> <td colspan="2"><label> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="button" name="Delete" id="Delete" value="Delete" /> </label></td> Thats the form..mabye i fucked that up and i dk lol Quote Link to comment Share on other sites More sharing options...
AndyB Posted June 30, 2007 Share Posted June 30, 2007 You do like tabs, don't you!! That's hard to read in this forum. Actually, the id appears to be a $_GET variable (not a $_POST variable) since it's stuck on the end of your form action URL. It would have made more sense to have it as a hidden input in the form, but then it's your code not mine. Quote Link to comment Share on other sites More sharing options...
JP128 Posted June 30, 2007 Share Posted June 30, 2007 <?php $values[0] = $_POST['name']; $values[1] = $_POST['email']; $values[2] = $_POST['address']; $values[3] = $_POST['state']; $values[4] = $_POST['city']; $values[5] = $_POST['zip']; $values[6] = $_POST['type']; $values[7] = $_POST['footage']; $values[8] = $_POST['approved']; mysql_query("update `houses` set `name`='$values[0]', `email`='$values[1]', `address`='$values[2]', `state`='$values[3]', `city`='$values[4]', `zip`='$values[5]', `type`='$values[6]', `footage`='$values[7]', `enabled`='$values[8]' WHERE `id`='$_POST[id]'") or die(mysql_error()); ?> try that EDIT: Also, you dont ever end your form... </form> Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 30, 2007 Author Share Posted June 30, 2007 Nope, i did a test, Value: afdsa Value: dsfasd@daf.com Value: sdaf Value: 2132 Value: 21312 Value: 9312 Value: dsaf Value: dasf Value: 1 1 If i change the values they come out perfectly but they dont insert into the db. Quote Link to comment Share on other sites More sharing options...
corbin Posted July 1, 2007 Share Posted July 1, 2007 Hmmm so uhhh the row does exist, correct? Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 1, 2007 Author Share Posted July 1, 2007 yeah $_POST['id'] doesn't work but $_REQUEST['id'] did it was the fact that it couldn't fin dthe field for some reason... Thx Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 1, 2007 Share Posted July 1, 2007 Correct format protecting the database. Also you did not use all this in a form mad man/lady lol good luck ok. <?php if($_POST['submit']){ $values[0] = addslashes($_POST['name']); $values[1] = addslashes($_POST['email']); $values[2] = addslashes($_POST['address']); $values[3] = addslashes($_POST['state']); $values[4] = addslashes($_POST['city']); $values[5] = addslashes($_POST['zip']); $values[6] = addslashes($_POST['type']); $values[7] = addslashes($_POST['footage']); $values[8] = addslashes($_POST['approved']); $id=addslashes($_POST['id']); $query="update `houses` set `name`=".$values[0].",`email`=".$values[1].",`address`=".$values[2].", `state`=".$values[3].",`city`=".$values[4].",`zip`=".$values[5].",`type`=".$values[6].", `footage`=".$values[7].",`enabled`=".$values[8]." WHERE `id`='$id'"; $result=mysql_query($query); } ?> Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 1, 2007 Share Posted July 1, 2007 yeah $_POST['id'] doesn't work but $_REQUEST['id'] did it was the fact that it couldn't fin dthe field for some reason... thanks For some reason? Did you even read my reply? Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 1, 2007 Author Share Posted July 1, 2007 o rofl didn't see $_GET thx Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.