the student
asked on
PHP insert data in to database... this is not letting me in insert data...please help!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Saving Data</title>
<a href="showDetails.php">Sho w All User's Profile</a>
</head>
<body>
<?php
$fName =$_POST['fName'];
$lName=$_POST['lName'];
$email=$_POST['email'];
$PhoneNo=$_POST['PhoneNo'] ;
$gender=$_POST['gender'];
$resumeDoc = $_POST['resumeDoc'];
//VARIABLE TO INDICATE IF INPUT HAS 1 OR MORE ERROR
$ok=true;
//VALIDATE THE INPUTS
if(empty($fName)){
echo 'First Name is required <br />';
$ok=false;
}
if(empty($lName)){
echo 'Last Name is required <br />';
$ok=false;
}
if(empty($email)){
echo 'Email is required <br />';
$ok=false;
}
if(!empty($PhoneNo)) {
if ($PhoneNo < 1) {
echo 'Please Enter Valid Number';
$ok = false;
}
else{
// CONVERT DOUBLE INTO INTEGER
$phoneNo =intval($PhoneNo);
}
}
// VARIABLE TO INDICATE IF INPUT HAS 1 OR MORE ERROR
if ($ok=true) {
$conn = new PDO('mysql:host=ca-cdbr-az ure-centra l-a.clouda pp.net;dbn ame=abcdef ', 'abc', 'abc');
$conn->setAttribute(PDO::A TTR_ERRMOD E, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO uploadResume(fName,lName,e mail,Phone No,gender, resumeDoc) VALUES( :fNmame, :lName,:email,:PhoneNo, :gender,:resumeDoc);";
$cmd = $conn->prepare($sql);
$cmd->bindParam(':fName', $fName, PDO::PARAM_STR, 50);
$cmd->bindParam(':lName', $lName, PDO::PARAM_STR, 50);
$cmd->bindParam(':email', $email, PDO::PARAM_STR, 254);
$cmd->bindParam(':PhoneNo' , $PhoneNo, PDO::PARAM_INT);
$cmd->bindParam(':gender', $gender, PDO::PARAM_NULL);
$cmd->bindParam(':resumeDo c', $resumeDoc, PDO::PARAM_LOB);
$cmd->execute();
$conn = null;
echo 'Candidate Information Saved';
}
?>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Saving Data</title>
<a href="showDetails.php">Sho
</head>
<body>
<?php
$fName =$_POST['fName'];
$lName=$_POST['lName'];
$email=$_POST['email'];
$PhoneNo=$_POST['PhoneNo']
$gender=$_POST['gender'];
$resumeDoc = $_POST['resumeDoc'];
//VARIABLE TO INDICATE IF INPUT HAS 1 OR MORE ERROR
$ok=true;
//VALIDATE THE INPUTS
if(empty($fName)){
echo 'First Name is required <br />';
$ok=false;
}
if(empty($lName)){
echo 'Last Name is required <br />';
$ok=false;
}
if(empty($email)){
echo 'Email is required <br />';
$ok=false;
}
if(!empty($PhoneNo)) {
if ($PhoneNo < 1) {
echo 'Please Enter Valid Number';
$ok = false;
}
else{
// CONVERT DOUBLE INTO INTEGER
$phoneNo =intval($PhoneNo);
}
}
// VARIABLE TO INDICATE IF INPUT HAS 1 OR MORE ERROR
if ($ok=true) {
$conn = new PDO('mysql:host=ca-cdbr-az
$conn->setAttribute(PDO::A
$sql = "INSERT INTO uploadResume(fName,lName,e
$cmd = $conn->prepare($sql);
$cmd->bindParam(':fName', $fName, PDO::PARAM_STR, 50);
$cmd->bindParam(':lName', $lName, PDO::PARAM_STR, 50);
$cmd->bindParam(':email', $email, PDO::PARAM_STR, 254);
$cmd->bindParam(':PhoneNo'
$cmd->bindParam(':gender',
$cmd->bindParam(':resumeDo
$cmd->execute();
$conn = null;
echo 'Candidate Information Saved';
}
?>
</body>
</html>
ASKER
Am I doing something wrong with PDO??
I can't really tell. Why not try catching the PDO Exception and seeing what it says!
ASKER
It doesn't show any error
That's to be expected. You need to wrap the processes in try/catch blocks and catch the PDOException to find out what, if anything, is in the error message. As far as I can recall, all MySQL extensions work this way. They are silent about errors unless you make an affirmative effort to test the return values, and locate and display the error messages.
It's all shown in the (tested and working) code examples in the article.
It's all shown in the (tested and working) code examples in the article.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@hielo: Good catch. I think the if() statement will evaluate true after the assignment, so it's probably still running the query and then failing silently. I was hoping to lead the author to learning -- how to do the error visualization that is needed when things go wrong with PDO/MySQL.
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
If you're new to PHP and want to find dependable learning resources, this article can help. Just skip over the parts you already know from academics or work experience.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html