Hello
I have this code and when I load the page parts of the PHP codes are displayed on the page, can you tell me what is wrong with the code? does it not recognize it as php code?
Here is the code:
<?php include('connect.php');
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
///
$vfname = "";
$vlname = "";
$vlogin="";
$vpassword="";
$vcpassword="";
$vaddress="";
$vcnumber="";
$vemail="";
$a="";
$u="";
$e="";
//
$fname = "";
$lname = "";
$login="";
$password="";
$cpassword="";
$address="";
$cnumber="";
$email="";
if (isset($_POST['Submit'])) {
//Sanitize the POST values
$fname = ($_POST['fname']);
$lname = ($_POST['lname']);
$login =($_POST['login']);
$password = md5($_POST['password2']);
$cpassword = md5($_POST['cpassword']);
$address = ($_POST['address']);
$cnumber =($_POST['cnumber']);
$email = ($_POST['email']);
$gender = ($_POST['gender']);
//$bdate = clean($_POST['bdate']);
$propic = ($_POST['propic']);
$bday=$_POST['month'];
$pattern = "/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i";
//Input Validations
if (!preg_match($pattern,$email)){
$e = "Invalid Email Address";
}
if ($email=="") {
$e = "";
}
if ($fname=="") {
$vfname = "<td>Field Missing.</td>";
}else{
$vfname="";
}
if ($lname==""){
$vlname = "<td>Field Missing.</td>";
}else{
$vlname="";
}
if ($login=="") {
$vlogin = "<td>Field Missing.</td>";
} else{
$vlogin = "";
}
if ($password=="") {
$vpassword = "<td>Field Missing.</td>";
} else{
$vpassword="";
}
if ($cpassword=="") {
$vcpassword = "<td>Field Missing.</td>";
} else{
$vcpassword="";
}
if ($address=="") {
$vaddress = "<td>Field Missing.</td>";
} else{
$vaddress="";
}
if ($cnumber=="") {
$vcnumber= "<td>Field Missing.</td>";
} else{
$vcnumber="";
}
if ($email=="") {
$vemail = "<td>Field Missing.</td>";
} else{
$vemail="";
}
if($cpassword!=$password){
$a="Password do not Match";}
if ($cpassword==""){
$a="";
}
//Check for duplicate login ID
if($login != '') {
$query = "SELECT * FROM members WHERE UserName='$login'";
$result = mysql_query($query);
if($result) {
if(mysql_num_rows($result) > 0) {
$u = 'UserName already in use';
}
@mysql_free_result($result);
}
else {
die("Query failed");
}
}
if ($fname!= "" && $lname!= "" && $login!= "" && $password!= "" && $cpassword==$password && $address!="" && preg_match($pattern,$email) && $cnumber!="" ) {
$link = mysql_connect("localhost", "root", "");
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db("db");
if(!$db) {
die("Unable to select database");
}
$query = mysql_query("INSERT INTO members(UserName, Password, FirstName, LastName, Address, ContactNo, Url, Birthdate, Gender, profImage,curcity)VALUES('$login','$password','$fname','$lname','$address','$cnumber','$email','$bday','$gender','$propic','$address')")or die(mysql_error());
header('Location: signup-success.php');
echo "login success";
}
}
?>
And this is how the page looks like:
[ATTACH]5151[/ATTACH]
page.jpg