473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP and MySQL WHERE statement

I can write simple MySQL stuff in PHP but I'm having problems putting
in WHERE clauses. Everytime I do I get errors like this:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program
files\apache group\apache\htdocs\vod\mineral_action.php on line 10

The code that generated this crap is:

$sql = "UPDATE character SET mining = $new_skill WHERE char_name =
$_SESSION['user']";

I do have my session correctly started and all that (I know this
mainly because I don't get error without the WHERE stuff and have
tested out the variable). I think I've tried everything under the sun
to try and get this working. This is in <? ?> as correctly needed
with PHP it's just something with the WHERE statements. I tried the
yahoo chat rooms but to no avail.

Besides looking for help with this problem, can anyone refer me to a
good irc chat room for php problems that has ACTIVE (not filled with
lurkers) people in it?

Thanks for your help!
Jul 16 '05 #1
3 6485

"Cowfisher" <co*******@yahoo.com> wrote in message
news:93**************************@posting.google.c om...
I can write simple MySQL stuff in PHP but I'm having problems putting
in WHERE clauses. Everytime I do I get errors like this:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program
files\apache group\apache\htdocs\vod\mineral_action.php on line 10

The code that generated this crap is:

$sql = "UPDATE character SET mining = $new_skill WHERE char_name =
$_SESSION['user']";

I do have my session correctly started and all that (I know this
mainly because I don't get error without the WHERE stuff and have
tested out the variable). I think I've tried everything under the sun
to try and get this working. This is in <? ?> as correctly needed
with PHP it's just something with the WHERE statements. I tried the
yahoo chat rooms but to no avail.

Besides looking for help with this problem, can anyone refer me to a
good irc chat room for php problems that has ACTIVE (not filled with
lurkers) people in it?

Thanks for your help!


Use double quote:

$_SESSION["user"]

-Steven
Jul 16 '05 #2
Steven sikyal:

"Cowfisher" <co*******@yahoo.com> wrote in message
news:93**************************@posting.google.c om...
I can write simple MySQL stuff in PHP but I'm having problems putting
in WHERE clauses. Everytime I do I get errors like this:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program
files\apache group\apache\htdocs\vod\mineral_action.php on line 10

The code that generated this crap is:

$sql = "UPDATE character SET mining = $new_skill WHERE char_name =
$_SESSION['user']";
[snip]


Use double quote:

$_SESSION["user"]


Don't do that. This will close your quote one one side of "user" and
reopen it one the other. It might compile (thought I doubt it), and it
might work because PHP assumes that barewords are single-quoted strings if
it can't figure out otherwise. It's still a very bad thing, though.

What you want is to use no quotes at all:

$sql = "UPDATE character SET mining = $new_skill WHERE char_name =
$_SESSION[user]";

This is an exception to the normal parsing of variable names, but that's
how PHP does it inside a double-quoted string. This information is in the
manual somewhere, but I can never find it.
Jesse S. Bangs ja****@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"
Jul 16 '05 #3

"JS Bangs" <ja****@u.washington.edu> wrote in message
news:Pi*******************************@dante18.u.w ashington.edu...
Steven sikyal:

"Cowfisher" <co*******@yahoo.com> wrote in message
news:93**************************@posting.google.c om...
I can write simple MySQL stuff in PHP but I'm having problems putting
in WHERE clauses. Everytime I do I get errors like this:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program
files\apache group\apache\htdocs\vod\mineral_action.php on line 10

The code that generated this crap is:

$sql = "UPDATE character SET mining = $new_skill WHERE char_name =
$_SESSION['user']";
[snip]


Use double quote:

$_SESSION["user"]


Don't do that. This will close your quote one one side of "user" and
reopen it one the other. It might compile (thought I doubt it), and it
might work because PHP assumes that barewords are single-quoted strings if
it can't figure out otherwise. It's still a very bad thing, though.

What you want is to use no quotes at all:

$sql = "UPDATE character SET mining = $new_skill WHERE char_name =
$_SESSION[user]";

This is an exception to the normal parsing of variable names, but that's
how PHP does it inside a double-quoted string. This information is in the
manual somewhere, but I can never find it.
Jesse S. Bangs ja****@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"


Actually, I did this :

previous statement". $_SESSION["user"]."after statment...

It works, and I just tried it without the quote at all and it is also
working :)

Thanks for point that out.

-Steven

Jul 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
5
oll3i
by: oll3i | last post by:
my librarybean package library.ejb; import java.sql.*; import javax.ejb.*; import library.common.*; @Stateless @Remote
3
by: tulika dutta | last post by:
after 8 hrs my MySQL connection with JDBC gets time out. It gives the error java.sql.SQLException: No operations allowed after connection closed.Connection was implicitly closed due to underlying...
1
by: ajos | last post by:
hi evrybdy, the problem is:- i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem... when i enter values in the 2 text boxes and click enter...
1
by: paulq182 | last post by:
PLEASE HELP ME WITH MY CODE?? import java.sql.*; import java.io.*; class min_filmdb_rel_mysql { public static void main (String args ) throws SQLException, IOException {
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.