Forum Moderators: coopster

Message Too Old, No Replies

MySQL problem

my last great hurdle (for now)

         

too much information

2:35 am on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just don't get it, I have searched everywhere and can not find what I am doing wrong. I am familiar with SQL, but I typically use ASP, Access so this MySQL thing is very new. Here's my attempt at inserting data into the database:

// Connection Strings
$username = "-------";
$password = "-------";
$hostname = "localhost";
$dbConnect = mysql_connect($hostname, $username, $password) or die("Unable to connect to the Database, please try again.");
mysql_select_db("database1") or die(mysql_error());
$theSQL = "insert into table (Item1, Item2, Item3) values ";
$theSQL = $theSQL."('".$Item1."','".$Item2."','".$Item3."')"
mysql_query($theSQL, $dbConnect) or die(mysql_error());

I know my connection is good, the problem is with the mysql_query line. I've tried it with and without the $dbConnect and neither works. What am I doing wrong?

too much information

5:26 am on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So it must be Friday... (I have done some really goofy stuff today)

The problem wasn't with my connection, or the query, the problem was that I left out a ';' in the next line that printed the confirmation.

This ';' thing is going to be the hardest thing to remember.

NickCoons

7:10 am on Feb 19, 2005 (gmt 0)

10+ Year Member



One thing that you may also want to try, for readability, is to change this line:

$theSQL = $theSQL."('".$Item1."','".$Item2."','".$Item3."')";

To this:

$theSQL .= "('".$Item1."','".$Item2."','".$Item3."')";

Functionally, it does the same thing. But to me, the latter is easier to read.

hakre

7:21 am on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



congrats too much information to switch over to php. you can do a lot more stuff with php then asp i can tell you! keep on learning you'll love it.