Jump to content

[SOLVED] mySQL: Why isnt the data saving back into the database?


andrewgarn

Recommended Posts

The page can be accessed here:

 

http://idire.no-ip.org/info2007/editboat.php

 

I can load the fields from the database, but it does not save the fields back into the database.

 

<?
//Database Information
$dbhost = "*****";
$dbname = "*****";
$dbuser = "*****";
$dbpass = "*****";

//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

//If cmd has not been initialized
if(!isset($cmd))
{
   echo 'Select Mode';
   //display all the news
   $result = mysql_query("select * from boat"); 
   
   //run the while loop that grabs all the news scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //grab the title and the ID of the news
      $hullnumber=$r["hullnumber"];//take out the title
      $certid=$r["certid"];//take out the id
     
 //make the title a link
      echo "<a href='editboat.php?cmd=edit&certid=$certid'>$hullnumber - Edit</a>";
      echo "<br>";
}
}
?>




<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      echo 'Edit Mode';
  $certif = $_GET["certid"];
      $sql = "select * from boat WHERE certid=$certif";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
  
      <form action="editboat.php" method="post">
      <input type=hidden name="certid" value="<?php echo $myrow["certid"] ?>">
   
      Hull Number:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["hullnumber"] ?>" SIZE=10><br>
      Certificate Number:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["certid"] ?>" SIZE=15><br>
      Owner's ID:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["ownerid"] ?>" SIZE=10><br>
      Design:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["design"] ?>" SIZE=45><br>
      Designer:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["designer"] ?>" SIZE=45><br>
      Measurement Date:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["dateofmeasurement"] ?>" SIZE=12><br>
      Rigs:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["rigs"] ?>" SIZE=10><br>
      Length:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["length"] ?>" SIZE=10><br>
      Weight:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["weight"] ?>" SIZE=10><br>
      Draught:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["draught"] ?>" SIZE=10><br>
      Status:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["certstatus"] ?>" SIZE=10><br>
      Registrar:<INPUT TYPE="TEXT" NAME="title" VALUE="<? echo $myrow["registrar"] ?>" SIZE=45><br>
      Measurer:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["measurer"] ?>" SIZE=45><br>
   
      <input type="hidden" name="cmd" value="edit">
   
      <input type="submit" name="submit" value="submit">
   
      </form>
   
   <? } ?>
   
   
   <?
   if ($_POST["$submit"])
   {
      echo 'Submit Mode';
  $hullnumber = $_POST["hullnumber"];
      $certid = $_POST["certid"];
      $ownerid = $_POST["ownerid"];
  $design = $_POST["design"];
  $designer = $_POST["designer"];
  $dateofmeasurement = $_POST["dateofmeasurement"];
  $rigs = $_POST["rigs"];
  $length = $_POST["length"];
  $weight = $_POST["weight"];
  $draught = $_POST["draught"];
  $certstatus = $_POST["certstatus"];
  $registrar = $_POST["registrar"];
  $measurer = $_POST["measurer"];
  	  

      $sql = "UPDATE boat SET hullnumber='$hullnumber',certid='$certid',ownerid='$ownerid', design='$designer', designer='$designer', dateofmeasurement='$dateofmeasurement', rigs='$rigs', length='$length', weight='$weight', draught='$draught', certstatus='$certstatus', registrar='$registrar', measurer='$measurer' WHERE certid=$certid";

//insert into boat (hullnumber, certid, ownerid, design, designer, dateofmeasurement, rigs, length, weight, draught, certstatus, registrar, measurer) values ('2', '2', '1', 'motor', 'Daivdson', '2008-01-12', '2', '25', '15', '40', 'Yes', 'ag605', 'tw106')

      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
   }
}

echo "<a href='editboat.php'>Return to Edit Boat</a>";
?>

 

I attempt to correct the spelling of the designer by clicking on the second link, changing the field and clicking submit, but it doesnt work, why?

 

Thanks

EDIT: sorry wasn't looking found it

 

try this

 $sql = "UPDATE boat SET hullnumber = " . $hullnumber . ", certid = " . $certid . ", $ownerid= " . $ownerid . ", design=" . $designer . ", designer= " . $designer .",  dateofmeasurement= " . $dateofmeasurement . ", rigs= " . $rigs . ", length= " . $length .", weight= " . $weight . ", draught= " . $draught .", certstatus= " . $certstatus . ", registrar= " . $registrar . ", measurer= " . $measurer . " WHERE certid= " . $certid .";";

EDIT: sorry wasn't looking found it

 

try this

 $sql = "UPDATE boat SET hullnumber = " . $hullnumber . ", certid = " . $certid . ", $ownerid= " . $ownerid . ", design=" . $designer . ", designer= " . $designer .",  dateofmeasurement= " . $dateofmeasurement . ", rigs= " . $rigs . ", length= " . $length .", weight= " . $weight . ", draught= " . $draught .", certstatus= " . $certstatus . ", registrar= " . $registrar . ", measurer= " . $measurer . " WHERE certid= " . $certid .";";

 

Thanks for replying, I edited it in, but it had no effect.

Thank you, I have made those changes, but I dont think it is getting to the last section of the code, as none of the echo's are displayed

 

<?
//Database Information
$dbhost = "db4free.net";
$dbname = "info2007";
$dbuser = "ag605";
$dbpass = "southampton";

//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

