0

I try to insert a row to my DB table as follows:

$selected = mysqli_select_db($link, $db_name);
if(!$selected){
    $mail_Subject = 'Error in selecting DB: ' . mysqli_error($link);        
    mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
    mysqli_close($link);
    exit;
}

// Add the line to the database!
if(!mysqli_query("INSERT INTO tokens (user_id, user_name, transaction_id, token_type, token_meta, date) VALUES ('-3', 'nisui2', 'blabla2', '111', '111 meta', '');")){
    $mail_Subject = 'Error in insertion: ' . mysqli_error($link);       
    mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
    mysqli_close($link);
    exit;
}    

From some reason I get an email with the subject "Error in insertion:", with no error details.

Can you spot what am I doing wrong?

Also, can you tell me a way to debug this? (how can I know what the problem was?)

3
  • 2
    You're using mysqli - but there's only one argument !?!? And you're mixing mysql_ and mysqli - that's not going to work Commented Jan 12, 2014 at 1:52
  • I changed it according to what you said. Thanks. Commented Jan 12, 2014 at 2:18
  • What happens when you enter that query directly into the mysql console? Commented Jan 12, 2014 at 4:36

2 Answers 2

2

You'r selecting the Database with "mysql_select_db" but you'r querying with msqli

try

   $selected = mysqli_select_db($db_name, $link); 
Sign up to request clarification or add additional context in comments.

3 Comments

I changed it, but still I get the Error in insertion. Do you know how can I know what is the concrete error?
try "mysqli_error($link)", did you made the database connection with $link = mysqli_connect ?
yes, $link is the connection to db. I did change it, still doesn't work... (and doesn't give error info)
1

Add $link as first parameter to your call:

mysqli_query($link, $query [, $resultmode])

mysqli_query($link, "INSERT …");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.