Jump to content

[SOLVED] HTML Values not loading and script doesn't save to mysql database


agallo

Recommended Posts

I am having some trouble debugging this mysql edit script I am trying to use.

 

The variables are posting after selecting the submit button (using the cmd function) and returning the new varaibles but are not updating my database. I have double and triple checked to make sure all the variables are correct in the "update property set" function.

 

The second problem I am having is that the textfield boxes are supposed to load the values from the row selected to edit, in which they are not.

 

If someone can please look over my code I would greatly appreciate it! As I have spent many hours trying to debug these issues.

 

Thanks for any and all help!

 



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<address_name>Below are the following listings you may edit: </br></address_name>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>


<? 


include_once ("../auth.php");
include_once ("../authconfig.php");
include_once ("../check.php");

$username = $check["uname"];


//If cmd has not been initialized
if(!isset($cmd)) 
{
   //display all the property
   $result = mysql_query("select * from property where username='$username' order by address_no"); 
   
   //run the while loop that grabs all the property scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //grab the address_name and the address_no of the property
     
$address_no=$_POST['address_no'];
$address_name=$_POST['address_name'];
$address_suite=$_POST['address_suite']; 
$sq_ft=$_POST['sq_ft']; 
$rent_price=$_POST['rent_price']; 
$bedroom=$_POST['bedroom']; 
$bath=$_POST['bath']; 
$living_room=$_POST['living_room']; 
$dining_room=$_POST['dining_room']; 
$furnished=$_POST['furnished']; 
$pets=$_POST['pets']; 
$pet_deposit=$_POST['pet_deposit']; 
$lease_term=$_POST['lease_term']; 
$security_deposit=$_POST['security_deposit']; 
$key_access=$_POST['key_access']; 
$resident_phone=$_POST['resident_phone']; 
$date_available=$_POST['date_available']; 
$ac=$_POST['ac']; 
$heat=$_POST['heat']; 
$laundry=$_POST['laundry']; 
$fireplace=$_POST['fireplace']; 
$alarm=$_POST['alarm']; 
$ceiling_fan=$_POST['ceiling_fan']; 
$refrigerator=$_POST['refrigerator']; 
$stove=$_POST['stove']; 
$dishwasher=$_POST['dishwasher'];
$microwave=$_POST['microwave']; 
$parking=$_POST['parking'];
$fenced=$_POST['fenced']; 
$pool=$_POST['pool'];
$spa=$_POST['spa']; 
$bills_paid=$_POST['bills_paid'];
$school_district=$_POST['school_district']; 
$school_elem=$_POST['school_elem'];
$school_midd=$_POST['school_midd'];
$school_high=$_POST['school_high'];
$company_name=$_POST['company_name'];
$company_phone=$_POST['company_phone'];
$agent_fname=$_POST['agent_fname'];
$agent_lname=$_POST['agent_lname'];
$agent_phone=$_POST['agent_phone'];
$commission=$_POST['commission'];
$bonus=$_POST['bonus'];
$remarks=$_POST['remarks'];


 //make the address_name a link
      echo "<a href='edit.php?cmd=edit&address_no=$address_no'>$address_no $address_name $address_suite </a>";
      echo "<br>";
    }
}

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $address_no = $_GET["address_no"];
      $sql = "SELECT * FROM property WHERE address_no=$address_no";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
  
      <form action="edit.php" method="post">
      Address # : <input type=haddress_noden name="address_no" value="<?php echo $myrow["address_no"] ?>">
      Address Suite : <INPUT TYPE="TEXT" NAME="address_suite" VALUE="<?php echo $myrow["address_name"] ?>" ><br>
  Address Name : <INPUT TYPE="TEXT" NAME="address_name" VALUE="<?php echo $myrow["address_suite"] ?>" ><br>
  Sq ft : <INPUT TYPE="TEXT" NAME="sq_ft" VALUE="<?php echo $myrow["sq_ft"] ?>" ><br>
  Rent Price : <INPUT TYPE="TEXT" NAME="rent_price" VALUE="<?php echo $myrow["rent_price"] ?>" ><br>
  Bedrooms : <INPUT TYPE="TEXT" NAME="bedroom" VALUE="<?php echo $myrow["bedroom"] ?>" ><br>
  Baths : <INPUT TYPE="TEXT" NAME="bath" VALUE="<?php echo $myrow["bath"] ?>" ><br>
  Living Rooms : <INPUT TYPE="TEXT" NAME="living_room" VALUE="<?php echo $myrow["living_room"] ?>" ><br>
  Dining Rooms : <INPUT TYPE="TEXT" NAME="dining_room" VALUE="<?php echo $myrow["dining_room"] ?>" ><br>
  Furnished : <INPUT TYPE="TEXT" NAME="furnished" VALUE="<?php echo $myrow["furnished"] ?>" ><br>
  Pets : <INPUT TYPE="TEXT" NAME="pets" VALUE="<?php echo $myrow["pets"] ?>" ><br>
  Pet Deposit : <INPUT TYPE="TEXT" NAME="pet_deposit" VALUE="<?php echo $myrow["pet_deposit"] ?>" ><br>
  Lease Term : <INPUT TYPE="TEXT" NAME="lease_term" VALUE="<?php echo $myrow["lease_term"] ?>" ><br>
  Security Deposit : <INPUT TYPE="TEXT" NAME="security_deposit" VALUE="<?php echo $myrow["security_deposit"] ?>" ><br>
  Key Access : <INPUT TYPE="TEXT" NAME="key_access" VALUE="<?php echo $myrow["key_access"] ?>" ><br>
  Resident Phone : <INPUT TYPE="TEXT" NAME="resident_phone" VALUE="<?php echo $myrow["resident_phone"] ?>" ><br>
  Date Available : <INPUT TYPE="TEXT" NAME="date_available" VALUE="<?php echo $myrow["date_available"] ?>" ><br>
  A/C : <INPUT TYPE="TEXT" NAME="ac" VALUE="<?php echo $myrow["ac"] ?>" ><br>
  Heat : <INPUT TYPE="TEXT" NAME="heat" VALUE="<?php echo $myrow["heat"] ?>" ><br>
  Laundry : <INPUT TYPE="TEXT" NAME="laundry" VALUE="<?php echo $myrow["laundry"] ?>" ><br>
  Fireplace : <INPUT TYPE="TEXT" NAME="fireplace" VALUE="<?php echo $myrow["fireplace"] ?>" ><br>
  Alarm : <INPUT TYPE="TEXT" NAME="alarm" VALUE="<?php echo $myrow["alarm"] ?>" ><br>
  Ceiling Fan : <INPUT TYPE="TEXT" NAME="ceiling_fan" VALUE="<?php echo $myrow["ceiling_fan"] ?>" ><br>
  Refrigerator : <INPUT TYPE="TEXT" NAME="refrigerator" VALUE="<?php echo $myrow["refrigerator"] ?>" ><br>
  Stove : <INPUT TYPE="TEXT" NAME="stove" VALUE="<?php echo $myrow["stove"] ?>" ><br>
  Dishwasher : <INPUT TYPE="TEXT" NAME="dishwasher" VALUE="<?php echo $myrow["dishwasher"] ?>" ><br>
  Mircowave : <INPUT TYPE="TEXT" NAME="microwave" VALUE="<?php echo $myrow["microwave"] ?>" ><br>
  Parking : <INPUT TYPE="TEXT" NAME="parking" VALUE="<?php echo $myrow["parking"] ?>" ><br>
  Fenced : <INPUT TYPE="TEXT" NAME="fenced" VALUE="<?php echo $myrow["fenced"] ?>" ><br>
  Pool : <INPUT TYPE="TEXT" NAME="pool" VALUE="<?php echo $myrow["pool"] ?>" ><br>
  Spa : <INPUT TYPE="TEXT" NAME="spa" VALUE="<?php echo $myrow["spa"] ?>" ><br>
  Bills Paid : <INPUT TYPE="TEXT" NAME="bills_paid" VALUE="<?php echo $myrow["bills_paid"] ?>" ><br>
  School District : <INPUT TYPE="TEXT" NAME="school_district" VALUE="<?php echo $myrow["school_district"] ?>" ><br>
  Elem School : <INPUT TYPE="TEXT" NAME="school_elem" VALUE="<?php echo $myrow["school_elem"] ?>" ><br>
  Midd School : <INPUT TYPE="TEXT" NAME="school_midd" VALUE="<?php echo $myrow["school_midd"] ?>" ><br>
  High School : <INPUT TYPE="TEXT" NAME="school_high" VALUE="<?php echo $myrow["school_high"] ?>" ><br>
  Company Name : <INPUT TYPE="TEXT" NAME="company_name" VALUE="<?php echo $myrow["company_name"] ?>" ><br>
  Company Phone : <INPUT TYPE="TEXT" NAME="company_phone" VALUE="<?php echo $myrow["company_phone"] ?>" ><br>
  Agent First Name : <INPUT TYPE="TEXT" NAME="agent_fname" VALUE="<?php echo $myrow["agent_fname"] ?>" ><br>
  Agent Last Name : <INPUT TYPE="TEXT" NAME="agent_lname" VALUE="<?php echo $myrow["agent_lname"] ?>" ><br>
  Agent Phone : <INPUT TYPE="TEXT" NAME="agent_phone" VALUE="<?php echo $myrow["agent_phone"] ?>" ><br>
  Commission : <INPUT TYPE="TEXT" NAME="commission" VALUE="<?php echo $myrow["commission"] ?>" ><br>
  Bonus : <INPUT TYPE="TEXT" NAME="bonus" VALUE="<?php echo $myrow["bonus"] ?>" ><br>
  Remarks:<TEXTAREA NAME="message" ROWS=10 COLS=30><? echo $myrow["remarks"] ?></TEXTAREA><br>
      
   
       <input type="haddress_noden" name="cmd" value="edit">
   
      <input type="submit" name="submit" value="submit">
   
      </form>
   
