Hello

How do i know if an insert query was done?...im doing...

$sql = "INSERT INTO db(table) VALUES('$value')";
or die = print = "There was an Error";

of course...or die..doesnt work...what can i do?

Comments

saepl’s picture

jaydubb181’s picture

You should be using the Database abstraction layer: http://api.drupal.org/api/group/database/6 . The db_query function: http://api.drupal.org/api/function/db_query/6 returns a boolean false if there was an error executing the query.

So something like:

$result = db_query("INSERT INTO {table} set name='%s'", $user->name);

//then test to see if result is false, if it is, print an error message
if ($result != FALSE) {
drupal_set_message("There was an error with the query. ","error");
}

saepl’s picture

@studley181

Did you really mean to say

if ($result ! = FALSE) {

Shouldn't it be

if ($result == FALSE) {

?

lucasvm’s picture

thank you for your explain...im trying to do this:

[PHP]
$total = db_result(db_query('SELECT * FROM users WHERE users.name='.$login));
if ($total > 0 ) {
print "The user '.$login.' exists" codigo="0"/>';
}
else{
$sql = "INSERT INTO users(uid,pass,mail) VALUES('$login','$password','$mail')";
$result = db_query($sql);
if ($result == FALSE) {
prnt "There was an error";
} else {
print "The query was ok";
}
[/PHP]

Im always getting there was an error and tne insert into doesnt work....what im doing wrong?

saepl’s picture

Does the comment on this page help you?

http://api.drupal.org/api/function/user_authenticate

jaydubb181’s picture

Right, that's what I meant.