Solved

MySQL query is getting denied

Posted on 2012-04-02
4
258 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
  • 2
4 Comments
 
LVL 9

Expert Comment

by: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 83

Accepted Solution

by:
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');
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do uses indexes to maximize MySQL Searches 14 55
MySQL Backup Strategy 15 44
PHP and JQuery Syntax question 4 26
Ajax and PHP 9 29
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
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 …

809 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