Jump to content

Edit records within a table


joshgarrod

Recommended Posts

Hi all, I am having difficulty getting my UPDATE script to work. Basically the info is being pulled from a form and then being UPDATED, but it doesn't actually update and I am presented with no errors. It finds the record correctly and displays in the fields in the form as it should, just no update!  Any ideas? Thanks in advance...

 

 <?php
error_reporting (E_ALL ^ E_NOTICE);
$usr = "fdgdg";
    $pwd = "dgdg";
    $db = "dgdg";
    $host = "dgdg.ddg.dg.50dgdg

/***********************Get Record***********************/
$ref = (!empty($_GET['ref']))?trim($_GET['ref']):"";

# connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid){
echo("ERROR: " . mysql_error() . "\n");
}
$db_selected = mysql_select_db(database, $cid);

$query = sprintf("SELECT * FROM fleet where fleetref like '%s' LIMIT 1","%".mysql_real_escape_string($ref)."%");
$result = mysql_query($query) or die($query."<br>".mysql_error());  
$record = mysql_fetch_assoc($result);
if(mysql_num_rows($result) > 0)
{
echo "<strong>Updating fleet vehicle</strong>";
$fleetref=$record["ref"];
$fleetmake=$record["fleetmake"];
$fleetmodel=$record["fleetmodel"];
$fleetberth=$record["fleetberth"];
$fleetyear=$record["fleetyear"];
$fleetlength=$record["fleetlength"];
$fleetchassis=$record["fleetchassis"];
$fleetengine=$record["fleetengine"];
$fleetlayout=$record["fleetlayout"];
$fleettype=$record["fleettype"];
$fleetcomments=$record["fleetcomments"];
$pricelow=$record["pricelow"];
$pricemid=$record["pricemid"];
$pricehigh=$record["pricehigh"];
$fleetof=$record["fleetof"];

}else{
echo "<div id=\"pages\"><strong>Record not found</strong> - Edit Directory</div>";
$fleetmake="";
$fleetmodel="";
$fleetberth="";
$fleetyear="";
$fleetlength="";
$fleetchassis="";
$fleetengine="";
$fleetlayout="";
$fleettype="";
$fleetcomments="";
$pricelow="";
$pricemid="";
$pricehigh="";
$fleetof=$record["fleetof"];
}

if ($fleetof == $account) {
/***********************Save Record***********************/
# this is processed when the form is submitted
# back on to this page (POST METHOD)
if (isset($_POST['submit'])){
$fleetmake=$_POST["fleetmake"];
$fleetmodel=$_POST["fleetmodel"];
$fleetberth=$_POST["fleetberth"];
$fleetyear=$_POST["fleetyear"];
$fleetchassis=$_POST["fleetchassis"];
$fleetengine=$_POST["fleetengine"];
$fleetlayout=$_POST["fleetlayout"];
$fleetlength=$_POST["fleetlength"];
$fleettype=$_POST["fleettype"];
$fleetcomments=$_POST["fleetcomments"];
$pricelow=$_POST["pricelow"];
$pricemid=$_POST["pricemid"];
$pricehigh=$_POST["pricehigh"];

# setup SQL statement
$query = sprintf("UPDATE `fleet` SET `fleetmake` = '%s',`fleetmodel` = '%s',`fleetberth` = '%s',`fleetyear` = '%s',`fleetchassis` = '%s',`fleetengine` = '%s',`fleetlayout` = '%s',`fleetlength` = '%s',`fleettype` = '%s',`fleetcomments` = '%s',`pricelow` = '%s',`pricemid` = '%s',`pricehigh` = '%s' WHERE `fleetref` ='%s' LIMIT 1",	mysql_real_escape_string($fleetmake),mysql_real_escape_string($fleetmodel),mysql_real_escape_string($fleetberth),mysql_real_escape_string($fleetyear),mysql_real_escape_string($fleetchassis),mysql_real_escape_string($fleetengine),mysql_real_escape_string($fleetlayout),mysql_real_escape_string($fleetlength),mysql_real_escape_string($fleettype),mysql_real_escape_string($fleetcomments),mysql_real_escape_string($pricelow),mysql_real_escape_string($pricemid),mysql_real_escape_string($pricehigh),mysql_real_escape_string($fleetref));

#execute SQL statement
$result = mysql_db_query($db,$query,$cid) or die($query."<br>".mysql_error());

# check for error
if (!$result){
	echo("ERROR: " . mysql_error() . "\n$SQL\n");
}
echo "<P>Fleet vehicle updated</P>\n";
} }
else
{echo "Sorry, you are not authorised to edit this vehicle, please contact the system administrator for further help.";}
   
?>

Link to comment
https://forums.phpfreaks.com/topic/218361-edit-records-within-a-table/
Share on other sites

HTML Form

 

