PDA

View Full Version : my script is acting WEIRD!


The69Pimp
10-05-2002, 09:20 AM
ok i am making this game and i have this file inc.header.php and there is a error at the very last line nomatter what the line it even if it is blank here is the script it is long so.....


<?
$ip = getenv(/Joes/');
$newfilename = $uid . "." . $secid . "." . $ip;

require('inc.settings.php');

if ((file_exists("$homedir/$newfilename")) && ($uid != "")) {


$sql = "SELECT * from og_userinfo where uid='$uid'";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$result = @mysql_query($sql);
$myrow = @mysql_fetch_array($result);
$networthdisplay = $myrow[networth];
$sqlcbmm = "SELECT uid from og_marketmods";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcbmm = @mysql_query($sqlcbmm);
$myrowcbmm = @mysql_fetch_array($resultcbmm);
if ($myrowcbmm[uid] == "") {
$sqlcbmm2 = "update og_marketmods set uid='$uid' where id=1";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcbmm2 = @mysql_query($sqlcbmm2);
//market check
$timemod = time();
$sqlcb = "SELECT * from og_marketinfo where endtime <= $timemod";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcb = @mysql_query($sqlcb);
$myrowcb = @mysql_fetch_array($resultcb);
$i2 = 0;
do {
if (($myrowcb[type]) && ($myrowcb[id] != $lastid)) {
$lastid = $myrowcb[id];
if ($myrowcb[type] == 1) {
$product = "prostitutes";
$product2 = "prostitutes";
}
if ($myrowcb[type] == 11) {
$product = "thugs";
$product2 = "thugs";
}
if ($myrowcb[type] == 12) {
$product = "dealers";
$product2 = "dealers";
}
if ($myrowcb[type] == 13) {
$product = "informants";
$product2 = "informants";
}
if ($myrowcb[type] == 2) {
$product = "crackrocks";
$product2 = "crackrocks";
}
if ($myrowcb[type] == 21) {
$product = "smack";
$product2 = "smack";
}
if ($myrowcb[type] == 3) {
$product = "glocks";
$product2 = "glocks";
}
if ($myrowcb[type] == 31) {
$product = "tek9s";
$product2 = "tek9s";
}
if ($myrowcb[type] == 32) {
$product = "uzis";
$product2 = "uzis";
}
if ($myrowcb[type] == 33) {
$product = "aks";
$product2 = "aks";
}
if ($myrowcb[type] == 4) {
$product2 = "civics";
$product = "hondas";
}
if ($myrowcb[type] == 41) {
$product2 = "cadillacs";
$product = "cadillacs";
}
if ($myrowcb[type] == 42) {
$product2 = "s-classes";
$product = "mercedes";
}
if ($myrowcb[type] == 43) {
$product2 = "5-series";
$product = "bmws";
}
if (($myrowcb[bidder] == "") || ($myrowcb[bidder] == 0)) {
$marketitem = $myrowcb[id];
$sqlcb2b = "delete from og_marketinfo where id=$marketitem";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcb2b = @mysql_query($sqlcb2b);
$amountwin = $myrowcb[number];
$bidderwin = $myrowcb[seller];
$toid = $bidderwin;
$fromid = 0;
$type = 3;
$cartelid = 0;
$msg = "Nobody bided on your " . $myrowcb[number] . " " . $product2 . ". So, your items have been returned to you.";
$msg = addslashes($msg);
$sqlcbmz = "SELECT count(*) from og_messages where message like '%$msg%' AND time=$timemod";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcbmz = @mysql_query($sqlcbmz);
$myrowcbmz = @mysql_fetch_array($resultcbmz);
if ($myrowcbmz[0] == 0) {
$sqlzb = "INSERT into og_messages (sent, message, cartel, type, fromid, toid, time, id) values (null, '$msg', $cartelid, $type, $fromid, $toid, $timemod, null)";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultzb = @mysql_query($sqlzb);
$sqlcb2 = "UPDATE og_userinfo set $product=$product+$amountwin where id=$bidderwin";
//logging start
$stringlogging = $sqlcb2;
require( 'inc.log.php' );
//logging finish
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcb2 = @mysql_query($sqlcb2);
}
} else {
$marketitem = $myrowcb[id];
$sqlcb2b = "delete from og_marketinfo where id=$marketitem";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcb2b = @mysql_query($sqlcb2b);
$amountwin = $myrowcb[number];
$bidderwin = $myrowcb[bidder];
$toid = $bidderwin;
$fromid = 0;
$type = 3;
$cartelid = 0;
$msg = "You have won the market items you were bidding on. " . $amountwin . " " . $product2 . " have been delivered to you!";
$msg = addslashes($msg);
$sqlcbmz2 = "SELECT count(*) from og_messages where message like '%$msg%' AND time=$timemod";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcbmz2 = @mysql_query($sqlcbmz2);
$myrowcbmz2 = @mysql_fetch_array($resultcbmz2);
if ($myrowcbmz2[0] == 0) {

$sqlzb = "INSERT into og_messages (sent, message, cartel, type, fromid, toid, time, id) values (null, '$msg', $cartelid, $type, $fromid, $toid, $timemod, null)";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultzb = @mysql_query($sqlzb);

//give items
$sqlcb2aa = "UPDATE og_userinfo set $product=$product+$amountwin where id=$bidderwin";
//logging start
$stringlogging = $sqlcb2aa;
require( 'inc.log.php' );
//logging finish
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcb2aa = @mysql_query($sqlcb2aa);

//give money to winner
$seller = $myrowcb[seller];
$winningamt = $myrowcb[price];
$sqlcb2 = "UPDATE og_userinfo set money=money+$winningamt where id=$seller";
//logging start
$stringlogging = $sqlcb2;
require( 'inc.log.php' );
//logging finish
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcb2 = @mysql_query($sqlcb2);
//msg to winner
$toid3 = $seller;
$fromid3 = 0;
$type3 = 3;
$cartelid3 = 0;
$msg3 = "We were able to sell your " . $amountwin . " " . $product2 . " on the market for $" . number_format($winningamt) . "!";
$msg3 = addslashes($msg3);
$sqlzb3 = "INSERT into og_messages (sent, message, cartel, type, fromid, toid, time, id) values (null, '$msg3', $cartelid3, $type3, $fromid3, $toid3, $timemod, null)";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultzb3 = @mysql_query($sqlzb3);
}
}
}
$i2 = $i2 + 1;
} while($myrowcb = @mysql_fetch_array($resultcb));
}
// clear key
$sqlcbmm2b = "update og_marketmods set uid='' where id=1";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$resultcbmm2b = @mysql_query($sqlcbmm2b);
$sql3bc = "SELECT count(*) from og_userinfo where networth > $networthdisplay";
@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");
$result3bc = @mysql_query($sql3bc);
$myrow3bc = @mysql_fetch_array($result3bc);
$rank = $myrow3bc[0] + 1;
?>
<!doctype html public "-//W3C//DTD HTML 3.2//EN">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">
<title></title>
<STYLE type=text/css>
A:HOVER {
background : #000000;
color : black;
}
.text {
font-family: Verdana, Arial, sans-serif;
FONT-SIZE: 11px;
line-height : 12px;
color : FFC000;
}
-->
</style>
</head>

<body text="FFFFFF" bgcolor="#000000" link="#FFC000" alink="#FFC000" vlink="#FFC000" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">
<p><br>
</body>
</html>



ALL help would be greatly appricated

firepages
10-05-2002, 11:26 AM
dude you never gonna find errors in code like that :)

if an error is always at the last line as you stated the problem is nearly always a missing closing brace

'}'

but its really too hard to find in all that code, + you are mixing 2 styles of coding ... always use braces for if/else statements , or at least stick to one format...

so I guess the issue is around here somewhere

} while($myrowcb = @mysql_fetch_array($resultcb));
}

