Jump to content

Archived

This topic is now archived and is closed to further replies.

dark_destroyer

Incorrect Database Name

Recommended Posts

Hi all,

This is my first post so please forgive any glaringly obvious mistakes!!

I have a simple form that allows a user to enter Name, Telephone number, Company Name and a short message, i want this to then write to a MySQL database but when I click my submit button i get this error returned, even though i know for sure that I am using the correct database.

Error Message Returned:

Connected
Incorrect database name 'insert into log (name1,name2,company, telephone, message) values ('','','','','')'

Here is teh code that i am using:

<?php
$_REQUEST["Name1"] . " was used.";
$_REQUEST["Name2"] . " was used.";
$_REQUEST["Company"] . " was used.";
$_REQUEST["Telephone"] . " was used.";
$_REQUEST["Message"] . " was used.";

$_Name1 = $_REQUEST["Name1"];
$_Name2 = $_REQUEST["Name2"];
$_Company = $_REQUEST["Company"];
$_Telephone = $_REQUEST["Telephone"];
$_Message = $_REQUEST["Message"];

$link = mysql_connect('localhost', 'root', 'password') or die(mysql_error());
mysql_select_db("messages") or die(mysql_error());
echo "<b>Connected<br>";

$query = ("insert into log (Name1,Name2,Company, Telephone, Message) VALUES ('$_POST[Name1]','$_POST[Name2]','$_POST[Company]','$_POST[Telephone]','$_POST[Message]')");
if(!mysql_db_query($query,$link)) die(mysql_error());
echo "success in database entry.";

?>

Can anyone point out what I an doing wrong, im not really sure what else to try!!!!

Thanks in Advance

Share this post


Link to post
Share on other sites
Hi

I'm a newbie too - so lets hope in not talking rubbish here!

Problem is with the names of the arrays not being in strings: try esacping the names of the arrays using \"

$query = ("insert into log (Name1,Name2,Company, Telephone, Message) VALUES ('$_POST[\"Name1\"]','$_POST[\"Name2\"]','$_POST[\"Company\"]','$_POST[\"Telephone\"]','$_POST[\"Message\"]')");

Maybe that will work...

good luck

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.