Page 1 of 1

[SOLVED] code doesn't execute...

Posted: Fri Mar 09, 2007 2:15 pm
by arukomp
Hi everyone

I'm having a problem again :( My code doesn't execute...

here's first part of the code in the first page:

Code: Select all

function otherprogram($pid, $id){
	$sql = "SELECT * FROM `user` WHERE id='$id'";
	$result = mysql_query($sql);
	$array = mysql_fetch_array($result);
	$name = $array['name'];
	$egold = $array['egold'];
	$email = $array['email'];
	global $url;
	global $key;
	$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url . '/insertnewuser.php?key='.$key.'&p='.$pid.'&name='.$name.'&email='.$email.'&egold='.$egold);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $a = curl_exec($ch);
    if (!$a) {
		curl_exec($ch);
	}
    curl_close($ch);
}
And here's second part of the code in insertnewuser.php page:

Code: Select all

ignore_user_abort();

$fp = fopen("log2.txt", "a");
require("config.php");
if ($_GET['key'] != $key) {
	fwrite($fp, "Cheating detected!\n\n\n");
	die("Cheating detected!");
}

$pid = intval($_GET['p']);
$name = $_GET['name'];
$email =$_GET['email'];
$egold = $_GET['egold'];

if ($pid == 1) {
	$dbhost2 = "";  // Your MySQL database host (no / at the end)
	$dbname2 = "";  // Your database name to use for your cycler
	$dbusername2 = "";  // Your database username
	$dbpassword2 = "";  // Your database password
	$connect = mysql_connect($dbhost2, $dbusername2, $dbpassword2);
	mysql_select_db($dbname2);
	$url2 = "$url/update.php?p=1";
}
elseif ($pid == 2) {
	$dbhost2 = "";  // Your MySQL database host (no / at the end)
	$dbname2 = "";  // Your database name to use for your cycler
	$dbusername2 = "";  // Your database username
	$dbpassword2 = "";  // Your database password
	$connect = mysql_connect($dbhost2, $dbusername2, $dbpassword2);
	mysql_select_db($dbname2);
	$url2 = "$url/update.php?p=2";
}
elseif ($pid == 3) {
	$dbhost2 = "";  // Your MySQL database host (no / at the end)
	$dbname2 = "";  // Your database name to use for your cycler
	$dbusername2 = "";  // Your database username
	$dbpassword2 = "";  // Your database password
	$connect = mysql_connect($dbhost2, $dbusername2, $dbpassword2);
	mysql_select_db($dbname2);
	$url2 = "$url/update.php?p=3";
}

$sql = "SELECT id FROM `user` WHERE stage=1 ORDER BY id DESC LIMIT 1";
$result = mysql_query($sql);
$re = mysql_fetch_array($result);
$ree = $re['id'] + 1;
$sql = "INSERT INTO `user` (id,name,email,egold,stage) VALUES ('$ree','$name','$email','$egold',1)";
$result = mysql_query($sql);
$sql = "UPDATE statistics SET total = total + 1 WHERE id=1";
$result = mysql_query($sql);
mysql_close($connect);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$a = curl_exec($ch);
if (!$a) {
	curl_exec($ch);
}
curl_close($ch);
This should add a new user to one of the databases depending on $pid value (1, 2 or 3), but it doesn't. I don't know, maybe this page isn't executed through curl in the first page, because when I disable $key check and go to insertnewuser.php?name=dfsdf... directly in my browser, the user with the data is added.

Thanks for any help.

Posted: Fri Mar 09, 2007 2:24 pm
by RobertGonzalez
Can you put some error checking into your code and post back what errors are being thrown?

Posted: Sat Mar 10, 2007 4:07 am
by arukomp
ahhh.... I just needed to add "global $p;" in one of my functions. Because of that the function otherprogram() didn't execute and nothing happened...

I have to say this is kind of stupid mistake :) I personally hate that I need to set globals to be able to use variables in my functions...

Any way, thanks Everah for pointing me to look for errors. I've added some code to log every move (what has been executed and what hasn't been). I've found where it stopped and had a better look at that place and then I found the problem...

Posted: Sat Mar 10, 2007 7:20 am
by feyd
Pass the data into the function.

Posted: Sat Mar 10, 2007 7:27 am
by arukomp
But it's about 10 variables... And there are about 10 places where script calls that function, so there would be more code with that way

Posted: Sat Mar 10, 2007 7:32 am
by feyd
That may signal an opportunity for refactoring. ;)

It's better to pass in information then for the function to require a certain global to exist to function correctly.

Posted: Sat Mar 10, 2007 7:44 am
by arukomp
ok, thanks for your help :)