<?php
echo date('y:n:d h:i:s');
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("form") or die(mysql_error());
//$_SERVER['REQUEST_METHOD']=='POST'
if(isset($_POST['submit_true']))
{
//Variables declaration
$first_name=mysql_real_escape_string($_POST['first_name']);
$last_name=mysql_real_escape_string($_POST['last_name']);
$email=mysql_real_escape_string($_POST['email']);
$gender=mysql_real_escape_string($_POST['gender']);
$language=mysql_real_escape_string($_POST['language']);
$subjects=$_POST['subjects'];
var_dump($_POST['subjects']);
$subject=$temprary="";
foreach($subjects as $temprary)
{
$subject="".$temprary.",";
}
$image=$_FILES['file']['name'];
$mobile=mysql_real_escape_string($_POST['mobile']);
$password=md5(mysql_real_escape_string($_POST['password']));
$confirm_password=md5(mysql_real_escape_string($_POST['mobile']));
//Variables declaration End
//Database Input
$email_check=mysql_query("SELECT * FROM user WHERE 'email==$email'");
if(mysql_num_rows($email_check)>0)
{
echo "<script>alert('Email already exist!')</script>";
}
else if($password==$confirm_password)
{
echo "<script>alert('Password does not match!')</script>";
}
else
{
mysql_query("INSERT INTO `user`(`first_name`, `last_name`, `email`, `gender`, `language`, `subject`, `image`, `mobile`, `password`) VALUES ('$first_name','$last_name','$email','$gender','$language','$subject','$image','$mobile','$password'");
$server_file=$_FILES['file']['tmp_name'];
$basename=basename($_FILES['file']['name']);
$destination_file="uploads/".$basename;
move_uploaded_file($server_file,$destination_file);
}
//Database Input End
}
else
{
echo "All good!";
}
?>
This is the PHP! The var_dump function returns NULL for $_POST['subjects'] instead of array of the inputs. Please focus only on elements related to the checkbox in the HTML as well as the PHP.
<html>
<head>
<title>Form!</title>
</head>
<body>
<form method="post" action="" enctype="multipart/form-data">
First Name: <input type="text" name="first_name"><br/><br/> Last Name: <input type="text" name="last_name"><br/><br/> Email: 
<input type="email" name="email"><br/><br/> Gender:      Male
<input type="radio" name="gender" value="Male"> Female
<input type="radio" name="gender" value="Female">
<br/><br/> Subject:  English 
<input type="checkbox" name="subjects[]" value="eng"> Physics 
<input type="checkbox" name="subjects[]" value="phy"> Computer 
<input type="checkbox" name="subjects[]" value="com"> Mathematics 
<input type="checkbox" name="subjects[]" value="mat">
<br/><br/> language: 
<select name="language">
<option value="eng">English</option>
<option value="hin">Hindi</option>
<option value="spa">Spanish</option>
</select>
<br/><br/> Upload Image: <input type="file" name="file"><br/><br/> Mobile: 
<input type="text" name="mobile"><br/><br/> Password: 
<input type="password" name="password"><br/><br/> Confirm Password: <input type="password" name="confirm_password"><br/><br/>
<input type="submit" name="submit_true"><br/><br/>
</form>
</body>
</html>
Help me understand why a valid input is not being returned? Please help me check for any kind of mistake if it is. Let me know the reason this is not working please.
Aucun commentaire:
Enregistrer un commentaire