MYSQL returned an empty result set
Posted by: apples (---.clickptc.com)
Date: May 31, 2007 08:40PM

Bare with me, I've VERY new to PHP and any type of programing. I've created a form and then want the form to process the information into a database which I created in phpMyAdmin using WAMPSERVER.

When I test it, it echos exactly what it should, but at the end it tells me Insert Failed:

Customer Name: John Doe
Phone Number: 123-123-1234
Account Number: 84574738
Your information has been received and processed....Thank You!Insert Failed!!

When I check my database, it tells me MYSQL returned an empty result set. (duh...insert failed) Any ways, I can not figure out for the life of me what is wrong.

Here is my php file, can some one please help me...Like I said I really don't know anything about this stuff, someone helped me write this and now they're not available.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CUSTOMER FORM</title>
</head>

<body>

<?php

$customername = $_REQUEST["customer_name"];
$phonenumber = $_REQUEST["phone_number"];
$acctnumber = $_REQUEST["acct_number"];
$address = $_REQUEST["address"];
$city = $_REQUEST["city"];
$state = $_REQUEST["state"];
$zip = $_REQUEST["zip"];
$inter = $_REQUEST["inter_lata"];
$intra = $_REQUEST["intra_lata"];
$servicerep = $_REQUEST["service_rep"];

