Her er lidt:
SQL DUMP:
CREATE TABLE `tilmeld` (
`ID` varchar(50) collate latin1_danish_ci NOT NULL,
`Navn` varchar(100) collate latin1_danish_ci NOT NULL,
`Adresse` varchar(255) collate latin1_danish_ci NOT NULL,
`Postnr` varchar(10) collate latin1_danish_ci NOT NULL,
`By` varchar(100) collate latin1_danish_ci NOT NULL,
`Tlf` varchar(10) collate latin1_danish_ci default NULL,
`Email` varchar(255) collate latin1_danish_ci default NULL,
`Gren` varchar(100) collate latin1_danish_ci NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_danish_ci;
PHP side til at indsætte records:
<?php $hostname_test = "DB-HOST";
$database_test = "DB-NAME";
$username_test = "DB-USER";
$password_test = "DB-PASSWORD";
$test = mysql_pconnect($hostname_test, $username_test, $password_test) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?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"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tilmeld (ID, Navn, Adresse, Postnr, `By`, Tlf, Email, Gren) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['hiddenField'], "text"),
GetSQLValueString($_POST['navn'], "text"),
GetSQLValueString($_POST['adresse'], "text"),
GetSQLValueString($_POST['postnr'], "text"),
GetSQLValueString($_POST['by'], "text"),
GetSQLValueString($_POST['tlf'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['slaegt'], "text"));
mysql_select_db($database_test, $test);
$Result1 = mysql_query($insertSQL, $test) or die(mysql_error());
$insertGoTo = "test.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="95" align="right">Navn:</td>
<td width="405" align="left"><input name="navn" type="text" id="navn" size="40" /></td>
</tr>
<tr>
<td align="right">Adresse:</td>
<td align="left"><input name="adresse" type="text" id="adresse" size="40" /></td>
</tr>
<tr>
<td align="right">Postnr:</td>
<td align="left"><input name="postnr" type="text" id="postnr" size="10" /></td>
</tr>
<tr>
<td align="right">By:</td>
<td align="left"><input name="by" type="text" id="by" size="40" /></td>
</tr>
<tr>
<td align="right">Email:</td>
<td align="left"><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td align="right">Tlf:</td>
<td align="left"><input name="tlf" type="text" id="tlf" size="10" /></td>
</tr>
<tr>
<td align="right">Slægtsgren:</td>
<td align="left"><select name="slaegt" id="slaegt">
<option value="1">gren1</option>
<option value="2">gren2</option>
<option value="3">gren3</option>
<option value="4">gren4</option>
<option value="5">gren5</option>
<option value="6">gren6</option>
<option value="7">gren7</option>
</select>
</td>
</tr>
<tr>
<td align="right"> </td>
<td align="left"><input type="submit" name="Submit" value="Indsæt" />
<input name="hiddenField" type="hidden" value=">?php echo time(); ?>" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>