<? } ?>
<?
   if ($_POST["$submit"])
   {
$address_no=$_POST['address_no'];
$address_name=$_POST['address_name'];
$address_suite=$_POST['address_suite']; 
$sq_ft=$_POST['sq_ft']; 
$rent_price=$_POST['rent_price']; 
$bedroom=$_POST['bedroom']; 
$bath=$_POST['bath']; 
$living_room=$_POST['living_room']; 
$dining_room=$_POST['dining_room']; 
$furnished=$_POST['furnished']; 
$pets=$_POST['pets']; 
$pet_deposit=$_POST['pet_deposit']; 
$lease_term=$_POST['lease_term']; 
$security_deposit=$_POST['security_deposit']; 
$key_access=$_POST['key_access']; 
$resident_phone=$_POST['resident_phone']; 
$date_available=$_POST['date_available']; 
$ac=$_POST['ac']; 
$heat=$_POST['heat']; 
$laundry=$_POST['laundry']; 
$fireplace=$_POST['fireplace']; 
$alarm=$_POST['alarm']; 
$ceiling_fan=$_POST['ceiling_fan']; 
$refrigerator=$_POST['refrigerator']; 
$stove=$_POST['stove']; 
$dishwasher=$_POST['dishwasher'];
$microwave=$_POST['microwave']; 
$parking=$_POST['parking'];
$fenced=$_POST['fenced']; 
$pool=$_POST['pool'];
$spa=$_POST['spa']; 
$bills_paid=$_POST['bills_paid'];
$school_district=$_POST['school_district']; 
$school_elem=$_POST['school_elem'];
$school_midd=$_POST['school_midd'];
$school_high=$_POST['school_high'];
$company_name=$_POST['company_name'];
$company_phone=$_POST['company_phone'];
$agent_fname=$_POST['agent_fname'];
$agent_lname=$_POST['agent_lname'];
$agent_phone=$_POST['agent_phone'];
$commission=$_POST['commission'];
$bonus=$_POST['bonus'];
$remarks=$_POST['remarks'];


  
  $sql = "UPDATE property SET address_no='$address_no',address_name='$address_name',sq_ft='$sq_ft',rent_price='$rent_price',bedroom='$bedroom',bath='$bath',living_room='$living_room',dining_room='$dining_room',furnished='$furnished',pets='$pets',pet_deposit='$pet_deposit',lease_term='$lease_term',security_deposit='$security_deposit',key_access='$key_access',resident_phone='$resident_phone',date_available='$date_available',ac='$ac',heat='$heat', laundry='$laundry', fireplace='$fireplace',alarm='$alarm',ceiling_fan='$ceiling_fan',refrigerator='$refrigerator',stove='$stove',dishwasher='$dishwasher',microwave='$microwave',parking='$parking',fenced='$fenced',pool='$pool',spa='$spa',bills_paid='$bills_paid',school_district='$school_district',school_elem='$school_elem',school_midd='$school_midd',school_high='$school_high',company_name='$company_name',company_phone='$company_phone',agent_fname='$agent_fname',agent_lname='$agent_lname',agent_phone='$agent_phone',commission='$commission',bonus='$bonus',remarks='$remarks', WHERE address_no=$address_no";
      //replace property with your table name above
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
}
}
?>



</body>
</html>



Link to comment
Share on other sites

first of all im gonna assume theres an active mysqli_connect() in 1 of the includes, so that the querys work...

and with all that chaos of $_POST's and $_GET's im suprised u dont get all confused. i would just change everything to $_REQUEST to avoid mistakes.

other than that, i think u need to drop the last comma in the UPDATE query (the one just before WHERE):

$sql = "UPDATE property SET address_no='$address_no',...remarks='$remarks', WHERE address_no=$address_no";

 

Link to comment
Share on other sites

I changed all the post to request but that didn't help in loading my html form values  :(

 

I also took out the comma at then end of my sql statement.. something I looked over many times. Thanks for the comment!

 

Thanks again

 

Note* The values of the changes are being held somewhere in memory but not my db. If i go back to the edit.php after a change to address_no, address_name, and address_suite I am viewing the correct (updated) address_no, address_name, and address_suite.

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.