Jump to content

[SOLVED] Please Check Code


gts

Recommended Posts

Hello,

 

I am extremely new to php. I recently took over as webmaster for a company and I have started running into problems. There website worked perfectly when I started. The owner then decided to switch over to a new hosting company. My problem is that parts of the website pull data from a database. the only thing that has changed within the page is the info for the database to which it connects to. I have listed the code that i am using below. if someone gets a chance can you just tell me if you see anything wrong with it? Thanks in advance.

 

 

 

 

<p><font face="Arial, Helvetica, sans-serif" size="4">Swap Shop<br>

                    <font size="2">Welcome to our Swap Shop online.</font></font></p>

      <p><b><font face="Arial, Helvetica, sans-serif">Viewing: </font></b><font face="Arial, Helvetica, sans-serif"><?php echo $c; ?></font></p>

  <font face="Arial, Helvetica, sans-serif" size="2">

<?php

 

if($c != "All Items") {

$result = mysql_query("SELECT name,phone,action,title,description,town,itemID FROM swapshop WHERE category = '$c' AND to_days(now()) - to_days(date) <= 5 AND checked = 'Yes' ORDER BY date DESC",$db);

}

else {

$result = mysql_query("SELECT name,phone,action,title,description,town,itemID FROM swapshop WHERE to_days(now()) - to_days(date) <= 5 AND checked = 'Yes' ORDER BY date DESC",$db);

}

 

