shalli
12-08-2008, 11:39 AM
Hi
Wondering if anyone can assist me with php mysql and html forms errors that I am getting
I am trying to get this page to print what the user select in the drop down menu 'areaName'. At the moment the print command does nothing at all.:confused::confused:
Any help will be much appreciated
thanks in advance
shalli
<?php
include("connection/dbconnect.php");
// STEP 1: Connect to the database:
mysql_select_db("$database_TestConnect") or die ("Unable to Connect to the database");
//STEP 2: See if there is a table that you require...
$table = "propertyValues";
if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".$table."'")))
{
//print("Found Table. Ready to proceed!<br>");
}else{
print("Table was not found, I will create it now.<br>");
//STEP 3: Create the table:
$sql = "CREATE TABLE `propertyValues` (
`propertyVal_id` INT NOT NULL AUTO_INCREMENT ,
`propertyTitle` VARCHAR( 64 ) NOT NULL ,
`address` VARCHAR( 300 ) NOT NULL ,
`city` VARCHAR( 64 ) NOT NULL ,
`county` VARCHAR( 64 ) NOT NULL ,
`postcode` VARCHAR( 7 ) NOT NULL,
`propertyPrice` INT NOT NULL ,
INDEX ( `propertyVal_id` ) )";
mysql_query($sql) or die(mysql_error()) ;
print("Table Creation Complete. . .<br>");
}
if(isset($function) && $function=="add"){
print("This is the county name selected - '$areaName'<br>");
$sqlInsert = "INSERT INTO `propertyValues` (
`propertyTitle`,
`address`,
`city`,
`county`,
`postcode`,
`propertyPrice`)
VALUES ( '$propertyTitle', '$address', '$city', '$areaName', '$postcode', $propertyPrice )";
//print("$sqlInsert<br>");
mysql_query($sqlInsert) or die(mysql_error());
print("Data OK!!");
}
$regSQL = "SELECT `areaName` FROM area";
$resultQuery = mysql_query($regSQL) or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP/MySQL Programming Course Part 2</title>
</head>
<body>
<form id="enterForm" name="dateEnter" method="post" action="index.php?function=add">
Enter Property Name
<input type="text" name="propertyTitle" id="propertyTitle" />
<br />
Enter Property Address
<input type="text" name="address" id="address" />
<br />
Enter City
<input type="text" name="city" id="city"/>
<br />
Select County
<select name="areaName" id="areaName" />
<? while ( $myrow = mysql_fetch_array($resultQuery) ) { ?>
<option value="<? echo $myrow['areaName']; ?>"><? echo $myrow['areaName']; ?></option>
<? } ?>
</select><br />
Enter PostCode
<input type="text" name="postcode" id="postcode" />
<br />
Enter Property Price
<input type="text" name="propertyPrice" id="propertyPrice" />
<br />
<input type="submit" name="addData" id="addData" value="Ok" />
</form>
</body>
</html>
Wondering if anyone can assist me with php mysql and html forms errors that I am getting
I am trying to get this page to print what the user select in the drop down menu 'areaName'. At the moment the print command does nothing at all.:confused::confused:
Any help will be much appreciated
thanks in advance
shalli
<?php
include("connection/dbconnect.php");
// STEP 1: Connect to the database:
mysql_select_db("$database_TestConnect") or die ("Unable to Connect to the database");
//STEP 2: See if there is a table that you require...
$table = "propertyValues";
if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".$table."'")))
{
//print("Found Table. Ready to proceed!<br>");
}else{
print("Table was not found, I will create it now.<br>");
//STEP 3: Create the table:
$sql = "CREATE TABLE `propertyValues` (
`propertyVal_id` INT NOT NULL AUTO_INCREMENT ,
`propertyTitle` VARCHAR( 64 ) NOT NULL ,
`address` VARCHAR( 300 ) NOT NULL ,
`city` VARCHAR( 64 ) NOT NULL ,
`county` VARCHAR( 64 ) NOT NULL ,
`postcode` VARCHAR( 7 ) NOT NULL,
`propertyPrice` INT NOT NULL ,
INDEX ( `propertyVal_id` ) )";
mysql_query($sql) or die(mysql_error()) ;
print("Table Creation Complete. . .<br>");
}
if(isset($function) && $function=="add"){
print("This is the county name selected - '$areaName'<br>");
$sqlInsert = "INSERT INTO `propertyValues` (
`propertyTitle`,
`address`,
`city`,
`county`,
`postcode`,
`propertyPrice`)
VALUES ( '$propertyTitle', '$address', '$city', '$areaName', '$postcode', $propertyPrice )";
//print("$sqlInsert<br>");
mysql_query($sqlInsert) or die(mysql_error());
print("Data OK!!");
}
$regSQL = "SELECT `areaName` FROM area";
$resultQuery = mysql_query($regSQL) or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP/MySQL Programming Course Part 2</title>
</head>
<body>
<form id="enterForm" name="dateEnter" method="post" action="index.php?function=add">
Enter Property Name
<input type="text" name="propertyTitle" id="propertyTitle" />
<br />
Enter Property Address
<input type="text" name="address" id="address" />
<br />
Enter City
<input type="text" name="city" id="city"/>
<br />
Select County
<select name="areaName" id="areaName" />
<? while ( $myrow = mysql_fetch_array($resultQuery) ) { ?>
<option value="<? echo $myrow['areaName']; ?>"><? echo $myrow['areaName']; ?></option>
<? } ?>
</select><br />
Enter PostCode
<input type="text" name="postcode" id="postcode" />
<br />
Enter Property Price
<input type="text" name="propertyPrice" id="propertyPrice" />
<br />
<input type="submit" name="addData" id="addData" value="Ok" />
</form>
</body>
</html>