a query is inserted from PHPMYAdmin but not from PHP
i'm writing a php code to insert form values in a forum values
$dbServer = mysql_connect("localhost" , "root", "") ;
if(!$dbServer) die ("Unable to connect");
mysql_select_db("kfumWonder");
$name= $_POST['name'] ;
$password= md5($_POST['password']);
$email= $_POST['email'] ;
$major= $_POST['major'] ;
$dateOfBirth=$_POST['dateOfBirth'] ;
$webSite = $_POST['website'];
$joinDate= date("Y m d") ;
$query = "INSERT INTO user (name, password, email, major, dob, website, join_date)
Values ('$name', '$passwo开发者_高级运维rd', '$email', '$major', '$dateOfBirth',
'$webSite' , '$joinDate')" ;
//echo $query ;
$result = mysql_query($query) ;
if (! $result )
echo " no results " ;
this works perfectly fine when i took the printed query and run it in PHPMyAdmin but when i run this code nothing happens
Your POST vars need to be escaped if you do not have magic quotes on like this mysql_real_escape_string($_POST['blah']). Even if magic quotes is on, you should strip slashes, or turn off magic quotes in the cofig, and re-escape them with mysql_real_escape_string. Or use PDO to do database entries as it handles this for you.
Also, to see what your errors are, you could call your query like this:
if (!$result = mysql_query($query)) echo mysql_error();
精彩评论