I uses isset(); function to pass value od $post var to a normal variable with a genral script without any problems.
like this
$headline=isset($POST['headlineform']);
echo $headline;
But what comes the problem is when I try to pass it to SQL to insert to Mysql DB.Here is the code.
<?
// pass in $GET or $POST here:
$dbHost = "localhost";
$dbUser = "dawn";
$dbPass = "dawn";
$dbName = "news";
$table = "user";
$connect = @mysql_connect ($dbHost, $dbUser, $dbPass);
if (!$connect) {
echo "goback=" . urlencode("Error Cannot connect to SQL Server") . "&";
exit;
}
if (!@mysql_select_db ($dbName)) {
echo "goback=" . urlencode("Error Cannot Select DATABASE") . "&" ;
exit;
}
//Intialize predefined variables
$pname = $name;
$plastname =isset($POST['lastname']);
$pemail = isset($POST['email']);
$pphonenumber = isset($POST['phonenumber']);
$pcity = isset($POST['city']);
$pusername = isset($POST['username']);
$ppassword = isset($POST['password1']);
$psex = isset($POST['sex']);
$pacceptnews=isset($POST['acceptnews']);
//Intitialize query
$query = "INSERT INTO $table (name, lastname, email, phonenumber, city, username, password, sex, acceptnews)
VALUES($pname, $plastname, $pemail, $pphonenumber, $pcity, $pusername, $ppassword, $psex, $pacceptnews)";
$result = @($query);
/ If the query has problem /
if (!$result ){
echo "goback=" . mysql_error() . error_reporting() ;
exit;
}
//close connect
@mysql_close($connect);
?>
That cause PHP error:
goback=You have an error in your SQL syntax near ' , , , , , , , )' at line 22047PHP Notice: Undefined variable: name in C:\Inetpub\wwwroot\php\register.php on line 18
That is definitely comes from SQL but I don;'t know how to fix this.
If I don;'t use isset to pass $post value
it will cause "Undefined index "error.
Thank you for your help.