I am trying to get data from my text field to go into my database from my form located on my
php page. Its a experiment, the error logs are saying i have syntax errors on lines 34 and 36.
Could some one explain what i am doing wrong.
Its only 1 text box and a tiny database, so its should be easy to spot n fix.
here is my code:
And under that is my database
- PHP: Select all
<?php require_once('Connections/dblearn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tbl_data (name) VALUES (%s)",
GetSQLValueString($_POST['name'], "int"),
mysql_select_db($database_dblearn, $dblearn);
$Result1 = mysql_query($insertSQL, $dblearn) or die(mysql_error());
$insertGoTo = "Customer Data.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_dblearn, $dblearn);
$query name = "SELECT * FROM tbl_data ORDER BY imid ASC";
$name = mysql_query($query name, $dblearn) or die(mysql_error());
$row name = mysql_fetch_assoc($ name);
$totalRows name = mysql_num_rows($ name);
?><!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>Untitled Document</title>
</head>
<body>
<p>Please Insert Your Name Below</p>
<form id="form1" name="form1" method="POST">
<label>
<input type="text" name="Name Insert Field" id="Name Insert Field" />
</label>
</form>
<form id="form2" name="form2" method="post" action="">
<label>
<input type="submit" name="Button" id="Button" value="Submit" />
</label>
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Here my database:
CREATE DATABASE IF NOT EXISTS dblearn;
USE dblearn;
CREATE TABLE tbl_data (name VARCHAR(20), address VARCHAR(50), post_code VARCHAR(7), telephone_no VARCHAR(25));
Please help