Current location: Hot Scripts Forums » Programming Languages » PHP » If Statement With Query !!!


If Statement With Query !!!

Reply
  #1 (permalink)  
Old 10-02-06, 08:54 AM
phpfreek phpfreek is offline
Wannabe Coder
 
Join Date: Feb 2006
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
If Statement With Query !!!

Hey guys ... How r ya all doing ?

Hope you are fine ...

i was trying to write a script , but got stuck on a code ... thought some of you guys mught help me

Here is my problem ;

I want the code to see if a table named "money" in the database has a value bigger than 500, if it has a value bigger than 500, the folowing query's will be executed :

PHP Code:

$query="UPDATE $usernamee SET weapon = 'klashen'";

$query2="update $usernamee set money=money-500";
$result mysql_query($query) or die(mysql_error());
$result mysql_query($query2) or die(mysql_error()); 
And if it doesn't have a value bigger than 500, the folowing line will be displayed :
You do not have enought money to buy that weapon !

After hard work of cosing, i have come up with the folowing code :

PHP Code:

<?php

session_start
();
$username="root"
$password=""
$database="login";
$usernamee=$_SESSION['username'];
mysql_connect(localhost,$username,$password); 
@
mysql_select_db($database) or die( "Unable to select database");
$query="UPDATE $usernamee SET weapon = 'klashen'";
$query2="update $usernamee set money=money-500";
if (
money>100) {
$result mysql_query($query) or die(mysql_error());
$result mysql_query($query2) or die(mysql_error());
} else {
echo 
"You do not have enought money to buy that weapon !";
}
mysql_close();
?>
Unfortunately, it didin't work

Can any of you guys help me with my script ?

Thank you in advance,
Best Regards;
PHPFREEK
Reply With Quote
  #2 (permalink)  
Old 10-02-06, 11:29 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
this will not work as you didn't define money, and as money is not a variable.

first select the money from your db, assign it to the variable $money, and the match against 100

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 10-02-06, 02:31 PM
phpfreek phpfreek is offline
Wannabe Coder
 
Join Date: Feb 2006
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
Hmmm ... i think i understand ... well do u know the code for selecting the table from the database ??? ... if you do, can u please tell me ...

Thank you in advance.
PHPFREEK
Reply With Quote
  #4 (permalink)  
Old 10-03-06, 03:28 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
i don't know exactly what your database looks like, but try this:
PHP Code:

$res mysql_query("SELECT money FROM $usernamee");

$temp mysql_fetch_array($res) or dei(mysql_error());
$money $temp['money']; 
btw: those 2 queries you're updating can be merged into 1:
PHP Code:

$query "UPDATE $usernamee SET money=money-500, weapon='klashen'"
it seems that you don't know much about mysql querires, here are some good tutorials:
http://dev.mysql.com/doc/refman/5.0/en/tutorial.html
http://www.php-mysql-tutorial.com/my...rial/index.php
http://www.tizag.com/mysqlTutorial/

these are all rather basic tutorials, but this is how i learned the basis of mysql. Or you could just by a book about mysql

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

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
MySQL query... case statement? joining? ?? dracula PHP 2 08-15-05 07:55 AM
Hard query statement help ExtremeGuy PHP 1 08-10-04 04:24 PM
sql query statement unsure mivec PHP 3 04-12-04 08:52 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


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