zero-perfoliate
zero-perfoliate

Author Topic: Problem with insert  (Read 194 times)

Offline Brav

  • New PHP Members
  • Posts: 3
  • Karma: +0/-0
Problem with insert
« on: December 22, 2010, 01:24:58 PM »
I have a bit problem with inserting data into the database. Problem is that it won't insert data when the function is called. Here is the code:
Code: [Select]
<?php

include(
"connections/mySQL.phpConnect.php");

mysql_select_db("$database_TestConnect") or die ("Unable to Connect to the database");

$table "statusValues";
if( mysql_num_rowsmysql_query("SHOW TABLES LIKE '".$table."'")))
{

}else{
print("Table was not found, I will create it now.<br>");

$sql  "CREATE TABLE `statusValues` (
`statVal_id` INT NOT NULL AUTO_INCREMENT ,
`FirstName` VARCHAR( 64 ) NOT NULL ,
`LastName` VARCHAR( 64 ) NOT NULL ,
`Region` INT NOT NULL ,
`SS#` INT NOT NULL,
INDEX ( `statVal_id` ) )"


mysql_query($sql) or die(mysql_error()) ;
print("Table Creation Complete. . .<br>");
}
if(isset($function) && $function=="add"){
$sqlInsert  "INSERT INTO  `statusvalues` (
`FirstName`, 
`LastName`, 
`Region`, 
`SS#`) 
VALUES ('$name', '$lastName', $regionNumber, $socialNumber)"
;

//print("$sqlInsert<br>");
mysql_query($sqlInsert) or die(mysql_error());
//print ("Date Enter Ok :D");
$function="";
echo'<script type="text/javascript" language="javascript">alert("Data Added.");location.replace("index.php");</script>';
}

$regSQL "SELECT `regionName`,`regionNumber` FROM ragions";
$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 First Name
    <input type="text" name="name" id="name" />
    <br />
Enter Last Name
<input type="text" name="lastName" id="lastName" />
<br />
Select Region Number
<select name="regionNumber" id="regionNumber">
  <?php while ( $myrow mysql_fetch_array($resultQuery) ) { ?>
 
  <option value="<?php echo $myrow['regionNumber']; ?>"><?php echo $myrow['regionNumber'] ."-"$myrow['regionName']; ?></option>
 
  <?php ?>
</select>
<br />
Please Enter SS# No Dashes
<input type="text" name="socialNumber" id="socialNumber" />
<br />
<input type="submit" name="addData" id="addData" value="Ok" />
</form>
<?php

$selectQuery "SELECT  * FROM statusvalues
 WHERE 1
 ORDER BY LastName ASC"
;
$resultName mysql_query($selectQuery) or die(mysql_error());

?>

<table width="400" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td>id#</td>
    <td>First Name</td>
    <td>Last Name</td>
    <td align="center">Region</td>
    <td>&nbsp;</td>
  </tr>

<?php while ($myrowRes mysql_fetch_array($resultName)) { ?>

  <tr><p></p>
    <td><?php echo $myrowRes['statVal_id']; ?></td>
    <td><?php echo $myrowRes['FirstName']; ?></td>
    <td><?php echo $myrowRes['LastName']; ?></td>
    <td align="center"><?php echo $myrowRes['Region']; ?></td>
    <td>&nbsp;</td>
  </tr>

<?php ?>
</table>

</body>
</html>

Table is working properly (it display data that i have manually inserted into the DB). Any idea what seems to be the problem???