Hi have a signup form with
<form action="test.php" method="post" id="insert" name="signup" onsubmit="return validateForm();">
and the code for test is:
<?php
require_once 'config.php';
function error($msg) {
global $message;
$message = $msg;
include "signup.php";"database.php";
die();
}
function error2($msg) {
error("<font color=\"red\"><b><i>$msg</i></b></font>");
}
function esc($data) {
return mysql_real_escape_string($data);
}
function getesc($varname) {
global $$varname;
$$varname = isset($_POST[$varname]) ? esc($_POST[$varname]) : "";
return $$varname;
}
//Get data in local variable
getesc('CNAME');
getesc('CSTREET');
getesc('CCITY');
getesc('CZIP');
getesc('CSTATE');
getesc('CCOUNTRY');
getesc('CPHONE');
getesc('CEMAIL');
getesc('password');
getesc('securityq');
getesc('securitya');
try { $conn = new PDO("mysql:host=$db_host1;dbname=$db_database1", $db_username1, $db_password1);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO COMPANY (COMPANY_NAME, COMPANY_STREET, COMPANY_CITY, COMPANY_ZIP, COMPANY_STATE, COMPANY_COUNTRY, COMPANY_PHONE, COMPANY_EMAIL, password, securityq, securitya)
VALUES ('$CNAME', '$CSTREET', '$CCITY', '$CZIP', '$CSTATE', '$CCOUNTRY', '$CPHONE', '$CEMAIL', '$password', '$securityq', '$securitya')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
It works fine in inserting all values into db. I want to display msg to user when a required field like password id not entered. Can you please show me how?
Thanks