//If cmd has not been initialized
if(!isset($cmd))
{
   echo '<p>Select Mode</p>';
   //display all the boat information
   $result = mysql_query("select * from boat"); 
   
   //run the while loop that grabs all the news scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //hull number and certid.
      $hullnumber=$r["hullnumber"];//take out the hullnumber
      $certid=$r["certid"];//take out the certid
     
 //make the title a link
      echo "<a href='editboat.php?cmd=edit&certid=$certid'>$hullnumber - Edit</a>";
      echo "<br>";
}
}
?>




<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      echo '<p>Edit Mode</p>';
  $certif = $_GET["certid"];
      $sql = "select * from boat WHERE certid=$certif";
      echo $sql;
  $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
  
      <form action="editboat.php" method="post">
      <input type=hidden name="certid" value="<?php echo $myrow["certid"] ?>">
   
      Hull Number:<INPUT TYPE="TEXT" NAME="hullnumber" VALUE="<?php echo $myrow["hullnumber"] ?>" SIZE=10><br>
      Certificate Number:<INPUT TYPE="TEXT" NAME="certid" VALUE="<?php echo $myrow["certid"] ?>" SIZE=15><br>
      Owner's ID:<INPUT TYPE="TEXT" NAME="ownerid" VALUE="<?php echo $myrow["ownerid"] ?>" SIZE=10><br>
      Design:<INPUT TYPE="TEXT" NAME="design" VALUE="<?php echo $myrow["design"] ?>" SIZE=45><br>
      Designer:<INPUT TYPE="TEXT" NAME="designer" VALUE="<?php echo $myrow["designer"] ?>" SIZE=45><br>
      Measurement Date:<INPUT TYPE="TEXT" NAME="dateofmeasurement" VALUE="<?php echo $myrow["dateofmeasurement"] ?>" SIZE=12><br>
      Rigs:<INPUT TYPE="TEXT" NAME="rigs" VALUE="<?php echo $myrow["rigs"] ?>" SIZE=10><br>
      Length:<INPUT TYPE="TEXT" NAME="length" VALUE="<?php echo $myrow["length"] ?>" SIZE=10><br>
      Weight:<INPUT TYPE="TEXT" NAME="weight" VALUE="<?php echo $myrow["weight"] ?>" SIZE=10><br>
      Draught:<INPUT TYPE="TEXT" NAME="draught" VALUE="<?php echo $myrow["draught"] ?>" SIZE=10><br>
      Status:<INPUT TYPE="TEXT" NAME="certstatus" VALUE="<?php echo $myrow["certstatus"] ?>" SIZE=10><br>
      Registrar:<INPUT TYPE="TEXT" NAME="registrar" VALUE="<? echo $myrow["registrar"] ?>" SIZE=45><br>
      Measurer:<INPUT TYPE="TEXT" NAME="measurer" VALUE="<?php echo $myrow["measurer"] ?>" SIZE=45><br>
   
      <input type="hidden" name="cmd" value="edit">
   
      <input type="submit" name="submit" value="submit">
   
      </form>
   
   <? } ?>
   
   
   <?
   if ($_POST["$submit"])
   {
      echo '<p>Submit Mode</p>';
  $hullnumber = $_POST["hullnumber"];
      $certid = $_POST["certid"];
      $ownerid = $_POST["ownerid"];
  $design = $_POST["design"];
  $designer = $_POST["designer"];
  $dateofmeasurement = $_POST["dateofmeasurement"];
  $rigs = $_POST["rigs"];
  $length = $_POST["length"];
  $weight = $_POST["weight"];
  $draught = $_POST["draught"];
  $certstatus = $_POST["certstatus"];
  $registrar = $_POST["registrar"];
  $measurer = $_POST["measurer"];
  	  
  $sql = "UPDATE boat SET hullnumber = " . $hullnumber . ", certid = " . $certid . ", $ownerid= " . $ownerid . ", design=" . $designer . ", designer= " . $designer .",  dateofmeasurement= " . $dateofmeasurement . ", rigs= " . $rigs . ", length= " . $length .", weight= " . $weight . ", draught= " . $draught .", certstatus= " . $certstatus . ", registrar= " . $registrar . ", measurer= " . $measurer . " WHERE certid= " . $certid .";";
  echo $sql;

      //$sql = "UPDATE boat SET hullnumber='$hullnumber',certid='$certid',ownerid='$ownerid', design='$designer', designer='$designer', dateofmeasurement='$dateofmeasurement', rigs='$rigs', length='$length', weight='$weight', draught='$draught', certstatus='$certstatus', registrar='$registrar', measurer='$measurer' WHERE certid=$certid";

//insert into boat (hullnumber, certid, ownerid, design, designer, dateofmeasurement, rigs, length, weight, draught, certstatus, registrar, measurer) values ('2', '2', '1', 'motor', 'Daivdson', '2008-01-12', '2', '25', '15', '40', 'Yes', 'ag605', 'tw106')

      $result = mysql_query($sql) or die(mysql_error());
      echo "Thank you! Information updated.";
   }
}

echo "<p><a href='editboat.php'>Return to Edit Boat</a></p>";
?>

I also noticed another error.

 

Change this;

if ($_POST["$submit"])
{

 

To;

if ($_POST["submit"])
{

 

--

DJ

 

Thank you! That fixed it, as the if condition was never been satisfied, the section of code was never being run. Appreciate the help :)

 

I don't know why i'm not being given the option to modify, but can someone remove the link from the first post please

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.