Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-27-2002, 08:48 PM   PM User | #1
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
php/mysql script that is meant up update..

...some info in a table doesnt work..
hmm you see the $id is from the url the rest is either in the script or the db.... its meant to get the current balance... and work out how much it should go up and then updat eit to the new baance.. it errors.. any one see why?
Code:
<?php
$dbc = mysql_connect('localhost', '', '') or die("Couldn't connect to database"); 
 mysql_select_db('GAME') or die("Couldn't select database"); 

$query ="SELECT * FROM founds WHERE id=$id";
$query ="UPDATE founds SET balance = $income WHERE id =$id";

$result = mysql_query($query) or die("There is an error with you account, please contact support and inform them of this"); 
 while ($r = mysql_fetch_array($result)) { 
 extract($r);

        $fincome = $extractors * 2000 ;
        $sincome = $extractors * $advanced ;
        $income = $fincome + $sincome ;

echo("Account Balance Updated");

?>
thanks a lot
sir pannels is offline   Reply With Quote
Old 11-28-2002, 12:32 AM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
You are only running the second query. A query is executed using this command:

mysql_query($query)

so in yours, you are only executing the second one:

$query ="UPDATE founds SET balance = $income WHERE id =$id";

because you overwrite the first one with the second one.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 11-28-2002, 11:45 AM   PM User | #3
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
oh i see.
thanks
hmm is there anyway i can run to querys in the same sript in that case?
I think i saw it somewhere befor... maybe I was wrong
sir pannels is offline   Reply With Quote
Old 11-28-2002, 01:38 PM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
$query ="SELECT * FROM founds WHERE id=$id";

$result = mysql_query($query)

//put your code here to extract results to get value for the second query

$query ="UPDATE founds SET balance = $income WHERE id =$id";

$result = mysql_query($query)
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 11-28-2002, 02:14 PM   PM User | #5
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
oh thanks Spook
so like this yeh..
Code:
<?php
$dbc = mysql_connect('localhost', '', '') or die("Couldn't connect to database"); 
 mysql_select_db('GAME') or die("Couldn't select database"); 

$query ="SELECT * FROM founds WHERE id=$id"; 
$result = mysql_query($query) 
 while ($r = mysql_fetch_array($result)) { 
 extract($r);

        $fincome = $extractors * 2000 ;
        $sincome = $extractors * $advanced ;
        $income = $fincome + $sincome ;

$query ="UPDATE founds SET balance = $income WHERE id =$id"; 

$result = mysql_query($query)

echo("Account Balance Updated");

?>
that what i think your tellin me to do.. done that tho.
however error line 7 parse error... hmm any further ideas?
thanks for all yoru time
sir pannels is offline   Reply With Quote
Old 11-28-2002, 02:29 PM   PM User | #6
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Well other than a couple of missing semi-colons at the ends of two lines I don't see anything else wrong. I've never used the extract function before. I usually just pull the data out of the array like so:

while ($row = mysql_fetch_array($result)) {
$yaks = $row["tablecolumnname"];
}
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 11-28-2002, 02:39 PM   PM User | #7
Wichetael
New Coder

 
Join Date: Nov 2002
Location: Netherlands
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Wichetael has a little shameless behaviour in the past
You're missing a curly bracket...

Code:
<?php
$dbc = mysql_connect('localhost', '', '') or die("Couldn't connect to database"); 
mysql_select_db('GAME') or die("Couldn't select database"); 

$query ="SELECT * FROM founds WHERE id=$id"; 
$result = mysql_query($query) 

while ($r = mysql_fetch_array($result)) { 
  extract($r);
  $fincome = $extractors * 2000 ;
  $sincome = $extractors * $advanced ;
  $income = $fincome + $sincome ;

  $query ="UPDATE founds SET balance = $income WHERE id = $id"; 
  $result = mysql_query($query);
}
echo("Account Balance Updated");

?>
Wichetael is offline   Reply With Quote
Old 11-28-2002, 02:43 PM   PM User | #8
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
oh thanks spooks, for all yer help.
wich.. hm ok i put that code you typed in a file and ran it and got
Parse error: parse error in c:\phpdev\www\public\game\hourlyfounds.php on line 8

hmm doesnt make sense.. im lost arg
sir pannels is offline   Reply With Quote
Old 11-28-2002, 03:24 PM   PM User | #9
Wichetael
New Coder

 
Join Date: Nov 2002
Location: Netherlands
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Wichetael has a little shameless behaviour in the past
Forgot another semicolon (on line 6)...

Code:
<?php
$dbc = mysql_connect('localhost', '', '') or die("Couldn't connect to database"); 
mysql_select_db('GAME') or die("Couldn't select database"); 

$query ="SELECT * FROM founds WHERE id=$id"; 
$result = mysql_query($query);

while ($r = mysql_fetch_array($result)) { 
  extract($r);
  $fincome = $extractors * 2000 ;
  $sincome = $extractors * $advanced ;
  $income = $fincome + $sincome ;

  $query ="UPDATE founds SET balance = $income WHERE id = $id"; 
  $result = mysql_query($query);
}
echo("Account Balance Updated");

?>
That should work
Wichetael is offline   Reply With Quote
Old 11-28-2002, 06:12 PM   PM User | #10
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
oh yeh did nt see that thanks
arg more trouble now.. all it puts in browser is this
Quote:
Warning: Supplied argument is not a valid MySQL result resource in c:\phpdev\www\public\game\hourlyfounds.php on line 8
Account Balance Updated
so many problems hehe
sir pannels is offline   Reply With Quote
Old 11-29-2002, 02:54 PM   PM User | #11
Wichetael
New Coder

 
Join Date: Nov 2002
Location: Netherlands
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Wichetael has a little shameless behaviour in the past
That simply means that your query: "select * from founds where id=$id" didn't return any results, so either you have no data in you table matching id to $id, or $id has an inapropriate value or the table 'founds' doesn't exist...

Try using this, that should give you some more info:

Code:
<?php
$dbc = mysql_connect('localhost', '', '') or die("Couldn't connect to database");
mysql_select_db('GAME') or die("Couldn't select database");

$query ="SELECT * FROM founds WHERE id=$id";
$result = mysql_query($query);

if (!$result)
  die(mysql_error());

while ($r = mysql_fetch_array($result)) {
  extract($r);
  $fincome = $extractors * 2000 ;
  $sincome = $extractors * $advanced ;
  $income = $fincome + $sincome ;
  
  $query ="UPDATE founds SET balance = $income WHERE id = $id";
  $result = mysql_query($query);
  if (!$result)
    die(mysql_error());
}

echo("Account Balance Updated");

?>
Wichetael is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:25 PM.


Advertisement
Log in to turn off these ads.