Jump to content

how do I add mysql_error() to my code


Digitry Designs

Recommended Posts

hello and thank you again for reading.

 

Here is my problem. I am trying to connect to the database and post information from a form. It doesnt seem to be working. I have logged into my db and verified db name and table name is correct. I have verified the password is correct. Another person here suggested to add "mysql_error()" to the "or die" statement. how do I do this. I guess what I am asking is what would it look like? I googled the issue and came up with one solution that shows the mysql_error statement to go immediately after the table insert statement like this:

 

$query = "INSERT INTO mail (name, organization, phone, email, description) " .
"VALUES ('$name', '$organization', '$phone', '$email', '$description')";
echo "MySQL Error:" . mysqli_error();

 

 

I am afraid this is incorrect because I get this:

 

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\digitrydesigns\templates\pro\include\process_mail.php  on line 14

MySQL Error:We are sorry, your email could not be sent at this time. Please try again in a few minutes

 

This is the entire code:

<?php

$name = $_POST['name'];
$organization = $_POST['organization'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$description = $_POST['description'];

$dbc = mysqli_connect('localhost', 'root', 'nuv1420', 'digitry')
or die('We are sorry, due to extensive server overload we were unable to process your mail.');

$query = "INSERT INTO mail (name, organization, phone, email, description) " .
"VALUES ('$name', '$organization', '$phone', '$email', '$description')";
echo "MySQL Error:" . mysqli_error();

$result = mysqli_query($dbc,$query) 
or die('We are sorry, your email could not be sent at this time. Please try again in a few minutes');


mysqli_close($dbc);

echo '<meta HTTP-EQUIV="REFRESH" content="0; url=../admin/digitrycms_panel.php">';

?>

 

Can someone please help me out. I really appreciate it in advance. Thank you.

Link to comment
Share on other sites

Thats because you run the echo line BEFORE the query is run (ie before mysqli_query(...))

 

Ok, so where would I put it exactly? If I put it in between the query and the or die statement, I get syntax error. If I put it after the or die statement, it doesnt run because the code stops at or die and parses the custom error?

Link to comment
Share on other sites

A... person here suggested to add "mysql_error()" to the "or die" statement.

 

That would imply that you change the "or die" statement so that it also contains a mysqli_error().

 

You have two "or die()" statements. Which one are you receiving the output from, that you need to troubleshoot?

Link to comment
Share on other sites

You can just add it to the die statement, or do the error handling the traditional way of


$result = mysqli_query($dbc,$query);
if(!$result) {
    echo "MySQL Error:" . mysqli_error($dbc);
    die('We are sorry, your email could not be sent at this time. Please try again in a few minutes');
}

Link to comment
Share on other sites

A... person here suggested to add "mysql_error()" to the "or die" statement.

 

That would imply that you change the "or die" statement so that it also contains a mysqli_error().

 

You have two "or die()" statements. Which one are you receiving the output from, that you need to troubleshoot?

 

ok, I got it fixed. I is the query statement, not the connect statement.

 

Well not fixed, I got the error. The error is:

 

MYSQL ERROR: Duplicate entry '0' for key 'PRIMARY'

 

How do I ascend the id number?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.