Problems with isset
Posted: Sun Jun 28, 2009 9:57 pm
Hey Guys
Does anyone see anything wrong with the way I've put this together???
The $sqlInsert seem to stop working when I try to put this into play
Line 29-- if(isset($function) && $function=="add"){ --
If I slash that line out the $sqlInsert function works
I'm fairly new to php and thought I would challenge myself some, however with challenges comes defeat, any help would appreciated.
Does anyone see anything wrong with the way I've put this together???
The $sqlInsert seem to stop working when I try to put this into play
Line 29-- if(isset($function) && $function=="add"){ --
If I slash that line out the $sqlInsert function works
I'm fairly new to php and thought I would challenge myself some, however with challenges comes defeat, any help would appreciated.
Code: Select all
<?php
include("../../../connections/mysql_connect.php");
mysql_select_db("$database") or die ("Unable to Connect to the Database");
$table = "company_z";
if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".$table."'")))
{
//print("Found Table.Ready to Proceed!");
}else{
print("Table was not found, I will create it now.<br>");
$sql = "CREATE TABLE `company_z` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`company` VARCHAR( 64 ) NOT NULL ,
`address` VARCHAR( 64 ) NOT NULL ,
`postal_code` VARCHAR( 12 ) NOT NULL ,
`phone` VARCHAR( 16 ) NOT NULL ,
`email` VARCHAR( 32 ) NOT NULL ,
`region` VARCHAR( 12 ) NOT NULL) " ;
mysql_query($sql) or die(mysql_error()) ;
print("Table Creation Complete. . .<br>");
}
if(isset($function) && $function=="add"){
$sqlInsert = "INSERT INTO `company_z` (
`company`,
`address`,
`postal_code`,
`phone`,
`email`,
`region`)
VALUES ('Some Company', 'some address', 'postal', '555-555-5555', 'me@here.ca', 4 )";
//print("$sqlInsert<br>");
mysql_query($sqlInsert) or die(mysql_error());
}
$regSQL = "SELECT `regionName`,`regionNumber` FROM regions";
$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>
<table width="42%" height="145" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top"><p>Add your clients shipping information here<br />
</p>
<table width="289" height="114" border="0" cellpadding="0" cellspacing="0">
<form id="enterForm" name="dataEnter" method="post" action="index.php?function=add">
<tr>
<td width="100" height="25" align="left" valign="middle" class="style26">Company</td>
<td width="168" height="25" align="left" valign="middle"><input type="text" name="company" id="company" /></td>
</tr>
<tr>
<td width="100" height="25" align="left" valign="middle" class="style26">Address</td>
<td width="168" height="25" align="left" valign="middle"><input type="text" name="address" id="address" /></td>
</tr>
<tr>
<td width="100" height="25" align="left" valign="middle" class="style26">Postal Code</td>
<td width="168" height="25" align="left" valign="middle"><input type="text" name="postal" id="postal" /></td>
</tr>
<tr>
<td width="100" height="25" align="left" valign="middle" class="style26">Phone</td>
<td width="168" height="25" align="left" valign="middle"><input type="text" name="phone" id="phone" /></td>
</tr>
<tr>
<td width="100" height="25" align="left" valign="middle" class="style26">Email</td>
<td width="168" height="25" align="left" valign="middle"><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td width="100" height="25" align="left" valign="middle" class="style26">Region</td>
<td width="168" height="25" align="left" valign="middle"><select name="regionNumber" id="regionNumber">
<? while ( $myrow = mysql_fetch_array($resultQuery) ) { ?>
<option value="<? echo $myrow['regionNumber']; ?>"><? echo $myrow['regionNumber'] ."-". $myrow['regionName']; ?></option>
<? } ?>
</select>
</td>
</tr>
<tr>
<td height="25" colspan="2" align="left" valign="middle" class="style26"><div align="center">
<input type="submit" name="addData" id="addData" value="Submit" />
</div></td>
</tr>
</form>
</table>
<p></p></td>
</tr>
</table>