Web Hosting Talk







View Full Version : Can anyone tell me what's wrong with this script?


sam.moses
05-25-2002, 02:10 PM
Hey everyone.
I'm working on porting an ad management and exchange script from asp to php, but it is generating odd errors. Still new to the php world, and I am not entirely sure what I'm doing wrong. I'm not asking for new code, but if someone could tell me what I'm doing wrong, it would really help.

Thanks.

Here's the ported code:

<?
session_start();
session_register("unique_session");
session_register("autoid_session");
?>
<?
if ($unique_session=="")
{

// Create database connection string, login and password variables

$MySQLSVR="localhost"; // enter IP or hostname of MySQL server
;
$MySQLPRT=3306; // enter MySQL port (default 3306)
;
$MySQLUID="root"; // enter Username (between quotes)
;
$MySQLPWD=""; // enter Password (between quotes)
;
$MySQLDB="bx4"; // enter Active DataBase (between quotes)
;
$MySQLOPT=16387; // enter MyODBC options values (at least 16387)
;
// Loading up the the MySQL Database.

$strConn="driver={MySQL};server=".$MySQLSVR.";port=".$MySQLPRT.";"
."uid=".$MySQLUID.";pwd=".$MySQLPWD.";database=".$MySQLDB.";option=".$MySQLOPT."";
$mySqlads_STRING=$strConn; ?>
<?
//Establishing Contstants

$myown="1";
if (($HTTP_GET_VARS["autoid"]!=""))
{
$myown=$HTTP_GET_VARS["autoid"];
}
$mycategory=$HTTP_GET_VARS["tempid"];
if ($HTTP_GET_VARS["tempid"]=="")
{
$mycategory="14";
}

//Now, we find the ad

// $theaditself is of type "ADODB.Recordset"

echo $mySqlads_STRING;
echo "SELECT * FROM ads WHERE status=2 AND bank>0 AND
tempid=".$mycategory." AND autoid <> ".$myown."";
echo 1;
echo 2;
echo 3;
mysql_query($theaditself_CommandText,$theaditself_ActiveConnection);
$theaditself_numRows=0;

//Now we count the records in the recordset, and randomly pick one
where the select critiria works.

mt_srand((double)microtime()*1000000);
mysql_data_seek($theaditself_query,();
$Cint[mysql_num_rows($theaditself_query)]);

//Cleaning up the database calls

$autoid=(.$Item["autoid"].$Value);
$autoid_session=$autoid;
$bank=(.$Item["bank"].$Value);
$banner=(.$Item["formcode"].$Value);
$tempid=$mycategory;
$URL=(.$Item["url"].$Value);
$title=(.$Item["title"].$Value);
?>
<?
//Now here's where we have some fun. The code below will generate the
unchatable javascript that makes the banner.
if (!($theaditself==0) || !($theaditself_BOF==1))
{
?>
var ob = '0' var obx = '468' var obx2 = '60' var target = '_parent'
var image
= 'uploads/<? echo $banner; ?>.gif' var link =
'catapolt.asp?autoid=<? echo $autoid; ?>' document.write("<A
target=\""+target+"\" href=\""+link+"\">"); document.write("<Img
width=\""+obx+"\" height=\""+obx2+"\" border=\""+ob+"\"
src=\""+image+"\">");
document.write("<\/a>");
<?
//Think of the trading of links like a bank transaction.

//There are two parties involved, and credits need to trade hands.

//First we charge for service by debiting the ad shown on the page.

// $chargetheuser is of type "ADODB.Command"

$chargetheuser_ActiveConnection=$mySQLads_STRING;
$chargetheuser_CommandText="UPDATE ads SET impx=impx+1,
bank=bank-1 WHERE autoid=".$autoid." ";
//chargetheuser.CommandType = 1

//chargetheuser.CommandTimeout = 0

//chargetheuser.Prepared = true

$chargetheuser_Execute=);

//So now that the money has been taken out of one account, it needs to
be put into another.

//In this instance the user earns three credits for every unique
banner shown.

//Here's how you do it.
// $= is of type "ADODB.Command"

$chargetheuser.$ActiveConnection=$mySQLads_STRING;
$chargetheuser.$CommandText="UPDATE ads SET bank=bank+3,
onmypage=onmypage+1 WHERE autoid=".$myown." ";
$chargetheuser.$CommandType=1;
$chargetheuser.$CommandTimeout=0;
$chargetheuser.$Prepared=true;
$chargetheuser.$Execute[];
$unique_session="used";
}
}


?>

BluemoonHost
05-27-2002, 02:26 PM
Could you post the errors you've recieved?

sam.moses
05-27-2002, 09:07 PM
Hey Aaron,
I'm getting a parse error on line 60 which is the line that calls the main query.

Looks like this:

mysql_data_seek($theaditself_query,();

I think it could be the connection string. When I get this type of error in ASP, that's usually what it is. I can't seem to find any decent documentation on connection strings in PHP though.

Any ideas?

mwatkins
05-27-2002, 09:15 PM
>>
mysql_data_seek($theaditself_query,();
$Cint[mysql_num_rows($theaditself_query)]);
<<

Should be

mysql_data_seek($theaditself_query, $Cint[mysql_num_rows($theaditself_query)]);

Clues? "Parse Error" is almost always punctuation.

>> mysql_data_seek($theaditself_query,(); <- improperly closed

And then look at the function call prototype:
bool mysql_data_seek(resource result_identifier, int row_number)

Clearly the function requires two parameters.

You should have the excellent PHP manual documentation open side by side. Always look for the simple answers first (punctuation) and query the manual.

sam.moses
05-28-2002, 07:32 PM
Thanks guys.
It works now.
Odd thing this php. It will take some getting used to.

Studio64
05-30-2002, 02:55 AM
Originally posted by sam.moses
Odd thing this php. It will take some getting used to. [/B]

But, when it does work... It's fun... Although getting it to work will raise your blood pressure faster than calling your girlfriend the wrong name mid-love making.

sam.moses
05-30-2002, 08:32 AM
I'm not too hot on it.
It reminds seems like an odd cross between Java and Perl with a set of gramatical quirks unseen since Cobol. Not that I'm complaining mind you. Just need more pactice with it.