Digitry Designs Posted April 28, 2010 Share Posted April 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/ Share on other sites More sharing options...
JAY6390 Posted April 28, 2010 Share Posted April 28, 2010 mysqli_error($dbc) Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050151 Share on other sites More sharing options...
Digitry Designs Posted April 28, 2010 Author Share Posted April 28, 2010 mysqli_error($dbc) Thank you JAY. Unfortunately it does nothing more then parse what is already there before I add the mysqli_error($dbc) it just says MySQL Error: We are sorry, your email could not be sent at this time. Please try again in a few minutes Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050154 Share on other sites More sharing options...
JAY6390 Posted April 28, 2010 Share Posted April 28, 2010 Thats because you run the echo line BEFORE the query is run (ie before mysqli_query(...)) Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050156 Share on other sites More sharing options...
Digitry Designs Posted April 28, 2010 Author Share Posted April 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050160 Share on other sites More sharing options...
PFMaBiSmAd Posted April 28, 2010 Share Posted April 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050163 Share on other sites More sharing options...
JAY6390 Posted April 28, 2010 Share Posted April 28, 2010 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'); } Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050164 Share on other sites More sharing options...
Digitry Designs Posted April 28, 2010 Author Share Posted April 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050166 Share on other sites More sharing options...
JAY6390 Posted April 28, 2010 Share Posted April 28, 2010 set the field to auto increment http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050168 Share on other sites More sharing options...
Digitry Designs Posted April 28, 2010 Author Share Posted April 28, 2010 set the field to auto increment http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html Wow, Thank you so much JAY. that worked and helped alot!! I really appreciate the help! By the way, I have been looking, How do I mark this post resolved? Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050172 Share on other sites More sharing options...
JAY6390 Posted April 28, 2010 Share Posted April 28, 2010 Not sure, I've not created a thread myself Quote Link to comment https://forums.phpfreaks.com/topic/200085-how-do-i-add-mysql_error-to-my-code/#findComment-1050173 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.