Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL query is getting denied

Posted on 2012-04-02
4
Medium Priority
?
262 Views
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?

<HTML>

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

</HEAD>

<BODY>

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

<?php
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';
}

}

?>

</BODY>

</HTML>

Open in new window


My variables are being output correctly via the echo methods I used to test.
0
Comment
Question by:InquisitiveProgrammer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Philippe Damerval
ID: 37797384
Hi,
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:

INSERT INTO `Account` VALUES "
      . " ('123', '$name', '$address', '$phone')
0
 
LVL 1

Author Comment

by:InquisitiveProgrammer
ID: 37797401
I tried that and still no change.
0
 
LVL 1

Author Comment

by:InquisitiveProgrammer
ID: 37797430
This is the output I get from my program:

Successful connection to MySQL
Lefler, Jay
1145 Running
8137587733
INSERT INTO `Account` VALUES ('123', 'Lefler, Jay', '1145 Running', '8137587733')
Unable to add rows
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 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');
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 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