Quantcast
Channel: WampServer - WampServer English
Viewing all articles
Browse latest Browse all 3177

Error connecting to database (1 reply)

$
0
0
Hi,

Thanks again for the help getting WAMP running. I wrote a PHP script for to insert data into into Mariadb, and unfortunately it is not connecting. I have a an if statement in my code using mysqli_connect_errno() to check for errors, and when I run the script, mysqli_connect_errno() triggers the if statement and yields the value 2002. Here is the full script of the file:

<?php

// Extract HTML variable values
$fName = $_POST['fName'];
$lName = $_POST['lName'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$ccnumber = $_POST['ccnumber'];
$cardtype = $_POST['cardtype'];
$expmonth = $_POST['expmonth'];
$expyear = $_POST['expyear'];
$sc = $_POST['sc'];
$email = $_POST['email'];
$phonenumber = $_POST['phonenumber'];
$username= $_POST['username'];
$pwd1 = $_POST['pwd1'];
$pwd2 = $_POST['pwd2'];

// Verify passwords
if ($pwd1 != $pwd2)
{
echo "<h1>The passwords did not match. Please <a href=\"createaccount.htm\">try again.</a></h1>";
exit;
}

// Connect to database
@ $db = new mysqli('localhost', 'user', 'password', 'database');
$error = mysqli_connect_errno();

if ($error)
{
echo 'Error '.$error.'. Could not connect to database. Please try again later.';
exit;
}

// Insert values into database
$query = "INSERT INTO ebazaar VALUES ('".$fName."', '".$lName."', '".$address."', '".$city."', '".$state."', '".$zip."', '".$ccnumber."',
'".$cardtype."', '".$expmonth."', '".$expyear."', '".$sc."', '".$email."', '".$phonenumber."', '".$username."', '".$pwd1."', '".$pwd2."')";
$result= $db->query($query);

// Output results to user
if ($result)
{
echo "Congratulations. Account created!";
}
else
{
echo "An error has occurred. The account was not created.";
}

$db->close();

?>



Any solutions?

Viewing all articles
Browse latest Browse all 3177

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>