MySQL query is getting denied

My query is not being successfully added to my database table. Can someone please tell me where I am going wrong in my code?


<HEAD><TITLE>Florida Pet Clinics Inc.</TITLE>



<H1 ALIGN="CENTER">Florida Pet Clinics Inc. </H1>

define("MYSQLUSER", "???");
define("MYSQLPASS", "???");
define("HOSTNAME", "???");

$connection = @new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS);
if ($connection->connect_error) {
	die('Connect Error: ' . $connection->connect_error);
} else {
	echo 'Successful connection to MySQL<br>';

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address = $_POST['address'];
$phone = $_POST['phone'];

$name = $last_name . ', ' . $first_name;

echo $name . '<br>';
echo $address . '<br>';
echo $phone . '<br>';

$query = "INSERT INTO 'Account' VALUES "
	. " ('123', '$name', '$address', '$phone')";

if (!$result = $connection->query($query)) {
	echo 'Unable to add rows';
else {
	echo 'Row successfully added';





Open in new window

My variables are being output correctly via the echo methods I used to test.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Philippe DamervalSenior Analyst ProgrammerCommented:
I may be wrong, but it seems you are using single quotes (' ' ) instead of the MySQL database object quote character  (` `) which is right on top of the TAB key on US keyboards.
Your insert should read:

      . " ('123', '$name', '$address', '$phone')
InquisitiveProgrammerAuthor Commented:
I tried that and still no change.
InquisitiveProgrammerAuthor Commented:
This is the output I get from my program:

Successful connection to MySQL
Lefler, Jay
1145 Running
INSERT INTO `Account` VALUES ('123', 'Lefler, Jay', '1145 Running', '8137587733')
Unable to add rows
Dave BaldwinFixer of ProblemsCommented:
You haven't selected a database.  The fourth parameter should be the name of your database.  And when you are still trying to get it working, you should not be putting the '@' in there to suppress error messages that would tell if something was wrong.

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.