The request is inserted from PHPMYAdmin, but not from PHP

I am writing PHP code to insert form values ​​in 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', '$password', '$email', '$major', '$dateOfBirth',
                  '$webSite' , '$joinDate')" ; 

//echo $query ; 
$result = mysql_query($query) ;

if (! $result ) 
 echo " no results "  ;

this works fine when I took the printed request and ran it in PHPMyAdmin, but when I run this code nothing will happen

+5
source share
1 answer

Your POST files should be escaped unless you have magic quotes like this mysql_real_escape_string ($ _ POST ['blah']). Even if magic quotes are turned on, you must cut slashes or turn off magic quotes in cofig and re-escape them using mysql_real_escape_string. Or use PDO to write the database as it handles this for you.

, , , :

if (!$result = mysql_query($query)) echo mysql_error();
+1

All Articles