Following is the code in which i tried to submit the form details to the mysql database in my cpanel of godaddy.
$nameErr = $emailErr = $phnoErr= "";
$name = $area = $address = $phno = $email = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("fecustomer", $con);
$name = $_POST["name"];
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
$area = $_POST["area"];
$address = $_POST["address"];
$phno = $_POST["phno"];
if (!preg_match("/^[0-9 ]*$/",$phno)) {
$phnoErr = "Only 10 digits allowed";
}
$email = $_POST["email"];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$query = "
INSERT INTO `fecustomer`.`details` (`name`, `area`, `address`, `email`,
`phno`, `timestamp`) VALUES ('$name','$area','address','phno'
'$email');";
mysql_query($query);
echo "<p>Thank you for your Comment!</p>";
mysql_close($con);
}
else
echo "dint insert";
?>
I have registered my domain and hosting in godaddy.i wanted to use the database in that itself.Have i udes the mysql of local wamp server.Are both different?what should i do.Thank you
As the error suggests, your mysql username and password is not correct and so, can not connect.
Your local database credentials and Godaddy credentials surely varies.
You will have to create a database admin first, then create a database. You will have to use these credentials in your code to fix the issue.
Go to MySQL Databases
section on your panel. Then Create A New Database
and Add An User
.
More details: https://in.godaddy.com/help/create-mysql-databases-16016
Use the credentials here:
$con = mysql_connect("localhost","your_username","your_password");