MySQL query is getting denied

Posted on 2012-04-02
Last Modified: 2012-06-21
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.
Question by:InquisitiveProgrammer
  • 2

Expert Comment

ID: 37797384
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')

Author Comment

ID: 37797401
I tried that and still no change.

Author Comment

ID: 37797430
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
LVL 83

Accepted Solution

Dave Baldwin earned 500 total points
ID: 37797451
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');

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySql hide the stored procedures 2 40
PHP preg_replace code convert to Delphi 14 36
How to loop through records  using SELET COUNT 2 16
ebay table structure 2 14
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now