Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
Pyro In A Cage
- Forum Newbie
- Posts: 10
- Joined: Mon Jul 17, 2006 4:27 pm
Post
by Pyro In A Cage »
I don't get an error when running this query, but when I look in phpmyadmin, the data that should have been inserted is not there.
Code: Select all
$db = mysql_connect($db_host, $db_user, $db_pass); //Connect to the database
mysql_select_db($db_table_auths,$db); //Select the table
$query = ( 'INSERT INTO'.$db_name.' (code, user, admin) VALUES ("'.$auth_code.'", "'.$_POST['user'].'", "'.$_session['user'].'")' ); //Define the query
$result = mysql_query($sql); //Execute the query
Yes, all of the variables have the right values.
-
Burrito
- Spockulator
- Posts: 4715
- Joined: Wed Feb 04, 2004 8:15 pm
- Location: Eden, Utah
Post
by Burrito »
it looks like you need a space after 'INTO' in your sql query.
try echoing out query to make sure it is what you think it is.
also add a die after you mysql_query to ensure that it really isn't throwing an error.
ex:
Code: Select all
mysql_query($query)
or die(mysql_error());
-
Benjamin
- Site Administrator
- Posts: 6935
- Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin »
Shouldn't that be table name? Echo $query and post it please.
-
Burrito
- Spockulator
- Posts: 4715
- Joined: Wed Feb 04, 2004 8:15 pm
- Location: Eden, Utah
Post
by Burrito »
astions wrote:Shouldn't that be table name? Echo $query and post it please.
I thought that as well then noticed this above:
Code: Select all
mysql_select_db($db_table_auths,$db); //Select the table
I think he's just using some odd (as far as nomenclature) var names.
-
Benjamin
- Site Administrator
- Posts: 6935
- Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin »
Yes, it does look like the table and database variables need to be swapped.
Well here it is cleaned up a little bit, still might need to be fixed though..
Code: Select all
$db = mysql_connect($db_host, $db_user, $db_pass); //Connect to the database
mysql_select_db($db_table_auths,$db); //Select the table
$query = ( 'INSERT INTO `' . $db_name . '` (code, user, admin) VALUES ("' . $auth_code . '", "' . mysql_real_escape_string($_POST['user']) . '", "' . mysql_real_escape_string($_session['user']) . '")' ); //Define the query
$result = mysql_query($sql) or die(mysql_error()); //Execute the query
-
Pyro In A Cage
- Forum Newbie
- Posts: 10
- Joined: Mon Jul 17, 2006 4:27 pm
Post
by Pyro In A Cage »
Damn you guys are fast...
I echoed query, and there was nothing there. It did give an error: "Query was empty".
Wtf?
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 »
that's my most common mistake,don't feel bad