5

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', '$password', '$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

hakre
  • 193,403
  • 52
  • 435
  • 836
Iyad Al aqel
  • 2,020
  • 3
  • 21
  • 32

1 Answers1

1

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();
dqhendricks
  • 19,030
  • 11
  • 50
  • 83