Solved

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

Posted on 2006-11-07
4
195 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
ID: 17895492
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
ID: 17895508
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

777 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