Current location: Hot Scripts Forums » Programming Languages » PHP » Problems with Define Function


Problems with Define Function

Reply
  #1 (permalink)  
Old 01-30-05, 12:44 PM
1jetsam 1jetsam is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Problems with Define Function

I am using the define function to use as a prefix to database tables.
PHP Code:

define('SQL_PREFIX',''); 

Currently it is set to nothing, but it this database were to be shared with another program, you'd use something like "myprefix_".

Now here is the problem:
PHP Code:

$query "INSERT INTO " .SQL_PREFIX"user(user_username, user_password, user_type)

VALUES ('" 
.$_POST['username']. "', '" .$_POST['password']. "', 'admin');";
$result mysql_query($query) or die(mysql_error()); 
And here is the error it turns out with:
PHP Code:

You have an error in your SQL syntaxCheck the manual that corresponds to your MySQL server version for the right syntax to use near 'user(user_username, user_password, user_type) VALUES ('myusername 

This is really annoying me, and I'd like for it to work. Could someone come up with some solution, or tell me whats wrong.
__________________
Quate CMS 0.3.3 Released - A simple, fast Content Management System.
Reply With Quote
  #2 (permalink)  
Old 01-30-05, 06:04 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
put a space between the table name and the fields! and remove the semicolon from the statment
PHP Code:

$query "INSERT INTO " .SQL_PREFIX"user (user_username, user_password, user_type)

VALUES ('" 
.$_POST['username']. "', '" .$_POST['password']. "', 'admin')"
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 01-30-05, 07:40 PM
1jetsam 1jetsam is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Ok that helps. It works now.

What I don't get is why that same code (without the prefix feature) worked before...

It doesn't matter.
Thanks again!
__________________
Quate CMS 0.3.3 Released - A simple, fast Content Management System.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with function Taishinsei PHP 5 08-22-04 03:07 PM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 10:15 AM
accessing existing ISP email with a PHP webmail script. nlancaster PHP 1 01-07-04 03:28 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 05:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.