Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-27-2003, 02:18 AM   #1 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
whats wrong with this line?

hey, i've been playing around with this for hours:

PHP Code:
$query "UPDATE 'users' SET 'age' = '$age' WHERE 'username' = '$username'"
thanks
trevor is offline   Reply With Quote
Old 11-27-2003, 07:33 AM   #2 (permalink)
Nitro
Registered User
 
Nitro's Avatar
 
Join Date: Jun 2003
Location: London, England
Posts: 29
Nitro is on a distinguished road
Send a message via AIM to Nitro
Ok, the problem is that you are using '', e.g. 'users', 'age', '$age'. You dont need to do this, however if you want to, you are supposed to use the back tick(`), found to the left of your '1' key.

PHP Code:
$query "UPDATE `users` SET `age` = `$age` WHERE `username` = `$username`"
PHP Code:
$query "UPDATE users SET age = $age WHERE username = $username"
Both of those will work. Personally, I dont use anything like in the second example, but it's your preference. Hope this helps,
Nitro is offline   Reply With Quote
Old 11-27-2003, 09:19 AM   #3 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
wtf are you talking about?

you're supposed to quote your strings, but not identifiers.

PHP Code:
$query "UPDATE users SET age='$age' WHERE username='$username'"
joe_bruin is offline   Reply With Quote
Old 11-27-2003, 09:24 AM   #4 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Nitro - actually you're only half correct. You would need single quotes around a string you want to compare, e.g.
PHP Code:
$sql "SELECT * FROM table WHERE name = '$username'";

// or
$sql "SELECT * FROM table WHERE name = 'bdl'"
The `backtick` only works for selecting column names, not values. You must use single quotes.
bdl is offline   Reply With Quote
Old 11-27-2003, 09:27 AM   #5 (permalink)
bdl
Senior Contributor
 
Join Date: May 2002
Location: vta.ca.usa
Posts: 555
bdl is on a distinguished road
Quote:
Originally posted by joe_bruin
wtf are you talking about?

you're supposed to quote your strings, but not identifiers.

PHP Code:
$query "UPDATE users SET age='$age' WHERE username='$username'"
Actually, it is a good idea to use backticks on your column names, in the case you should happen to use a MySQL reserved word. I refer you to the MySQL manual section on <reserved words>.
bdl is offline   Reply With Quote
Old 11-27-2003, 09:34 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
i always wondered why phpmyadmin uses backticks so heavily ... i wonder why i can't name a field 'order' still though. i guess some reserved words aren't allowed at all. ( well i haven't tried in a long time .. maybe something changed )
__________________
Mike
sde is offline   Reply With Quote
Old 11-27-2003, 11:21 AM   #7 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
so that was it eh....its working fine now, thanks everyone. when i couldn't figure it out i got phpmyadmin to generate the php code for me, and i guess i mistakened the ` ticks to be single quotes '.
good to know.
trevor is offline   Reply With Quote
Old 12-02-2003, 05:07 AM   #8 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Quote:
Originally posted by sde
i always wondered why phpmyadmin uses backticks so heavily ... i wonder why i can't name a field 'order' still though. i guess some reserved words aren't allowed at all. ( well i haven't tried in a long time .. maybe something changed )
Yep, I get caught up trying to name a description field "desc" and it wont let me. Guess that would foul up the sorting.

-r
idx is offline   Reply With Quote
Old 12-05-2003, 08:45 AM   #9 (permalink)
Nitro
Registered User
 
Nitro's Avatar
 
Join Date: Jun 2003
Location: London, England
Posts: 29
Nitro is on a distinguished road
Send a message via AIM to Nitro
Lol, yeah, i've done that before, also, I once tried to name a field "order", which obviously didnt work:-p
Nitro is offline   Reply With Quote
Reply

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
writting progress to cl on one line sde Linux / BSD / OS X 4 11-08-2004 01:15 PM
whats wrong with this code trevor PHP 7 04-01-2003 06:00 PM
cgi script Henry PHP 25 12-30-2002 06:54 AM
so where exactly is the line drawn for ... sde PHP 2 06-05-2002 09:18 AM


All times are GMT -8. The time now is 09:53 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting