Help - Search - Members - Calendar
Full Version: Php Sql Query Syntax
Zymic Webmaster Forums > Zymic Free Web Hosting > Databases & MySQL
howbya
Howdy,
I'm a two day old php/mysql user. I'm trying to write a simple INSERT script. I don't receive any errors, however the query fails. I've tried many different forms of the query but haven't found the one that works. SELECT query works fine. My code is next and below is the output I receive. Any advice is appreciated.
Thanks
Dougman


<?php

include 'library/config.php'; //db account info
include 'library/opendb.php'; //assigns $dbhandle with mysql_connect

$dbquery = "INSERT INTO 'USERS' (userID,email,pass) VALUES ('coded1', 'code@code.com', 'pswd')";

$dbresult = mysql_query ($dbquery, $dbhandle);

if ($dbresult == false)
{
echo "Unable to to perform query<br>";
}

$dbquery = "SELECT * FROM `USERS` LIMIT 0, 30 ";
$dbresult = mysql_query ($dbquery, $dbhandle);

while ($dbrow = mysql_fetch_array($dbresult, MYSQL_ASSOC))
{
print_r($dbrow);
echo '<br>';
}

mysql_close($dbhandle);
?>

*************************************************

Unable to to perform query
Array ( [userID] => manual [email] => crap [pass] => pass )
Array ( [userID] => user2 [email] => email3@email.com [pass] => password2 )
Array ( [userID] => user3 [email] => email3@email.com [pass] => password3 )
Array ( [userID] => hahahha [email] => hahhaha [pass] => hahahaha )
Array ( [userID] => jajja [email] => kakakak [pass] => kakakak )
Array ( [userID] => tripp [email] => ha@ha.com [pass] => password )
swordz
You should be delimiting the field/table names.

$dbquery = "INSERT INTO `USERS` (`userID`,`email`,`pass`) VALUES ('coded1', 'code@code.com', 'pswd')";

` are for table/field names.
' are for data to be entered.

swordz
howbya
huh.gif Wow, I didn't even know those were different characters.

Thanks!!!
Dougman cool.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.