Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to fast issue

Status
Not open for further replies.

krappleby

Programmer
Jul 25, 2006
25
GB
Hi again all,

i wonder if any of you have any ideas on the following.

i have a very long php script that processes several queries, as well as checks data, here is an example

update blah set color = blue where member = 1
then
select * from blah where member = 1
if (colur=blue)
do this

however the problem is the second part of the script. the select statement, is running before the update statement.

i need for the select statement only to run once the update statement is completed. as it is currenlty giving wrong information.

im having to run the script twice, to get the desired results.

any ideas, on how this can be done

tahnks fro your help
 
there may be several issues here.

1. database queries are performed in the order that they are made as single atomic transactions. so unless you are using some weird database, or you are using a transaction, it seems impossible that the member 1's colour is not updating.

2. if you are convinced that all is correct, then you should try basic debugging techniques. it is possible that the queries are throwing errors.

Code:
mysql_query ('Update blah set color='blue' where member=1') or die (mysql_error());

3. of course I am assuming that you ARE enquoting the color variable in your query. otherwise the query WILL fail no matter how many times you are running it. all variables MUST be enquoted and escaped before use in a query.

4. the operator '=' is an assignment operator and not a conditional operator. this code:
Code:
if ($color = 'blue') //note that your code will never work as you are not using a $ sign in front of color nor are you enquoting the variable value (although sometimes php will not complain about this too much)
will ALWAYS evaluate to TRUE because what you are saying is "SET $color equal to 'blue'"
to use a comparison operator you must use '==' or '===' depending on whether you need a strict comparison or not.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top