croix Posted August 1, 2007 Share Posted August 1, 2007 I can never figure out how to properly echo or print my errors so I can find the problem. My form is not entering the information to the database, its not emailing the information, and its not redirecting to the page listed in the header. It seems like it just refreshes the page. can someone tell me a good way to find where the error is? I am trying to print the $message, but apparently Im not doing it right. I know its not the database connection, because I know how to test that, and i did at www.ridelube.com/dbtest.php <?php if (isset($_POST['name'])) { $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $fax = $_POST['fax']; $company = $_POST['company']; $address = $_POST['address']; $address2 = $_POST['address2']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $website = $_POST['website']; $type = $_POST['type']; $comment = $_POST['comment']; $msg = "Attention Ride Lubricant! You have a new vendor request!<br><br> Name = {$name} <br> Company = {$company}<br> Type = {$type} Address = {$address1}<br> Unit = {$address2}<br> City = {$city}<br> State = {$state}<br> Zip = {$zip}<br> Phone = {$phone}<br> Fax = {$fax}<br> Email = {$email} Website = {$website} Comment = {$comment}"; Enter_New_Entry($name,$email,$phone,$fax,$company,$address,$address2,$city,$state,$zip,$website,$type,$comment); //ini_set(SMTP, "smtp.ridelube.com"); ini_set(SMTP, "mail.ridelube.com"); ini_set(smtp_port, 25); ini_set(sendmail_from, "sales@ridelube.com"); $headers = "From: sales@ridelube.com\r\n"; $headers .= "BCC: dean@ridelube.com\r\n"; //mail(To, subject, content, header); $to = "sales@ridelube.com"; $result = mail($to, "New Ride Lube Vendor Request", $msg, $headers); if( $result == 0 ) { echo "error <br>"; } } function Enter_New_Entry ($name,$email,$phone,$fax,$company,$address,$address2,$city,$state,$zip,$website,$type,$comment) { $cnx = mysql_connect("localhost","********","*********"); if (!$cnx) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('***********', $cnx); if (!$db_selected) { die ('Can\'t use Records Database : ' . mysql_error()); } $SQL_Exec_String = "Insert Into clients (name, email, phone, fax, company, address, address2, city, state, zip, website, type, comment) Values ('$name', '$email', '$phone', '$fax', '$company', '$address', '$address2', '$city', '$state', '$zip', '$website', '$type', '$comment')"; $cur = mysql_query($SQL_Exec_String); if (!$cur) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } mysql_close($cnx); header("location: http://www.ridelube.com/verify.htm"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62851-echo-or-printing-an-error/ Share on other sites More sharing options...
pyrodude Posted August 1, 2007 Share Posted August 1, 2007 You may want to work on aligning your code to make it a little easier to follow and see where you're going. Also, I have to ask: Are you using post or get in your form? One thing you could do to debug it would be to add echo "testX<br />"; before, after, and inside every if statement, x being a number that you increment everytime (1, 2, 3, etc). This way, you can quickly go down the page and see which if statements are executing and which arent. If you chose to do this, you should comment out the header relocation so that you can see the results. Personally, I don't see what could be wrong, unless it's an issue with the values being passed from the form to the php page. Also, to shorten your code, you could change $cnx = mysql_connect("localhost","********","*********"); if (!$cnx) { die('Could not connect: ' . mysql_error()); } into $cnx = mysql_connect("localhost","********","*********") or die('Could not connect: ' . mysql_error()); And you could do the same thing with $db_selected. Quote Link to comment https://forums.phpfreaks.com/topic/62851-echo-or-printing-an-error/#findComment-312886 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.