473,667 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\ht docs\vod\minera l_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 6497

"Cowfisher" <co*******@yaho o.com> wrote in message
news:93******** *************** ***@posting.goo gle.com...
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\ht docs\vod\minera l_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*******@yaho o.com> wrote in message
news:93******** *************** ***@posting.goo gle.com...
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\ht docs\vod\minera l_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.washin gton.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.washi ngton.edu> wrote in message
news:Pi******** *************** ********@dante1 8.u.washington. edu...
Steven sikyal:

"Cowfisher" <co*******@yaho o.com> wrote in message
news:93******** *************** ***@posting.goo gle.com...
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\ht docs\vod\minera l_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.washin gton.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
3941
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 version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
4
3268
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 section from the manual: 20.1.9.7 WHILE Statement
0
11695
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 java.sql.SQLException: Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"; We get such errors generally on inserts or updates while applying a
5
2029
oll3i
by: oll3i | last post by:
my librarybean package library.ejb; import java.sql.*; import javax.ejb.*; import library.common.*; @Stateless @Remote
3
5504
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 exception/error: ** BEGIN NESTED EXCEPTION ** com.mysql.jdbc.CommunicationsException MESSAGE: Communications link failure due to underlying exception:
1
3367
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 an exception occours which is- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request.
1
2517
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
5850
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 ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
1
9569
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 things (stored procedures, functions).. we have to manually edit. That time, we face some interesting challenges.. I failed to document all of them, but whatever I can share with u.. I will try.. :) ...
0
8457
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8365
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8788
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8646
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.