12-06-2007, 05:21 PM
|
#32 (permalink)
|
|
The Wanderer
Join Date: Dec 2007
Posts: 22
Thanks: 4
|
Quote:
Originally Posted by SOCK
Backtracking a bit. I didn't notice this before, but it seems fairly obvious.
PHP Code:
// Connect to db
$db = new mysqli ('localhost', 'user', 'pass', 'dir', 'address', 'phone', 'email');
// Cant connect to db
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database.';
exit;
}
What's with your connect statement?
Now an interesting question comes up. Why, if the connect statement looks so strange it doesn't exit the script when it hits the conditional block with the call to mysqli_connect_errno()? Well, one possible reason might be that it throws anything but a '1' or TRUE and so the conditional is skipped over. A better way to perform that would be something like this:
PHP Code:
// check to see if it throws ANYTHING but zero
if ( mysqli_connect_errno() !=0 ) {
// an error occurred, exit
}
See the difference? Your conditional actually tests for TRUE. The function doesn't return TRUE. It returns 0 (if it's a good connection) or an error code.
|
I see what you're saying. I've gone ahead and made the change, but I still get the same error. I was reading that this might actually be a bug? I don't know how reliable the web site was though(Can't remember the url any more).
Someone mentioned that the max of values was 6 so I took one out just to test it out and it still gave me the same error. I also went ahead and gave the INSERT INTO table a different name and strangely enough I got the same error
PHP Code:
// Preparing to add customer
$stmt = $db->prepare("INSERT INTO ybh305_clients(user,pass,dir,address,phone,email) VALUES(?,?,?,?,?,?)");
In phpMyAdmin, the table is called ybh305_clients, at least thats what it shows from the drop down menu. I have tried, clients and ybh305_clients and it still gives me the same error.
__________________
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
|
|
|
|