<FORM NAME="fa" ACTION="fleet_edit.php" METHOD="POST" enctype="multipart/form-data">
     <div class="input_row"><div class="input_titles">Make:</div>
       <div class="input_box">
         <INPUT NAME="fleetmake" TYPE="text" id="fleetmake" VALUE="<?php echo $fleetmake; ?>" SIZE=15> 
         e.g. Swift </div>
     </div>
   <div class="input_row"><div class="input_titles">Model:</div><div class="input_box"><INPUT NAME="fleetmodel" TYPE="text" id="fleetmodel" VALUE="<?php echo $fleetmodel; ?>" SIZE=15> 
   e.g. Kon-Tiki 669 </div>
   </div>
   <div class="input_row"><div class="input_titles">Year:</div><div class="input_box"><input name="fleetyear" type="text" id="fleetyear" value="<?php echo $fleetyear; ?>" size="4" /> 
   What year was the vehicle manufactured?</div>
   </div>
<div class="input_row"><div class="input_titles">Berth:</div><div class="input_box"><select name="fleetberth" id="fleetberth">
<option selected="selected"><?php echo $fleetberth; ?><option>
       <option>2</option>
       <option>3</option>
       <option>4</option>
       <option>5</option>
       <option>6</option>
       <option>7</option>
     </select>
What is the maximum sleeping capacity of the vehicle? 
</div>
</div>
   <div class="input_row">
     <div class="input_titles">Shipping length </div>
     <div class="input_box"><input name="fleetlength" type="text" id="fleetlength" value="<?php echo $fleetlength; ?>" size="6" /> 
     Please provide measurement in METERS </div>
   </div>
   <div class="input_row">
     <div class="input_titles">Chassis</div>
     <div class="input_box"><input name="fleetchassis" type="text" id="fleetchassis" value="<?php echo $fleetchassis; ?>" size="15" /> 
       e.g. Fiat 
     </div>
   </div>
   <div class="input_row">
     <div class="input_titles">Engine size </div>
     <div class="input_box"><input name="fleetengine" type="text" id="fleetengine" value="<?php echo $fleetengine; ?>" size="15" /> 
       e.g. 3.0TD </div>
   </div>
   <div class="input_row"><div class="input_titles">Layout:</div><div class="input_box"><select name="fleetlayout" id="fleetlayout">
   <option selected="selected"><?php echo $fleetlayout; ?><option>
       <option>Fixed bed</option>
       <option>Fixed bunk beds</option>
       <option>End lounge</option>
       <option>End washroom</option>
       <option>End kitchen</option>
     </select>
What is the sleeping capacity of the vehicle? 
</div>
</div>
<div class="input_row">
  <div class="input_titles">Vehicle type :</div>
  <div class="input_box"><select name="fleettype" id="fleettype">
  <option selected="selected"><?php echo $fleettype; ?><option>
       <option>Coachbuilt low line</option>
       <option>Coachbuilt high line</option>
       <option>Van conversion</option>
       <option>A Class</option>
       <option>Camper van</option>
       <option>American RV</option>
     </select>
What is the vehicle type?</div>
</div>
   <div class="input_row"><div class="input_titles">Description:<br /><br />
   (Use this space to add anything you wish to say about the vehicle)</div>
     <div class="input_box"><textarea name="fleetcomments" cols="50" rows="10" id="fleetcomments" type="text" value="" /><?php echo $fleetcomments; ?></textarea></div></div>
   <div class="input_row">
     <div class="input_titles">Price low season:</div>
     <div class="input_box"><input name="pricelow" type="text" id="pricelow" value="<?php echo $pricelow; ?>" size="10" />
      Provide price per week </div>
   </div>
   <div class="input_row">
     <div class="input_titles">Price mid season:</div>
     <div class="input_box"><input name="pricemid" type="text" id="pricemid" value="<?php echo $pricemid; ?>" size="10" />
      Provide price per week </div>
   </div>
   <div class="input_row">
     <div class="input_titles">Price high season:</div>
     <div class="input_box"><input name="pricehigh" type="text" id="pricehigh" value="<?php echo $pricehigh; ?>" size="10" />
Provide price per week </div>
   </div>

   <div class="input_row">Please note: upon cilcking "edit fleet vehicle" any changes you have made above will be made to your live listing for this particular vehicle. <br />
     <br />
   </div>
   <div class="input_row"><div class="input_titles"><input name="submit" type="submit" value="Edit fleet vehicle" />
   </div></div>
   </FORM>

echo $query =

 

UPDATE `fleet` SET `fleetmake` = 'Compass2',`fleetmodel` = 'Drifter 3502',`fleetberth` = '5',`fleetyear` = '19972',`fleetchassis` = 'Peugeot2',`fleetengine` = '2.0TD2',`fleetlayout` = 'End washroom',`fleetlength` = '6.592',`fleettype` = 'A Class',`fleetcomments` = 'comments about vehicle,`pricelow` = '£4952',`pricemid` = '£5952',`pricehigh` = '£6952' WHERE `fleetref` ='' LIMIT 1

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.