Jump to content

echo or printing an error?


croix

Recommended Posts

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, "[email protected]");
$headers = "From: [email protected]\r\n";
$headers .= "BCC: [email protected]\r\n";
//mail(To, subject, content, header);
$to = "[email protected]";
$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"); 

}
?>

Link to comment
https://forums.phpfreaks.com/topic/62851-echo-or-printing-an-error/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.