beaux1 Posted February 17, 2007 Share Posted February 17, 2007 This is for the edit script, I suspect it's this code but I could be wrong, if this code's ok then I'll post the rest of the code. Problem: Says it updated SQL info, but really didn't. It lies! <?php if (isset($_POST['submit'])) { // list of rows $number = $_POST["number"]; $first = $_POST["first"]; $last = $_POST["last"]; $year = $_POST["year"]; $section = $_POST["section"]; $district = $_POST["district"]; $region = $_POST["region"]; $leathersuit = $_POST["leathersuit"]; $helmet = $_POST["helmet"]; $rainsuit = $_POST["rainsuit"]; $polotop = $_POST["polotop"]; $poloneck = $_POST["poloneck"]; $gloves = $_POST["gloves"]; $boots = $_POST["boots"]; $underwear = $_POST["underwear"]; $eyewear = $_POST["eyewear"]; $earplugs = $_POST["earplugs"]; $belt = $_POST["belt"]; $pinlock = $_POST["pinlock"]; $id = $_POST["id"]; // updates database with the information... $query = "UPDATE `information` SET `number`='$number',`first`='$first',`last`='$last',`year`='$year',`section`='$section',`district`='$district',`region`='$region',`leathersuit`='$leathersuit',`helmet`='$helmet',`rainsuit`='$rainsuit',`polotop`='$polotop',`poloneck`='$poloneck',`gloves`='$gloves',`boots`='$boots',`underwear`='$underwear',`eyewear`='$eyewear',`earplugs`=$earplugs',`belt`='$belt',`pinlock`='$pinlock' WHERE `id`=$id"; if (!$query) { echo "Unable to update the users information"; }else{ echo "The users information was updated"; } } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 All you did was make a string. you need to use something like mysql_query() to run it. Read the tutorial in the beginner section or on http://www.php.net/mysql_query Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 17, 2007 Share Posted February 17, 2007 I glanced at it but from what i can see its this: $query = "UPDATE `information` SET `number`='$number',`first`='$first',`last`='$last',`year`='$year',`section`='$section',`district`='$district',`region`='$region',`leathersuit`='$leathersuit',`helmet`='$helmet',`rainsuit`='$rainsuit',`polotop`='$polotop',`poloneck`='$poloneck',`gloves`='$gloves',`boots`='$boots',`underwear`='$underwear',`eyewear`='$eyewear',`earplugs`=$earplugs',`belt`='$belt',`pinlock`='$pinlock' WHERE `id`=$id"; needs to be this: $query = mysql_query("UPDATE `information` SET `number`='$number',`first`='$first',`last`='$last',`year`='$year',`section`='$section',`district`='$district',`region`='$region',`leathersuit`='$leathersuit',`helmet`='$helmet',`rainsuit`='$rainsuit',`polotop`='$polotop',`poloneck`='$poloneck',`gloves`='$gloves',`boots`='$boots',`underwear`='$underwear',`eyewear`='$eyewear',`earplugs`=$earplugs',`belt`='$belt',`pinlock`='$pinlock' WHERE `id`=$id"); you forgot the mysql_query and the () Quote Link to comment Share on other sites More sharing options...
beaux1 Posted February 17, 2007 Author Share Posted February 17, 2007 <?php include 'config.php'; include 'opendb.php'; if (isset($_POST['submit'])) { // list of rows $number = $_POST["number"]; $first = $_POST["first"]; $last = $_POST["last"]; $year = $_POST["year"]; $section = $_POST["section"]; $district = $_POST["district"]; $region = $_POST["region"]; $leathersuit = $_POST["leathersuit"]; $helmet = $_POST["helmet"]; $rainsuit = $_POST["rainsuit"]; $polotop = $_POST["polotop"]; $poloneck = $_POST["poloneck"]; $gloves = $_POST["gloves"]; $boots = $_POST["boots"]; $underwear = $_POST["underwear"]; $eyewear = $_POST["eyewear"]; $earplugs = $_POST["earplugs"]; $belt = $_POST["belt"]; $pinlock = $_POST["pinlock"]; $id = $_POST["id"]; // updates database with the information... $query = mysql_query("UPDATE `information` SET `number`='$number',`first`='$first',`last`='$last',`year`='$year',`section`='$section',`district`='$district',`region`='$region',`leathersuit`='$leathersuit',`helmet`='$helmet',`rainsuit`='$rainsuit',`polotop`='$polotop',`poloneck`='$poloneck',`gloves`='$gloves',`boots`='$boots',`underwear`='$underwear',`eyewear`='$eyewear',`earplugs`=$earplugs',`belt`='$belt',`pinlock`='$pinlock' WHERE `id`=$id"); if (!$query) { echo "Unable to update the users information"; }else{ echo "The users information was updated"; } } ?> No errors, just Unable to update the users information. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 <?php include 'config.php'; include 'opendb.php'; if (isset($_POST['submit'])) { // list of rows $number = $_POST["number"]; $first = $_POST["first"]; $last = $_POST["last"]; $year = $_POST["year"]; $section = $_POST["section"]; $district = $_POST["district"]; $region = $_POST["region"]; $leathersuit = $_POST["leathersuit"]; $helmet = $_POST["helmet"]; $rainsuit = $_POST["rainsuit"]; $polotop = $_POST["polotop"]; $poloneck = $_POST["poloneck"]; $gloves = $_POST["gloves"]; $boots = $_POST["boots"]; $underwear = $_POST["underwear"]; $eyewear = $_POST["eyewear"]; $earplugs = $_POST["earplugs"]; $belt = $_POST["belt"]; $pinlock = $_POST["pinlock"]; $id = $_POST["id"]; // updates database with the information... $query = "UPDATE `information` SET `number`='$number',`first`='$first',`last`='$last',`year`='$year',`section`='$section',`district`='$district',`region`='$region',`leathersuit`='$leathersuit',`helmet`='$helmet',`rainsuit`='$rainsuit',`polotop`='$polotop',`poloneck`='$poloneck',`gloves`='$gloves',`boots`='$boots',`underwear`='$underwear',`eyewear`='$eyewear',`earplugs`=$earplugs',`belt`='$belt',`pinlock`='$pinlock' WHERE `id`='$id' "; $result=mysql_query($query)or die(mysql_error()); if (!$result) { echo "Unable to update the users information"; }else{ echo "The users information was updated"; } } ?> also use addslashes ok. Quote Link to comment Share on other sites More sharing options...
beaux1 Posted February 17, 2007 Author Share Posted February 17, 2007 Alright, this is my code: The first one works like this: You enter a number which would be in a row, in this case the row is 'numbers', so you enter the number in the form. SQL find the column line. <body> <table width="365" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="ECE9D8" style="border-collapse:collapse"> <tr> <td width="17" valign="top" bgcolor="#5c5e62"><br /></td> <td width="330" height="142" valign="top" bgcolor="#666666"><form id="form1" name="form1" method="post" action="edit.php"> <label> <div align="center"><span class="style12">Insert the ID# and hit submit, which will return a form to edit the players information:</span><br /> <input name="number" type="text" class="text" id="number" value="[ Insert ID# Here ]" /> </div> </label> <br /> <label> <input name="submit" type="submit" class="text" id="Submit" value="Submit" /> </label> </form> </td> </tr> </table> </td> </tr> </table> Now, in this one, SQL has the column line (from the number that was entered) and echos all the information on that column line into text boxes for editing. Hit submit, it goes to another page. <?php include 'config.php'; include 'opendb.php'; $number = $_POST['number']; $id = $_GET['id']; ?> <?php $sql = "SELECT `number`, `first`, `last`, `section`, `district`, `region`, `year`, `leathersuit`, `helmet`, `rainsuit`, `polotop`, `poloneck`, `gloves`, `boots`, `underwear`, `eyewear`, `earplugs`, `belt`, `pinlock`, `id` FROM information WHERE number = '$number'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result) ?> <div align="center"><span class="style12">Results for queried ID# <?php echo $row['number']?>: </span> </div> <form id="form1" name="form1" method="post" action="edit2.php"> <input type=hidden name="id" value="<?php echo $row["id"] ?>"> <input name="number20" type="text" class="text" value="<?php echo $row['number']?>" size="15"/> <br /> <input name="number" type="text" class="text" value="<?php echo $row['first']?>" size="15"/> <br /> <input name="number3" type="text" class="text" value="<?php echo $row['last']?>" size="15"/> <br /> <input name="number4" type="text" class="text" value="<?php echo $row['section']?>" size="15"/> <br /> <input name="number5" type="text" class="text" value="<?php echo $row['district']?>" size="15"/> <br /> <input name="number6" type="text" class="text" value="<?php echo $row['region']?>" size="15"/> <br /> <input name="number7" type="text" class="text" value="<?php echo $row['year']?>" size="15"/> <br /> <input name="number8" type="text" class="text" value="<?php echo $row['leathersuit']?>" size="15"/> <br /> <input name="number9" type="text" class="text" value="<?php echo $row['helmet']?>" size="15"/> <br /> <input name="number10" type="text" class="text" value="<?php echo $row['rainsuit']?>" size="15"/> <br /> <input name="number112" type="text" class="text" value="<?php echo $row['polotop']?>" size="15"/> <br /> <input name="number12" type="text" class="text" value="<?php echo $row['poloneck']?>" size="15"/> <br /> <input name="number13" type="text" class="text" value="<?php echo $row['gloves']?>" size="15"/> <br /> <input name="number14" type="text" class="text" value="<?php echo $row['boots']?>" size="15"/> <br /> <input name="number15" type="text" class="text" value="<?php echo $row['underwear']?>" size="15"/> <br /> <input name="number16" type="text" class="text" value="<?php echo $row['eyewear']?>" size="15"/> <br /> <input name="number17" type="text" class="text" value="<?php echo $row['earplugs']?>" size="15"/> <br /> <input name="number18" type="text" class="text" value="<?php echo $row['belt']?>" size="15"/> <br /> <input name="number19" type="text" class="text" value="<?php echo $row['pinlock']?>" size="15"/><br /> <br /> <label> <input name="submit" type="submit" class="text" value="submit" /> </label> </form> <br /> And finally, the last bit where it just updates the database : <?php include 'config.php'; include 'opendb.php'; if (isset($_POST['submit'])) { // list of rows $id = $_POST["id"]; $number = $_POST["number"]; $first = $_POST["first"]; $last = $_POST["last"]; $year = $_POST["year"]; $section = $_POST["section"]; $district = $_POST["district"]; $region = $_POST["region"]; $leathersuit = $_POST["leathersuit"]; $helmet = $_POST["helmet"]; $rainsuit = $_POST["rainsuit"]; $polotop = $_POST["polotop"]; $poloneck = $_POST["poloneck"]; $gloves = $_POST["gloves"]; $boots = $_POST["boots"]; $underwear = $_POST["underwear"]; $eyewear = $_POST["eyewear"]; $earplugs = $_POST["earplugs"]; $belt = $_POST["belt"]; $pinlock = $_POST["pinlock"]; // updates database with the information... $query = "UPDATE `information` SET `id`='$id', `number`='$number',`first`='$first',`last`='$last',`year`='$year',`section`='$section',`district`='$district',`region`='$region',`leathersuit`='$leathersuit',`helmet`='$helmet',`rainsuit`='$rainsuit',`polotop`='$polotop',`poloneck`='$poloneck',`gloves`='$gloves',`boots`='$boots',`underwear`='$underwear',`eyewear`='$eyewear',`earplugs`=$earplugs',`belt`='$belt',`pinlock`='$pinlock' WHERE `id`='$id' "; $result=mysql_query($query)or die(mysql_error()); if (!$result) { echo "Unable to update the users information"; }else{ echo "The users information was updated"; } } ?> And I get: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '21'' at line 1 (By the way, I know all this can be put into 1 file, I've just split it up to make it easier on myself.) Quote Link to comment Share on other sites More sharing options...
beaux1 Posted February 17, 2007 Author Share Posted February 17, 2007 By the way, 21 is the ID of the number I entered in edit1.php, which was 9999. It just doesn't seem to be updating the database. Any help? Quote Link to comment Share on other sites More sharing options...
beaux1 Posted February 17, 2007 Author Share Posted February 17, 2007 Bump...can anyone help? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 17, 2007 Share Posted February 17, 2007 You'll always get a $result, even if it wasn't updated, unless there was an error. Since you check for an error, you'll either get the die() message or a $result. Add print $query before you run it to make sure it looks the way you want. Quote Link to comment Share on other sites More sharing options...
beaux1 Posted February 17, 2007 Author Share Posted February 17, 2007 Ok, I played around with it, fixed some stuff, I added print $query, and this is my outcome: UPDATE `information` SET `number`='9999',`first`='John',`last`='Murphy',`year`='2007',`section`='Station',`district`='District',`region`='Region',`leathersuit`='1',`helmet`='1',`rainsuit`='1',`polotop`='1',`poloneck`='1',`gloves`='1',`boots`='2',`underwear`='2',`eyewear`='2',`earplugs`=3',`belt`='3',`pinlock`='3' WHERE `id`='21'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '',`belt`='3',`pinlock`='3' WHERE `id`='21'' at line 1 Is there actually anything wrong with my query? Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 `earplugs`=3' has to be `earplugs'=`3' Quote Link to comment Share on other sites More sharing options...
beaux1 Posted February 17, 2007 Author Share Posted February 17, 2007 Hahaha! Ahhh! I was spending hours looking at each letter and digit to make sure everything was right, and I seemed to have passed that! Thanks, solved! Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 ya rofl but it took me like 1 minute you have to always put your query into your MySql Query Browser program it will bold the correct ones and the ones that have a missing quote or some error it won't be bold just pops in your face like that. Quote Link to comment Share on other sites More sharing options...
beaux1 Posted February 17, 2007 Author Share Posted February 17, 2007 Oooh, recommend any? I heard EditPlus was good? Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 never heard of EditPlus but yes Editpad Pro is very good it has that same bold/hightlight feeling for php/C#and java too as i noticed 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.