Here is my code:
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$method = $_POST["method"]; //dropdown box
$category = $_POST["category"]; //dropdown box
$email = mysql_real_escape_string($_POST["email"]);
$companyname = mysql_real_escape_string($_POST["companyname"]);
$phone = mysql_real_escape_string($_POST["phone"]);
$address = mysql_real_escape_string($_POST["address"]);
$state = mysql_real_escape_string($_POST["state"]);
$zip = mysql_real_escape_string($_POST["zip"]);
$salt = $email;
$length = 10;
$temporarypassword =
substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
0, $length);
$temp_encrypted_password = sha1($salt.$temporarypassword);
$addcompany = mysql_query("INSERT INTO company (`method`, `category`,
`email`, `password`, `companyname`, `phone`, `address`, `state`, `zip`, `ratingcount`,
`ratingscore`, `usage`, `date`)
VALUES
('$method','$category','$email','$temp_encrypted_password',
'$companyname','$phone','$address','$state','$zip','0','0','0',CURDATE()) ")
or die(mysql_error());
if (mysql_fetch_array($addcompany)) {
$to = "$email";
$subject = "Your Temporary Password";
$message = "Your temporary password is: <b>$temporarypassword;</b>. Sign in and
update your password as soon as possible.";
$header = "From: email@gmail.com\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
mail($to,$subject,$message,$header);
$message = "Company Added";
}
}
}
So, the sql statement executes just fine and is entered into my database just as I want it. However, the IF statement for if $addcompany returns true must be returning false, because nothing inside the statement executes. I use this check for mysql_fetch_array this way on other parts of my site and it works fine so I’m curious as to why it isn’t returning in this case.
FYI I’m looking into PDO for those who will say it. lol I already got reamed for it on a previous post today.
Thanks for your time, I appreciate it.
The php-doku declares, that for all INSERT-statements mysql_query returns a boolean, whether the statement was successfully executed.
So you don’t need to
But simply