Jump to content

[SOLVED] Anything wrong with this code?


beaux1

Recommended Posts

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";
  }
}
?>

Link to comment
Share on other sites

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 ()

Link to comment
Share on other sites

<?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.

 

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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.)

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.