Reputation: 15
Why PDO is not working in wamp ? I think my php is code is fine but I am not able to insert and get data from the MySQL database, how do I fix it ?
<?php
$db = new PDO('mysql:host=localhost;dbname=ajaxdata','root','');
$page = isset($_GET['p'])?$_GET['p']:'';
if($page=='add') {
$name = $_POST['nm'];
$email = $_POST['em'];
$phone = $_POST['pn'];
$address = $_POST['ad'];
$stmt = db->prepare("INSERT INTO info VALUES('',?,?,?,?)");
$stmt->bindParam(1,$name);
$stmt->bindParam(2,$email);
$stmt->bindParam(3,$phone);
$stmt->bindParam(4,$address);
if($stmt->execute()){
echo "Success add data";
} else {
echo "Fail add data";
}
} else if($page=='edit'){
} else if($page=='del'){
} else{
$stmt = $db->prepare("SELECT * FROM info");
$stmt->execute();
while($row = $stmt->fetch()){
?>
<tr>
<td><?php echo $row['id'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['email'] ?></td>
<td><?php echo $row['phone'] ?></td>
<td><?php echo $row['address'] ?></td>
<td>
<button class="btn btn-warning">Edit</button>
</td>
</tr>
<?php
}
}
?>
I don't know how to fix this error from wamp, so please tell me what to do.
Upvotes: 0
Views: 568