Solved

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

Posted on 2006-11-07
4
193 Views
Last Modified: 2006-12-06
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?
0
Comment
Question by:ecosvaldo
  • 2
4 Comments
 
LVL 2

Expert Comment

by:nsanden
Comment Utility
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"]);
0
 
LVL 2

Accepted Solution

by:
nsanden earned 125 total points
Comment Utility
By the way, you may want to change your mysql username and password now, since the code you posted has that in it. Technically if your mysql user account is setup to only allow localhost connections, your safe not changing it, but I would probably change it regardless.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now