Welcome to The Forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads

PHP Help! Urgent!


---------
 Share

Recommended Posts

PHP's too fun.

 

http://pastebin.com/La8255fh

 

Try that out, just changed a few things, can be viewed by "view the difference".

 

Thanks a million! It works and adds +1 to the user's IP's cookienum each time the user visits/refreshes the page it it is meant to! :D

Currently when someone views the page it only says "Cookies have been added". It only shows up in the database, and I'd also like it to display the IP's "cookienum" on the page.

 

The page is at: http://enigmoweb.com/hg/command.jpg/cookie-data.php

Link to comment
Share on other sites

Added it after it says "cookies have been added"; look for "ECHO:".

http://pastebin.com/eeT0YbeE

 

The variable to hold their cookie count is set to; $CLIENT_TOTAL_COOKIES by Papa John.

 

Also; you might as well change "cookienum" to an int field, since there's no text being stored there.

 

Oh, and no problem, message me on here or Steam if you ever need any help in PHP, not too bad at Java either.

Love them both.

Link to comment
Share on other sites

Added it after it says "cookies have been added"; look for "ECHO:".

http://pastebin.com/eeT0YbeE

 

The variable to hold their cookie count is set to; $CLIENT_TOTAL_COOKIES by Papa John.

 

It worked perfectly. :) Although I have now come across one big problem. If the users ip isn't already manually entered into the database, it will display a blank page and the query to add the users ip won't run. I had replaced REMOTE_IP with 1234 to see if it works, with no result.

	/* If it doesn't exist insert */
} else {

/* Insert record into database */
if( mysql_query("INSERT INTO `cookies_2403465`.`cookies` (`ip`, `cookienum`) VALUES ('1234', '1');"))
echo "Your record has been added!";
else
die(mysql_error());
}

Edited by ENIGM0
Link to comment
Share on other sites

Guest The_Monkey
It worked perfectly. :) Although I have now come across one big problem. If the users ip isn't already manually entered into the database, it will display a blank page and the query to add the users ip won't run. I had replaced REMOTE_IP with 1234 to see if it works, with no result.

    /* If it doesn't exist insert */
} else {

   /* Insert record into database */
   if( mysql_query("INSERT INTO `cookies_2403465`.`cookies` (`ip`, `cookienum`) VALUES ('1234', '1');"))
   echo "Your record has been added!";
   else
   die(mysql_error());
}

 

The @ sign is your friend.

Link to comment
Share on other sites

Wait Wait Wait...

 

First its @mysql_query(...

 

And second you don't need the database name "cookies_2403465" included in the insert statement when we selected the database at the top...

 

Have done everything you said, still returns a blank page and no rows were made in the database. If you want access to my DB, just say and i'll give you the login panel and info. Sorry to be such a pain..

 

 

<?php
/* Start Config */

define("DATABASE_USERNAME", "cookies"); // Database Username
define("DATABASE_PASSWORD", "**"); // Database Password
define("DATABASE_HOST", "sql**.bravehost.com"); // Database Host
define("DATABASE_NAME", "cookies_***3465"); // Database Name
define("REMOTE_IP", $_SERVER['REMOTE_ADDR']); // Client's IP

/**
* Database Note:
*  Table should be called: cookies
*  Two text rows called: ip & cookienum
*/

/* End Config */

/* Connect to database */
mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
mysql_select_db(DATABASE_NAME) or die(mysql_error());

/* Check Database For Record */
$query = "SELECT * FROM cookies WHERE ip = '" . REMOTE_IP . "' LIMIT 1";
$result = mysql_query($query) or die(mysql_error());

/* If the record exists */
if( $result ){

$row = mysql_fetch_array($result) or die(mysql_error());
$CLIENT_TOTAL_COOKIES = $row['cookienum'] + 1;

/* Since the record exists, lets update the amount of "cookies" they have */
if( mysql_query("UPDATE cookies SET cookienum = cookienum + 1 WHERE ip = '" . REMOTE_IP . "' LIMIT 1") )
echo "You have been given 1 cookie!";
else
die(mysql_error());

/* ECHO: Show client's current cookies */
echo "<br /><b>Total Cookies: $CLIENT_TOTAL_COOKIES</b>";

/* If it doesn't exist insert */
} else {

/* Insert record into database */
if( @mysql_query("INSERT IGNORE INTO cookies ( ip, cookienum ) VALUES( '" . REMOTE_IP . "', '1'") )
echo "Your record has been added!";
else
die(mysql_error()); 

}
?>

Edited by ENIGM0
Link to comment
Share on other sites

Have done everything you said, still returns a blank page and no rows were made in the database. If you want access to my DB, just say and i'll give you the login panel and info. Sorry to be such a pain..

 

 

<?php
/* Start Config */

define("DATABASE_USERNAME", "cookies"); // Database Username
define("DATABASE_PASSWORD", "**"); // Database Password
define("DATABASE_HOST", "sql**.bravehost.com"); // Database Host
define("DATABASE_NAME", "cookies_***3465"); // Database Name
define("REMOTE_IP", $_SERVER['REMOTE_ADDR']); // Client's IP

/**
* Database Note:
*  Table should be called: cookies
*  Two text rows called: ip & cookienum
*/

/* End Config */

/* Connect to database */
mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
mysql_select_db(DATABASE_NAME) or die(mysql_error());

/* Check Database For Record */
$query = "SELECT * FROM cookies WHERE ip = '" . REMOTE_IP . "' LIMIT 1";
$result = mysql_query($query) or die(mysql_error());

/* If the record exists */
if( $result ){

$row = mysql_fetch_array($result) or die(mysql_error());
$CLIENT_TOTAL_COOKIES = $row['cookienum'] + 1;

/* Since the record exists, lets update the amount of "cookies" they have */
if( mysql_query("UPDATE cookies SET cookienum = cookienum + 1 WHERE ip = '" . REMOTE_IP . "' LIMIT 1") )
echo "You have been given 1 cookie!";
else
die(mysql_error());

/* ECHO: Show client's current cookies */
echo "<br /><b>Total Cookies: $CLIENT_TOTAL_COOKIES</b>";

/* If it doesn't exist insert */
} else {

/* Insert record into database */
if( @mysql_query("INSERT IGNORE INTO cookies ( ip, cookienum ) VALUES( '" . REMOTE_IP . "', '1'") )
echo "Your record has been added!";
else
die(mysql_error()); 

/* ECHO: Show client's cookies after inserting into DB (any errors, cookie will be set to 0) */
$CLIENT_TOTAL_COOKIES = mysql_num_rows($result) >= 0 ? mysql_num_rows($result) : 0;
echo "<br /><b>Total Cookies: $CLIENT_TOTAL_COOKIES</b>";

}
?>

 

Changes cmmented with "ECHO:" again.

Calling the row count after inserting new data.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share