INSERT INTO table doesn't work???
Posted
by Joann
on Stack Overflow
See other posts from Stack Overflow
or by Joann
Published on 2010-05-08T10:19:38Z
Indexed on
2010/05/08
10:28 UTC
Read the original article
Hit count: 247
I found a tutorial from nettuts and it has a source code in it so tried implementing it in my site.. It is working now. However, it doesn't have a Registration system so I am making one. The thing is, as I have expected, my code is not working... It doesn't seem to know how to INSERT into the database. Here's the function that inserts data into the db.
function register_User($un, $email, $pwd) {
$query = "INSERT INTO users( username, password, email )
VALUES(:uname, :pwd, :email)
LIMIT 1";
if($stmt = $this->conn->prepare($query)) {
$stmt->bind_param(':uname', $un);
$stmt->bind_param(':pwd', $pwd);
$stmt->bind_param(':email', $email);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
} else return "The username or email you entered is already in
use...";
}
}
I have debugged the connection to the database from within the class, it says it's connected. I tried using this method instead:
function register($un, $email, $pwd)
{
$registerquery = $this->conn->query(
"INSERT INTO users(uername, password, email)
VALUES('".$un."', '".$pwd."', '".$email."')");
if($registerquery)
{
echo "<h4>Success</h4>";
}
else
{
echo "<h4>Error</h4>";
}
}
And it echos "Error"... Can you please help me pen point the error in this??? :(
© Stack Overflow or respective owner