Link to home
Start Free TrialLog in
Avatar of ecosvaldo
ecosvaldo

asked on

Script for Admin section of a Site Not Working - NEED HELP!!!

I'm having a problem with a PHP script for the admin section of a site I'm working on. The following script is below:


<html>
<body>

<?php

$db = mysql_connect("localhost", "i24-7hom_admin", "hotline");
mysql_select_db("i24-7hom_home",$db);

if ($submit) {
  // here if no ID then adding else we're editing
  if ($housecode) {
      $sql = "UPDATE home SET address='$address',city='$city',state='$state',zip='$zipcode',price='$price',beds='$bed',bath='$bath',garage='$garage',rooms='$room',lotrange='$lot',built='$yearbuilt',levels='$levels',fireplace='$fireplace',centralair='$centralair',zoned='$zoned',gas='$gas',forcedair='$forcedair',schooldistrict='$schooldistrict',elementaryschool='$elementary',middleschool='$middle',highschool='$high',county='$county',exterior='$exterior',propertytype='$property',style='$style',parking='$parking',contactphone='$phone',contactemail='$email',description='$description' WHERE housecode=$housecode";
  } else {
    $sql = "INSERT INTO home (housecode,address,city,state,zip,price,beds,bath,garage,rooms,lotrange,built,levels,fireplace,centralair,zoned,gas,forcedair,schooldistrict,elementaryschool,middleschool,highschool,county,exterior,propertytype,style,parking,contactphone,contactemail,description) VALUES ('$housecode','$address','$city','$state','$zipcode','$price','$bed','$bath','$garage','$room','$lot','$yearbuilt','$levels','$fireplace','$centralair','$zoned','$gas','$forcedair','$schooldistrict','$elementary','$middle','$high','$county','$exterior','$property','$style','$parking','$phone','$email','$description')";
  }
  // run SQL against the DB
  $result = mysql_query($sql);
  echo "Record updated/edited!<p>";
} elseif ($delete) {
      // delete a record
    $sql = "DELETE FROM home WHERE housecode=$housecode";      
    $result = mysql_query($sql);
    echo "$sql Record deleted!<p>";
} else {
  // this part happens if we don't press submit
  if (!$housecode) {
    // print the list if there is not editing
    $result = mysql_query("SELECT * FROM home",$db);
    while ($myrow = mysql_fetch_array($result)) {
            printf("<a href=\"%s?housecode=%s\">%s, %s, %s %s</a> \n", $PHP_SELF, $myrow["housecode"], $myrow["address"], $myrow["city"], $myrow["state"] $myrow["zip"]);
            printf("<a href=\"%s?housecode=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["housecode"]);
    }
  }
  ?>
  <P>
  <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
  <P>
  <form method="post" action="<?php echo $PHP_SELF?>">
  <?php
  if ($housecode) {
    // editing so select a record
    $sql = "SELECT * FROM home WHERE housecode=$housecode";;
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);
    $housecode = $myrow["housecode"];
    $address = $myrow["address"];
    $city = $myrow["city"];
    $state = $myrow["state"];
    $zipcode = $myrow["zip"];
    // print the id for editing
    ?>
    <input type=hidden name="housecode" value="<?php echo $housecode ?>">
    <?php
  }
  ?>
House Code: <input type="Text" name="housecode" value="<?php echo $housecode ?>"><br>
Address: <input type="Text" name="address" value="<?php echo $address ?>"><br>
City: <input type="Text" name="city" value="<?php echo $city ?>"><br>
State: <input type="Text" name="state" value="<?php echo $state ?>"><br>
Zip Code: <input type="Text" name="zipcode" value="<?php echo $zip ?>"><br>
Price: <input type="Text" name="price" value="<?php echo $price ?>"><br><br />
No. of Beds: <input type="Text" name="bed" value="<?php echo $beds ?>"><br>
No. of Bath: <input type="Text" name="bath" value="<?php echo $bath ?>"><br>
No. of Garages: <input type="Text" name="garage" value="<?php echo $garage ?>"><br>
No. of Rooms: <input type="Text" name="room" value="<?php echo $rooms ?>"><br>
Range of Lot: <input type="Text" name="lot" value="<?php echo $lotrange ?>"><br>
Year House was Built: <input type="Text" name="yearbuilt" value="<?php echo $built ?>"><br><br />
No. of Levels: <input type="Text" name="levels" value="<?php echo $levels ?>"><br>
No. of Fireplaces: <input type="Text" name="fireplace" value="<?php echo $fireplace ?>"><br><br />
Central Air <input type="checkbox" name="centralair" value="<?php echo $centralair ?>" />&nbsp; &nbsp; Zoned <input type="checkbox" name="zoned" value="<?php echo $zoned ?>" />&nbsp; &nbsp; Gas <input type="checkbox" name="gas" value="<?php echo $gas ?>" />&nbsp; &nbsp; Forced Air <input type="checkbox" name="forcedair" value="<?php echo $forcedair ?>" /><br /><br />
School District: <input type="Text" name="schooldistrict" value="<?php echo $schooldistrict ?>"><br />
Elementary School: <input type="Text" name="elementary" value="<?php echo $elementaryschool ?>"><br />
Middle School: <input type="Text" name="middle" value="<?php echo $middleschool ?>"><br />
High School: <input type="Text" name="high" value="<?php echo $highschool ?>"><br />
County: <input type="Text" name="county" value="<?php echo $county ?>"><br />
Exterior: <input type="Text" name="exterior" value="<?php echo $exterior ?>"><br />
Property Type: <input type="Text" name="property" value="<?php echo $propertytype ?>"><br />
Style: <input type="Text" name="style" value="<?php echo $style ?>"><br />
Parking: <input type="Text" name="parking" value="<?php echo $parking ?>"><br /><br />
Contact Information - Phone: <input type="Text" name="phone" value="<?php echo $contactphone ?>"><br />
Contact Information - Email: <input type="Text" name="email" value="<?php echo $contactemail ?>"><br /><br />
Description: <textarea name="description" cols="60" rows="12" wrap="hard"><?php echo $description ?></textarea>
<br /><br /><br />
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>

</body>
</html>


I tried running the page but I keep getting this error:

Parse error: parse error, unexpected T_VARIABLE in /home/i24-7hom/public_html/admin/index.php on line 30



Can anyone help me?
Avatar of nsanden
nsanden

I think you just need to add a comma on line 30

Change:
printf("<a href=\"%s?housecode=%s\">%s, %s, %s %s</a> \n", $PHP_SELF, $myrow["housecode"], $myrow["address"], $myrow["city"], $myrow["state"] $myrow["zip"]);

To:
printf("<a href=\"%s?housecode=%s\">%s, %s, %s %s</a> \n", $PHP_SELF, $myrow["housecode"], $myrow["address"], $myrow["city"], $myrow["state"], $myrow["zip"]);
ASKER CERTIFIED SOLUTION
Avatar of nsanden
nsanden

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial