I have this code below that is working perfectly, but I would like to change it to work in PDO but I am having trouble registering with DB when I change it to the PDO.
It refers to errors
online143
and line 164
ThecodeinMysqlthatisworkingisthisbelow:
<?if(isset($_POST['enter'])){$nome=$_POST['nome'];$tel=$_POST['tel'];$cel=$_POST['cel'];$email=$_POST['email'];$plano=$_POST['plano'];$horas=$_POST['horas'];$prof=$_POST['prof'];$data=$_POST['data'];$tempo=date("dd/mm/YY His",time());
$sql = mysql_query("SELECT * FROM agendar WHERE data LIKE '".$data."' AND horas ='".$horas."' AND prof = '".$prof."'");
if(mysql_num_rows($sql)>=1){
echo "<meta http-equiv='refresh' content='0; URL= http://www.rfclinica.com.br/index.php'>
<script type=\"text/javascript\">
alert(\"Esta data e hora já esta agendada para esse Profissional! Tente com outro Profissional ou outra data e hora! Obrigado!!!\");</script>";
return die;
}else{
$inserir = mysql_query("INSERT INTO agendar (nome, tel, cel, email, plano, prof, data, horas) VALUES ('$nome', '$tel', '$cel', '$email', '$plano', '$prof', '$data', '$horas')");
if($inserir == ''){
echo "<script language='javascript'>
window.alert('Ocorreu um erro ao Agendar sua Avaliaço!');
</script>";
}else{
echo "<script language='javascript'>
window.alert('Avaliação Agendada com sucesso!');
</script>";
}}}?>
And the modification to work with PDO looks like this:
<?php if(isset($_POST['enter'])){
$nome = $_POST['nome'];
$tel = $_POST['tel'];
$cel = $_POST['cel'];
$email = $_POST['email'];
$plano = $_POST['plano'];
$horas = $_POST['horas'];
$prof = $_POST['prof'];
$data = $_POST['data'];
$tempo = date("dd/mm/YY His",time());
$pdo = new PDO('mysql:host=localhost;dbname=site', "root", "");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if( $pdo->query("SELECT count(*) FROM agendar WHERE prof = '{$prof}'")->fetchColumn() <=0) {
$stmt = $pdo->prepare("SELECT * FROM agendar WHERE data LIKE '".$data."' AND horas ='".$horas."' AND prof = '".$prof."'");
if(mysql_num_rows($sql)>=1){
echo "<meta http-equiv='refresh' content='0; URL= agenda.php'>
<script type=\"text/javascript\">
alert(\"Esta data e hora já esta agendada para esse Profissional! Tente com outro Profissional ou outra data e hora! Obrigado!!!\");</script>";
return die;
}else{
$stmt = $pdo->prepare ('INSERT INTO agendar (nome, tel, cel, email, plano, prof, data, tempo)
VALUES (:nome, :tel, :cel, :email, :plano, :prof, :data, :tempo)');
$stmt->execute(array(':nome' => $nome,
':tel' => $tel,
':cel' => $cel,
':email' => $email,
':plano' => $plano,
':prof' => $prof,
':data' => $data,
':tempo' => date("dd/mm/YY His",time())
));
if($inserir == ''){
echo "<script language='javascript'>
window.alert('Ocorreu um erro ao Agendar sua Avaliaço!');
</script>";
}else{
echo "<script language='javascript'>
window.alert('Avaliação Agendada com sucesso!');
</script>";
}}}}
?>
My question is whether I'm making the change to PDO correctly, and would like the help of friends to find out where I'm going wrong. Thank you in advance for the attention of friends. Hugs to all!