Thursday, 12 September 2013

Inserting data into a Database using PHP (errors but doesn't insert anything);

Inserting data into a Database using PHP (errors but doesn't insert
anything);

Following tutorials I found online and this one basically was showing me
how to insert data into a database. I have Database called
JapaneseDefinition and I have the table named Japanesewords. I got HTML
Code that sends Japaneseword and English into my Database.
I am able to look up a word with a different query, but I am having no
such look with the INSERT Query. Can someone look at my code and tell me
where I am going wrong with it.
try{
$conn = new
PDO('mysql:host=Jamal-PC;dbname=japanesewords',$username,$password);
if(isset($_POST['EnglishWord'])){
$Japaneseword = $_POST ['JapaneseWord'];
$Englishword = $_POST['EnglishWord'];
$q = "INSERT INTO
Japanesedefinition(Japaneseword,Englishword)VALUES(:Japaneseword,:Englishword):";
$query = $conn->prepare($q);
$result = $query->execute(array(
'Japaneseword'=>$Japaneseword,
"Englishword"=>$Englishword
));
}
}catch(PDOException $e){
echo 'ERROR: ' . $e->getMessage();
}
echo 'hello';
}
myTest();
?>

No comments:

Post a Comment