which makes no sense

(Note add a '}' here and you lose the error - though whether its the right error or not I can't tell.)

for a start to clean up the code .. lose the repeated database connections, you only need connect once per script.... so put

@mysql_connect($dbhost, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Error opening database");

at the top of your script and lose the other 14 replications they are not needed and make your code hard to read.

mordred
10-05-2002, 01:45 PM
*falls from his chair at the sight of this code format*

I can only agree with what firepages said. You aren't doing yourself a favor by neglecting to indent your code properly. Remember, it's not only helpful for you, but also for others like us forum members to graps what's going on in your code...

Having said that, here are some tips that should help you dealing with your code.

1. Use an incremental approach
If something doesn't work, the error may not lie in the line you're currently looking at. Try incrementally comment out various lines of code until you can narrow down the source of the error. If you can exclude certain parts as working, remove the next portion of comments and so on.

2. Report error messages
Saying that an error message appears is fine, but could be better. You can also provide us with the exact error description PHP spits out. Have in mind that if we would cut'n-paste the code excerpt from above into our PHP environment, something quite different coud appear, depending on our actual PHP/server configuration.
Also, while developing, get rid of the error suppressing '@' sign infront of the functions.

3. Make your code less procedural
If you have certain parts of code that appear repeatedly in your code, why not put it into a function, aptly named, and call that within your if-statement etc.? That's what functions are made for.

Last but not least, your very first line seems broken to me. Neglect if it's just a copy-paste error, but this


$ip = getenv(/Joes/');


can't work... a missing single quote... and what variable did you want to reach by that?

Spookster
10-05-2002, 04:10 PM
Oh my gosh database connections. Probably max out the hosts max number of concurrent mysql connections just from that one script. :D

The69Pimp
10-06-2002, 03:59 AM
hey im a n00b quit making fun of me anywayz, i get this error now

Parse error: parse error, expecting `T_WHILE' in /home/drugwarz/public_html/gankstaz/inc.header.php on line 163

this is line 160 to 170


}
}
}
$i2 = $i2 + 1;
} while($myrowcb = @mysql_fetch_array($resultcb));
}
// clear key
$sqlcbmm2b = "update og_marketmods set uid='' where id=1";
$resultcbmm2b = @mysql_query($sqlcbmm2b);
$sql3bc = "SELECT count(*) from og_userinfo where networth > $networthdisplay";
$result3bc = @mysql_query($sql3bc);




and

$i2 = $i2 + 1;

is line 163 please help me

The69Pimp
10-06-2002, 04:59 AM
errrrrr now i have this error:

Parse error: parse error in /home/drugwarz/public_html/gankstaz/inc.header.php on line 167

here is line 50 to 77


$resultcb2 = @mysql_query($sqlcb2);
//msg to winner
$toid3 = $seller;
$fromid3 = 0;
$type3 = 3;
$cartelid3 = 0;
$msg3 = "We were able to sell your " . $amountwin . " " . $product2 . " on the market for $" . number_format($winningamt) . "!";
$msg3 = addslashes($msg3);
$sqlzb3 = "INSERT into og_messages (sent, message, cartel, type, fromid, toid, time, id) values (null, '$msg3', $cartelid3, $type3, $fromid3, $toid3, $timemod, null)";
$resultzb3 = @mysql_query($sqlzb3);
}
}
}
$i2 = $i2 + 1;
} while($myrowcb = @mysql_fetch_array($resultcb));
'}'

$resultcbmm2b = @mysql_query($sqlcbmm2b);
$sql3bc = "SELECT count(*) from og_userinfo where networth > $networthdisplay";
$result3bc = @mysql_query($sql3bc);
$myrow3bc = @mysql_fetch_array($result3bc);
$rank = $myrow3bc[0] + 1;
}
}
}
}
?>

someone please tell me what to do

firepages
10-06-2002, 05:11 AM
Nobody is making fun of you dude , we all (at least I) have made all the same mistakes, and we are just trying to point these out to you.

But the problem is that your code is very hard to read which makes it almost impossible to see whats happening, especially when there are so many database queries (so we cant debug locally)


$i2 = $i2 + 1; is fine $i2++; would work as well

but this bit just has to be causing problems

}
}
}
$i2 = $i2 + 1;
} while($myrowcb = @mysql_fetch_array($resultcb));
'}'

does this make a difference ?

while($myrowcb = @mysql_fetch_array($resultcb)){

I am guessing as its hard to see whats happening in your code.
You are going to have to debug this by rewriting the script a bit at a time once you find a bit that works save and add the next bit etc.

mordred
10-06-2002, 03:39 PM
I don't think we were making fun of you, The69Pimp. If we critizied your coding style, we offered at the same time alternative techniques which (and firepages is right on that, at least for me) we all learned the hard way.

That's what I call constructive criticism. If you think we were doing this in a rude manner, tell us. But I don't think we were rude.

Anyway, it has been explained to you already that your syntax directly behind the while condition is incorrect. Control structures like loops, if statements etc. must be followed directly with a single code statement (a line of code up to the semicolon) or a code block that must start with the opening brace {. So this


while ( $foo == 1 ) echo "blah\n";

while ( $foo2 == 2 )
echo "blah\n";

while ( $foo3 == 3 ) {
echo "second blah\n";
}


is correct PHP syntax for every while loop. While on the other hand,


while ( $foo4 == 4 )
echo "second blah\n";
}

while ( $foo5 == 5 )
}


is incorrect because the code blocks that shall be exectuted in the loop are not correctly opened - both miss the opening brace. See the pattern now? :)

Detailed explanation is of course also found in the manual. If you feel unsure about loops, perhaps start reading there and experiment with various ways of definining while loops.
http://us.php.net/manual/en/control-structures.while.php