<?php require_once('Connections/Krittiya.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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 tb_krittiya (name, username, password, address, numtel) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['numtel'], "text"));

  mysql_select_db($database_Krittiya, $Krittiya);
  $Result1 = mysql_query($insertSQL, $Krittiya) or die(mysql_error());

  $insertGoTo = "show.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<style type="text/css">
body {
	background-image: url(New%20folder/%E0%B8%9E%E0%B8%B7%E0%B9%89%E0%B8%99%E0%B8%AB%E0%B8%A5%E0%B8%B1%E0%B8%87.jpg);
	background-repeat: repeat;
}
body,td,th {
	font-size: 36px;
	color: #300;
	font-weight: bold;
	font-family: "DSN Poppy";
}
</style>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
  <p>&nbsp;</p>
  <table width="518" height="313" border="0" align="center">
    <tr>
      <td colspan="2" align="center">สมัครสมาชิกใหม่</td>
    </tr>
    <tr>
      <td width="67" align="center">name</td>
      <td width="123" align="center"><label for="name"></label>
      <input type="text" name="name" id="name" /></td>
    </tr>
    <tr>
      <td align="center">username</td>
      <td align="center"><label for="username"></label>
      <input type="text" name="username" id="username" /></td>
    </tr>
    <tr>
      <td align="center">password</td>
      <td align="center"><label for="password"></label>
      <input type="password" name="password" id="password" /></td>
    </tr>
    <tr>
      <td align="center">address</td>
      <td align="center"><label for="address"></label>
      <input type="text" name="address" id="address" /></td>
    </tr>
    <tr>
      <td align="center">numtel</td>
      <td align="center"><label for="numtel"></label>
      <input type="text" name="numtel" id="numtel" /></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input type="submit" name="button" id="button" value="ตกลง" />
      <input type="reset" name="button2" id="button2" value="ยกเลิก" /></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