echo("Customer Name: " . $customername . "<br>"winking smiley;
echo("Phone Number: " . $phonenumber . "<br>"winking smiley;
echo("Account Number: " . $acctnumber . "<br>"winking smiley;
echo("Your information has been received and processed....Thank You!"winking smiley;

$db = mysql_connect("localhost", "root", ""winking smiley or die("Could Not Connect!"winking smiley;
mysql_select_db("longdistance",$db) or die("Could Not Select Database!"winking smiley;

$sql = "insert into mail_list (customer_name, phone_number, acct_number, address, city, state, zip, inter_lata, intra_lata, service_rep)";
$sql = $sql . " values ('" . $customername . "','" . $phonenumber . "','" . $acctnumber . "','" . $address . "','" . $city . "','" . $state . "','" . $zip . "','" . $inter . "','" . $intra . "','" . $servicerep . "')";

mysql_query($sql, $db) or die("Insert Failed!!"winking smiley;

?>

</body>
</html>

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: ZeZe (---.catv.broadband.hu)
Date: May 31, 2007 08:47PM

Try an
echo $sql;
before the query execution and check for syntax errors
if you find it ok, copy-paste into mysqladmin and see what happens



Post Edited (05-31-07 20:48)

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: ZeZe (---.catv.broadband.hu)
Date: May 31, 2007 08:50PM

Try this:

$sql = "insert into mail_list (customer_name, phone_number, acct_number, address, city, state, zip, inter_lata, intra_lata, service_rep) values ('$customername','$phonenumber','$acctnumber','$address','$city','$state','$zip','$inter','$intra','$servicerep')";

An insert may fail on data types and keys too.

May use mysql_error() in die() too.



Post Edited (05-31-07 20:52)

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: apples (---.clickptc.com)
Date: May 31, 2007 08:53PM

ok...now I get this...Does it mean anything, it doesn't to me..LOL

Customer Name: fadsfasd
Phone Number: fadssf
Account Number: fads
Your information has been received and processed....Thank You!insert into mail_list (customer_name, phone_number, acct_number, address, city, state, zip, inter_lata, intra_lata, service_rep) values ('fadsfasd','fadssf','fads','fadssfd','fads','','','','','')Insert Failed!!

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: ZeZe (---.catv.broadband.hu)
Date: May 31, 2007 09:03PM

Try

mysql_query($sql, $db) or die("<br>Error message: ".mysql_error());

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: CyberSpatium (71.237.217.---)
Date: May 31, 2007 09:19PM

ah, i see the problem. your cannot break your sql up, you need to keep it in one statement.

change to:
$sql = "insert into mail_list (customer_name, phone_number, acct_number, address, city, state, zip, inter_lata, intra_lata, service_rep) values ('" . $customername . "','" . $phonenumber . "','" . $acctnumber . "','" . $address . "','" . $city . "','" . $state . "','" . $zip . "','" . $inter . "','" . $intra . "','" . $servicerep . "')";


CyberSpatium
----------------------
WAMP English Forum Admin

Need help? Check out my WAMP User Manual/Guide here!


Cellular Phone Deals - The Best on the Net! - FREE PHONES! Take your pick from our featured cellular phone deals by Cingular, Verizon, T-Mobile, Sprint PCS, Nextel, and more! Most of our cellular phone offers include a FREE cellular phone with FREE shipping!


Web Development for Newbie's Blog - Check out my new blog. It is for web developers, and especially tailored for the web development newbie. If you are not fluent in “geek speak”, then this incredible resource is just you. And even if you are a web development pro, this is a great resource to check out some of the latest web development tips, news, tutorials, codes and more.


Mortgage and Home Loan Advice:
Clarify Loans

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: apples (---.clickptc.com)
Date: May 31, 2007 10:14PM

Neither of those options worked..

When I did what ZeZe suggested, I get:

Customer Name: fadsfs
Phone Number: fasd
Account Number: fdsa
Your information has been received and processed....Thank You!insert into mail_list (customer_name, phone_number, acct_number, address, city, state, zip, inter_lata, intra_lata, service_rep) values ('fadsfs','fasd','fdsa','fsd','','','','','','')
Error message: Table 'longdistance.mail_list' doesn't exist

AND

When I do what CyberSpatium suggested, I get:

Customer Name: n,sdfgdsanm/
Phone Number: fdslsajd
Account Number: kflds;sak
Your information has been received and processed....Thank You!insert into mail_list (customer_name, phone_number, acct_number, address, city, state, zip, inter_lata, intra_lata, service_rep) values ('n,sdfgdsanm/','fdslsajd','kflds;sak','','','','','','','')Insert Failed!

I also, tried both of these suggestions at the same time and didn't work

Thanks again for all your help

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: ZeZe (---.barossg-misk.sulinet.hu)
Date: June 01, 2007 12:56PM

Wll, you have the answer from mysql itself:

"Table 'longdistance.mail_list' doesn't exist"

Check again in phpmyadmin.

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: apples (---.clickptc.com)
Date: June 01, 2007 05:19PM

The table is there. My database is called longdistance and the table is called pld_customers. I have 11 fields:

1. id, Type=int, extra= auto_increment, primary=checked
2. customer_name, Type=varchar
3. phone_number, Type=varchar
4. acct_number, Type=varchar
5. address, Type=varchar
6. city, Type=varchar
7. state, Type=varchar
8. zip, Type=varchar
9. inter_lata, Type=varchar
10. intra_lata, Type=varchar
11. service_rep, Type=varchar

Null is set to no on all of these...

I've deleted the database and started over several times and get the same thing. I've tried labeling the table the same as the database.

In the php, where is it telling it to go to longdistance.mail_list? What am I missing in creating the table then...I did it last week no problem...Grrrr. I'm so sorry if I'm bugging you, but I really do appreciate you assistance.

Thanks

UPDATE: I tested my table inside of phhMyAdmin by inserting values inside of the table and when I went and browsed the table, the data is there, so that tells me it is something inside of the PHP.



Post Edited (06-01-07 18:24)

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: CyberSpatium (71.237.217.---)
Date: June 01, 2007 11:56PM

Here are some recent posts on my web development newbie blog that will help you.

Creating and Using a Database with MySQL
http://webdevnewbie.com/2007/06/01/creating-and-using-a-database-with-mysql/

PHP MySQL Tutorial
http://webdevnewbie.com/2007/05/06/php-mysql-tutorial/


CyberSpatium
----------------------
WAMP English Forum Admin

Need help? Check out my WAMP User Manual/Guide here!


Cellular Phone Deals - The Best on the Net! - FREE PHONES! Take your pick from our featured cellular phone deals by Cingular, Verizon, T-Mobile, Sprint PCS, Nextel, and more! Most of our cellular phone offers include a FREE cellular phone with FREE shipping!


Web Development for Newbie's Blog - Check out my new blog. It is for web developers, and especially tailored for the web development newbie. If you are not fluent in “geek speak”, then this incredible resource is just you. And even if you are a web development pro, this is a great resource to check out some of the latest web development tips, news, tutorials, codes and more.


Mortgage and Home Loan Advice:
Clarify Loans

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: apples (208.51.49.---)
Date: June 02, 2007 07:34AM

Thanks for the information. I'd already looked at these sites for assistance. So far alls I've figured out is it is something in the PHP because using the database inside of the wampserver works fine. GRRRRRR

Thanks again

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: CyberSpatium (71.237.217.---)
Date: June 02, 2007 07:23PM

wow apples, you are from waldport, i am from salem. hello neighbor smiling smiley

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: ZeZe (---.catv.broadband.hu)
Date: June 03, 2007 08:52AM

Cannot be, PHPMyAdmin uses the same PHP interpreter as your code. So, it should not prouduce different results, if coded properly.

Try this, see what you get:

<?php
$db = mysql_connect("localhost", "root", ""winking smiley or die("Could Not Connect: ".mysql_error());

mysql_select_db("longdistance",$db) or die("Could Not Select Database: ".mysql_error());

mysql_query("create table temp(field integer)"winking smiley or die("Could Not Create Table: ".mysql_error());

mysql_query("insert into temp(field) values(2007)"winking smiley or die("Could Not Insert: ".mysql_error());

mysql_query("select * from temp"winking smiley or die("Could Not Select: ".mysql_error());
?>

(do not break the code lines for now!)

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: apples (208.51.49.---)
Date: June 04, 2007 05:19AM

I will try this in the AM and let you know what happens! Thanks again!

CyberSpatium...what makes you think I'm from Waldport? smiling smiley

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: apples (---.clickptc.com)
Date: June 04, 2007 05:04PM

Ok...tried it this morning...this is what I got.

The first time I filled out the form, it worked. Then I did it again, and got:

Customer Name: Mickey Mouse
Phone Number: 1234
Account Number: 239854390
Your information has been received and processed....Thank You! Could Not Create Table: Table 'temp' already exists

Went into phpMyAdmin and went into the database, and a new temp table is created. Inside of the new table, there is no data received from the form and in red it says, No Indes defined!

Thanks again for all your help! smiling smiley

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: CyberSpatium (71.237.217.---)
Date: June 05, 2007 02:14AM

apples wrote:
>
> CyberSpatium...what makes you think I'm from Waldport? smiling smiley

your ip address:
[www.networldmap.com]

for your problem check out:
[www.tutorialcode.com]


CyberSpatium
----------------------
WAMP English Forum Admin

Need help? Check out my WAMP User Manual/Guide here!


Cellular Phone Deals - The Best on the Net! - FREE PHONES! Take your pick from our featured cellular phone deals by Cingular, Verizon, T-Mobile, Sprint PCS, Nextel, and more! Most of our cellular phone offers include a FREE cellular phone with FREE shipping!


Web Development for Newbie's Blog - Check out my new blog. It is for web developers, and especially tailored for the web development newbie. If you are not fluent in “geek speak”, then this incredible resource is just you. And even if you are a web development pro, this is a great resource to check out some of the latest web development tips, news, tutorials, codes and more.


Mortgage and Home Loan Advice:
Clarify Loans

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: apples (208.51.49.---)
Date: June 05, 2007 06:17AM

That is so weird....I've never heard of:
[www.networldmap.com]

Nobody can hide huh? LOL

Thanks for the tutorial link...unfortunately that is stuff I pretty much already knew. Like I said I'm new at this, but I did have this database working and then I changed just a few things and now boom, getting all these errors and can't figure out why.

I really appreciate this forum...it's great

Options: ReplyQuote
Re: MYSQL returned an empty result set
Posted by: CyberSpatium (71.237.217.---)
Date: June 06, 2007 12:04AM

here are some recent posts on my blog:

Creating and Using a Database with MySQL
http://webdevnewbie.com/2007/06/01/creating-and-using-a-database-with-mysql/

PHP MySQL Tutorial
http://webdevnewbie.com/2007/05/06/php-mysql-tutorial/

bookmark my blog, i add new tutorials all the time.

CyberSpatium
----------------------
WAMP English Forum Admin

Need help? Check out my WAMP User Manual/Guide here!


Cellular Phone Deals - The Best on the Net! - FREE PHONES! Take your pick from our featured cellular phone deals by Cingular, Verizon, T-Mobile, Sprint PCS, Nextel, and more! Most of our cellular phone offers include a FREE cellular phone with FREE shipping!


Web Development for Newbie's Blog - Check out my new blog. It is for web developers, and especially tailored for the web development newbie. If you are not fluent in “geek speak”, then this incredible resource is just you. And even if you are a web development pro, this is a great resource to check out some of the latest web development tips, news, tutorials, codes and more.


Mortgage and Home Loan Advice:
Clarify Loans

Options: ReplyQuote


Sorry, only registered users may post in this forum.