MySQL Forums
Forum List  »  PHP

Is it possible for a PHP installation/interpreter to be corrupted?
Posted by: Frederick Ahmed
Date: July 18, 2005 10:49AM

Can I first declare that I am a newbie.
I am getting some strange occurrences with my PHP:

Problem #1
I had 2 IDENTICAL codes for a simple form but in different files. One worked but the other did not. Unfortunately, I have deleted the file that did not work and only retained the one that works. I am not including this here since this is an old problem.

Problem #2
This is a current problem. I have a file where one of the variables is called $price. The code works perfectly.
I then save to another file and change the name of the variable from $price to $rent and it gives me the following error message:
Query failed: Unknown column 'rent' in 'where clause'.

BELOW IS THE ORIGINAL CODE THAT WORKS PERFECTLY:
<?php
//Error reporting
error_reporting(E_ALL);
// Defining $Post items
$postcode = $_POST['postcode'];
$price=$_POST['price'];
echo $postcode;
echo "price is £".$price.".<br/>";

// Connecting, selecting database
$link = mysql_connect('localhost', 'root', 'secret')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('properties') or die('Could not select database');

//IF_Statements, then Performing SQL query
if (($price == NULL) AND ($postcode == "All"))
{$query = "SELECT * FROM tolet2";}
else if ($price == NULL)
{$query = "SELECT * FROM tolet2 WHERE postcode = '$postcode'";}
else if ($postcode == "All")
{$query = "SELECT * FROM tolet2 WHERE price <= '$price'";}
else {$query = "SELECT * FROM tolet2 WHERE postcode = '$postcode'
AND price <= '$price'";}

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>

AND THIS IS THE SAVED AND ALTERED FILE THAT IS CAUSING PROBLEMS:
<?php
//Error reporting
error_reporting(E_ALL);
// Defining $Post items
$postcode = $_POST['postcode'];
$rent=$_POST['rent'];
echo $postcode;
echo "rent is £".$rent.".<br/>";

// Connecting, selecting database
$link = mysql_connect('localhost', 'root', 'secret')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('properties') or die('Could not select database');

//IF_Statements, then Performing SQL query
if (($rent == NULL) AND ($postcode == "All"))
{$query = "SELECT * FROM tolet2";}
else if ($rent == NULL)
{$query = "SELECT * FROM tolet2 WHERE postcode = '$postcode'";}
else if ($postcode == "All")
{$query = "SELECT * FROM tolet2 WHERE rent <= '$rent'";}
else {$query = "SELECT * FROM tolet2 WHERE postcode = '$postcode'
AND rent <= '$rent'";}

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>

As you can see, the only thing changed is the name $price to $rent. I have been over it with a fine toothcombe and also repeated the save and name-change exercise. The respective HTML form files have been changed appropriately.
Further, I get problems expanding the "else if" statements to incorporate further drop-down boxes, but this is another story.

WOULD BE GRATEFUL FOR ANY HELP
Frederick
London, UK

Options: ReplyQuote


Subject
Written By
Posted
Is it possible for a PHP installation/interpreter to be corrupted?
July 18, 2005 10:49AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.