while ($myrow = mysql_fetch_row($result)) {

if($myrow[0] != "") { $ename = "$myrow[0], "; }

else { $ename = ""; }

 

if($myrow[2] == "Buy") { $eaction = "To Buy: "; }

if($myrow[2] == "Sell") { $eaction = "For Sale: "; }

if($myrow[2] == "Give Away") { $eaction = "To Give Away: "; }

 

print <<<END

<a name="$myrow[6]"></a>

<b>${eaction}$myrow[3]</b>

<br>$myrow[4]

<br><i>${ename}$myrow[1], $myrow[5], (#${myrow[6]})</i>

<hr>

 

END;

}

 

?>

</font>

Link to comment
Share on other sites

here is the code from swapshop.php if it helps..

 

 

      <p><font face="Arial, Helvetica, sans-serif" size="4">Swap Shop<br>

                    <font size="2">Welcome to our Swap Shop online.</font></font></p>

<?php

//check for new item

if($title) {

 

$name = mysql_escape_string($name);

$phone = mysql_escape_string($phone);

$action = mysql_escape_string($action);

$category = mysql_escape_string($c);

$title = mysql_escape_string($title);

$description = mysql_escape_string($description);

$town = mysql_escape_string($town);

 

 

$sql = "INSERT INTO swapshop VALUES (null,now(),'$category','$name','$title','$description','$phone','$action','$town','$ip','No')";

$result = mysql_query($sql);

 

print <<<END

      <p><b><font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif">Added Item to Swap Shop</font></b></p>

END;

}

?>

      <p><img src="images/Categories.gif" width="209" height="20"></p>

      <ul>

        <font face="Arial, Helvetica, sans-serif" size="2">

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Air Conditioners">Air Conditioners</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Animals">Animals</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Appliances">Appliances</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Baby Items">Baby Items</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Bedding Items">Bedding Items</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Bicycles">Bicycles</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Boats and motors">Boats and motors</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Cars and Pickups">Cars and Pickups</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Celing Fans">Ceiling Fans</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Clothing">Clothing</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Computer Equipment">Computer Equipment</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Electronics">Electronics</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Exercise Equipment">Exercise Equipment</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Farm Equipment">Farm Equipment</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Fruit and Vegetables">Fruit and Vegetables</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Furniture">Furniture</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Health Care Items">Health Care Items</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Home Decorating">Home Decorating</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Home Repair">Home Repair</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Lawn mowers and tools">Lawn mowers and tools</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Miscellaneous">Miscellaneous</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Mobile Homes">Mobile Homes</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Motorcycles and 4-Wheelers">Motorcycles and 4-Wheelers</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Music Instruments">Music Instruments</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Real Estate">Real Estate</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Satelite Systems">Satelite Systems</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Swimming Pools">Swimming Pools</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Tickets for Sale">Tickets for Sale</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Tires">Tires</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Toys and games">Toys and Games</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=Trailers">Trailers</a></li>

        <li><a href="http://www.kwhw.com/view-swapshop.php?c=All Items">Show All Items</a></li>

        </font>

      </ul>

      <hr size="1" noshade>

<form method="post" action="http://www.kwhw.com/swapshop.php">

        <font face="Arial, Helvetica, sans-serif" size="3">

        <p><b><font size="2">Add A Swap Shop Item</font></b></p>

        <font size="2">Name <input type="text" name="name"><br>

        Phone <input type="text" name="phone"><br>

        Town <input type="text" name="town"><br>

        Action <select name="action">

          <option>Buy</option>

          <option>Give Away</option>

          <option selected>Sell</option>

        </select>

        <br>

        Category

        <select name="c">

          <option>Air Conditioners</option>

          <option>Animals</option>

          <option>Appliances</option>

          <option>Baby Items</option>

          <option>Bedding Items</option>

          <option>Bicycles</option>

          <option>Boats and motors</option>

          <option>Cars and Pickups</option>

          <option>Ceiling Fans</option>

          <option>Clothing</option>

          <option>Computer Equipment</option>

          <option>Electronics</option>

          <option>Exercise Equipment</option>

          <option>Farm Equipment</option>

          <option>Fruit and Vegetables</option>

          <option>Furniture</option>

          <option>Health Care Items</option>

          <option>Home Decorating</option>

          <option>Home Repair</option>

          <option>Lawn mowers and tools</option>

          <option>Miscellaneous</option>

          <option>Mobile Homes</option>

          <option>Motorcycles and 4-Wheelers</option>

          <option>Music Instruments</option>

          <option>Real Estate</option>

          <option>Satelite Systems</option>

          <option>Swimming Pools</option>

          <option>Tickets for Sale</option>

          <option>Tires</option>

          <option>Toys and Games</option>

          <option>Trailers</option>

        </select>

        <br>

        Item <input type="text" name="title"><br>

        Description<br>

        <textarea name="description" rows=5 cols=60></textarea>

        <br>

        </font></font>

        <input type="submit" name="add" value="Add Item" onClick="submit(); this.form.add.disabled=False;">

        <br>

        <font face="Arial, Helvetica, sans-serif"><b><font color="#FF0000" size="2">Your

        item will be posted as soon as it is reviewed, usually within one business

        day.<br>

        Please do not resubmit your item because it doesn't show up right away. </font></b></font>

</form>

Link to comment
Share on other sites

Sadly, it appears that the code is dependent on register_globals being on (POST/GET... data magically appears in program variables.) Since it is unlikely that you will be able to go through the code and find and correct all the issues with it until you have a better understanding of php, your best short term fix would be to turn register_globals on.

 

If you have access to the php.ini file, turn on register_globals in php.ini. Stop and start the web server to get any change made to php.ini to take effect.

 

If you don't have access to the php.ini file and this is on an Apache web server and the web host has not specifically prevented you from turning on register_globals in this way, add the following line to a .htaccess file -

 

php_flag register_globals on

 

Note: This in only a temporary fix, because register_globals have been completely eliminated in PHP6. So, it will be necessary at some point, to keep the code working, to go through it and fix everything that is depended on register_globals being on.

Link to comment
Share on other sites

I just want to say thank you very much. your suggestion worked right off the bat. whoever made the site did not add a php.ini so i had to modify the .htaccess file with your changes.

 

again thank you, you saved me a lot of pain and suffering.

 

Sadly, it appears that the code is dependent on register_globals being on (POST/GET... data magically appears in program variables.) Since it is unlikely that you will be able to go through the code and find and correct all the issues with it until you have a better understanding of php, your best short term fix would be to turn register_globals on.

 

If you have access to the php.ini file, turn on register_globals in php.ini. Stop and start the web server to get any change made to php.ini to take effect.

 

If you don't have access to the php.ini file and this is on an Apache web server and the web host has not specifically prevented you from turning on register_globals in this way, add the following line to a .htaccess file -

 

php_flag register_globals on

 

Note: This in only a temporary fix, because register_globals have been completely eliminated in PHP6. So, it will be necessary at some point, to keep the code working, to go through it and fix everything that is depended on register_globals being on.

Link to comment
Share on other sites

Until the code is corrected to not rely on register_globals, the pain and suffering can return without notice, should the web host disable your ability to turn register_globals on in a .htaccess file, you switch to a new host that does not allow or use a .htaccess file, or PHP6 is released, which ever occurs first.

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.