this is my first php code and it is full of problems probably :)
I want to register information of people visiting my website. My main problem is that FARSI words in sql are not registered right and it is showing wrong characters.
I tried to use N for making it unicode but it didn't work for me. Maybe I'm using it wrong.
Also I tried give everyone a unique ID but I could not figure how.
My sql collation for FARSI parts are utf8 persian ci. I am using phpmy admin and I tried to make nvarchar in it but it only offers varchar.
This is my first question and first php code so please forgive me If it is too basic.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<?php
$name = $_POST["name"];
$familyname = $_POST["familyname"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$pass = $_POST["pass"];
$pass2 = $_POST["pass2"];
$id = 100;
// Remove all illegal characters from email
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate e-mail
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === true) {
echo("$email صحیح نمی باشد");
} else {
$con = mysqli_connect("localhost","","","register");
$name = mysqli_real_escape_string($con, $_POST['name']);
$familyname = mysqli_real_escape_string($con, $_POST['familyname']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$phone = mysqli_real_escape_string($con, $_POST['phone']);
$pass = mysqli_real_escape_string($con, $_POST['pass']);
$pass2 = mysqli_real_escape_string($con, $_POST['pass2']);
mysqli_query($con,"INSERT INTO users (`name17`, `familyname17`, `email17`, `phone17`, `pass17`, `id17`) VALUES ('$name', '$familyname', '$email', '$phone', '$pass', '$id')");
$result = mysqli_query($con,"select * from users where email17 ='$email' and pass17 = '$pass' and familyname17 = '$familyname'" )
or die("faild to query database".mysql_error());
$row = mysqli_fetch_array($result,MYSQLI_BOTH);
if (empty($name) || empty($familyname) || empty($email) || empty($phone) || empty($pass) || empty($pass2)) {
echo "لطفا اطلاعات را بطور کامل وارد فرمایید";
}
else {
if ($row['email17']==$email && $row['pass17'] == $pass2){
echo "<body style='direction: rtl !important;'>";
echo "<b>".$row['name17']." <b>";
echo "عزیز. خوش آمدید<br> ";
echo '<img src="images/takhfif.jpg" alt="تخفیف" />';
} else {
echo "خطا در ثبت نام.لطفا دوباره تلاش کنید";
}
}
}
?>
</body>
</html>