Filename: example_insert.php
<?php require_once('Connections/db.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;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "add")) {
$insertSQL = sprintf("INSERT INTO my_table (`number`, name) VALUES (%s, %s)",
GetSQLValueString($_POST['number'], "int"),
GetSQLValueString($_POST['name'], "text"));
mysql_select_db($database_db, $db);
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
$insertGoTo = "example_insert.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>my page</title>
</head>
<body>
<form method="POST" action="<?php echo $editFormAction; ?>" name="add">
<p align="center">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div align="right"><b><font face="Verdana">Number:</font></b></div></td>
<td> </td>
<td><input type="text" name="number" size="8"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right"><b><font face="Verdana">Name:</font></b></div></td>
<td> </td>
<td><input type="text" name="name" size="25"></td>
</tr>
</table>
</div><br />
<div align="center">
<input type="hidden" name="MM_insert" value="add">
<input name="Submit" type="submit" id="Submit" value="Save"> <input name="Reset" type="reset" value="Reset">
</p>
</div>
</form>
</body>
</html>