afridy
1
Hi all,
strange. i spent hours and hours. i cant find what’s wrong with this code.
$query="INSERT
INTO users
SET
full_name=:full_name,
user_role=:user_role,
user_name=:user_name,
password=:password";
$stmt->execute(array(':full_name' => $full_name,
':user_role' => $user_role,
':user_name' => $user_name,
':password' => $password));
$affected_rows = $stmt->rowCount();
if($affected_rows<1){
echo "<div class='alert alert-danger'>Record adding Failed.</div>";
}else{
echo "<div class='alert alert-success'>Record Added Successfully.</div>";
}
$db->connection = null;
The posted code isn’t preparing the sql query statement.
2 Likes
I miss a
$stmt = $connection->prepare($query)
Also I am not sure that you should use the double point in the array.
2 Likes
afridy
4
Please find the full code
$full_name=$_GET['full_name'];
if($full_name==''){
echo "<div class='alert alert-danger' role='alert'>Please enter Full Name.</div>";
exit;
}
$user_role=$_GET['user_role'];
if($user_role=='0'){
echo "<div class='alert alert-danger' role='alert'>Please select user role.</div>";
exit;
}
$user_name=$_GET['user_name'];
if($user_name==''){
echo "<div class='alert alert-danger' role='alert'>Please enter User Name.</div>";
exit;
}
//check for duplicate username//
$query="SELECT count('user_name') as tot
FROM users
WHERE user_name=:user_name";
$stmt = $db->prepare($query);
$stmt->execute(array(':user_name' => $user_name));
$row = $stmt->fetch();
if($row['tot']>0){
echo "<div class='alert alert-danger'><strong>Failed!</strong>Username Already Exist.</div>" . "<br>";
exit;
}
//
$password=$_GET['password'];
if($user_name==''){
echo "<div class='alert alert-danger' role='alert'>Please enter password.</div>";
exit;
}
$query="INSERT
INTO users
SET
full_name=:full_name,
user_role=:user_role,
user_name=:user_name,
password=:password";
$stmt->execute(array(':full_name' => $full_name,
':user_role' => $user_role,
':user_name' => $user_name,
':password' => $password));
$affected_rows = $stmt->rowCount();
if($affected_rows<1){
echo "<div class='alert alert-danger'>Record adding Failed.</div>";
}else{
echo "<div class='alert alert-success'>Record Added Successfully.</div>";
}
$db->connection = null;
?>
afridy
5
Thank you buddy. yep i have some how missed this line.
it works!!
system
Closed
6
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.