Jump to content


PHP help.


6 replies to this topic

#1 Nike

    Young Padawan

  • Members
  • Pip
  • 204 posts
  • Location:Ohio
  • Interests:Controlling the human and and duck race.

Posted 26 August 2006 - 08:08 PM

Alright, all I am trying to do is this.

[Link]
Under it says how many times it was clicked.

Is that so hard? I mean come on. I've been following tutorials. I can't figure it out.

<html>
<body bgcolor="blue">
<?

$url = $_GET;
$date = date("d/m/y"); // Grabs date

/* MYSQL CONNECT */
$db_host = "localhost";
$db_username = "nike"; // Will most likely need your username as a prefix
$db_password = "oreo";
$db_name = "nike_test"; // Will most likely need your username as a prefix
mysql_connect($db_host,$db_username,$db_password) or die(mysql_error()); // This just connects to your server, will give an error message if it cant
mysql_select_db($db_name) or die(mysql_error()); // This selects the database to work on, this will give an error if it cant aswell

$query = "SELECT * FROM clicks WHERE url='$url'"; // Query to find the url if it already exists
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
$clicks = "$r[clicks]";
$clicks++; // Adds one click to the total clicks
$end = "okay"; // This just tells the script that the url already exists and doesnt need to add a new entry
$query = "UPDATE `clicks` SET `date` = '$date', `clicks` = '$clicks' WHERE `id` = '$r[id]' LIMIT 1"; // Query to add a click to the url
mysql_query($query); // Add one more click to the url
}
if ($end != okay) { // If the url isnt already in the databse run the following lines
$query = "INSERT INTO clicks (url, clicks, date)
VALUES ('$url','1','$date')"; // Adds the url to the databse to start recoding clicks
mysql_query($query);
}
header("Location: $url"); // Go To the link that you clicked on



// For a tutorial on displaying the clicks with a nice per page system please ask me to add it tongue.gif
?>

</body>
</html>

I followed that this tutorial. [url="http://zulumonkey.org/?id=tutorials&page=comment&oid=24"]http://zulumonkey.or...a...ment&oid=24

I keep getting this error.

Warning: Cannot modify header information - headers already sent by (output started at /home/nike/public_html/clicks/click.php:3) in /home/nike/public_html/clicks/click.php on line 31

Somebody help.

#2 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 26 August 2006 - 08:14 PM

header("Location: $url"); // Go To the link that you clicked on

You've got that in the <body></body> of your page.

Quote

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
http://www.php.net/m...tion.header.php

if you need it down there, try echo'g a meta refresh with 0 seconds.

#3 Nike

    Young Padawan

  • Members
  • Pip
  • 204 posts
  • Location:Ohio
  • Interests:Controlling the human and and duck race.

Posted 26 August 2006 - 08:22 PM

View PostSpatialVisionary, on Aug 26 2006, 09:14 PM, said:

header("Location: $url"); // Go To the link that you clicked on

You've got that in the <body></body> of your page.

Quote

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
http://www.php.net/m...tion.header.php

if you need it down there, try echo'g a meta refresh with 0 seconds.

I'm sorry, I'm very confused.

How would I add header("Location: $url"); into my page?

I only need it for one link.

#4 cheerio

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Gender:Male

Posted 26 August 2006 - 08:44 PM

get rid of
<html>
<body bgcolor="blue">

or use ob_start()

Edited by cheerio, 26 August 2006 - 08:44 PM.


#5 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 26 August 2006 - 08:45 PM

View PostNike, on Aug 26 2006, 08:22 PM, said:

I'm sorry, I'm very confused.

How would I add header("Location: $url"); into my page?

I only need it for one link.

well, since the page doesn't appear to be displaying anything, just redirecting...

<?

$url = $_GET[url];
$date = date("d/m/y"); // Grabs date

/* MYSQL CONNECT */
$db_host = "localhost";
$db_username = "nike"; // Will most likely need your username as a prefix
$db_password = "oreo";
$db_name = "nike_test"; // Will most likely need your username as a prefix
mysql_connect($db_host,$db_username,$db_password) or die(mysql_error()); // This just connects to your server, will give an error message if it cant
mysql_select_db($db_name) or die(mysql_error()); // This selects the database to work on, this will give an error if it cant aswell

$query = "SELECT * FROM clicks WHERE url='$url'"; // Query to find the url if it already exists
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
$clicks = "$r[clicks]";
$clicks++; // Adds one click to the total clicks
$end = "okay"; // This just tells the script that the url already exists and doesnt need to add a new entry
$query = "UPDATE `clicks` SET `date` = '$date', `clicks` = '$clicks' WHERE `id` = '$r[id]' LIMIT 1"; // Query to add a click to the url
mysql_query($query); // Add one more click to the url
}
if ($end != okay) { // If the url isnt already in the databse run the following lines
$query = "INSERT INTO clicks (url, clicks, date)
VALUES ('$url','1','$date')"; // Adds the url to the databse to start recoding clicks
mysql_query($query);
}
header("Location: $url"); // Go To the link that you clicked on

?>

try removing the HTML components as I have done here.

Edited by SpatialVisionary, 26 August 2006 - 08:47 PM.


#6 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 August 2006 - 08:52 PM

Yes, you have three options.
Delete the '<html><body bgcolor="blue">'.
Use obstart().
Or use echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';.

Options 1 and 2 would be easiest in my opinion.

Opps, I stayed on the reply page too long, lol, my point(s) have already been given. :ph34r:

Edited by Demonslay, 26 August 2006 - 08:53 PM.


#7 Nike

    Young Padawan

  • Members
  • Pip
  • 204 posts
  • Location:Ohio
  • Interests:Controlling the human and and duck race.

Posted 26 August 2006 - 08:54 PM

Now it is just a blank page.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users