Jump to content

Sessions and update sql


sharpcode

Recommended Posts

[b]Warning[/b]: session_start() [[url="http://dontstopdreaming.net/function.session-start"]function.session-start[/url]]: Cannot send session cookie - headers already sent by (output started at /home/public_html/video.php:5) in [b]/home/public_html/video.php[/b] on line [b]6[/b]

[b]Warning[/b]: session_start() [[url="http://dontstopdreaming.net/function.session-start"]function.session-start[/url]]: Cannot send session cache limiter - headers already sent (output started at /home/public_html/video.php:5) in [b]/home/public_html/video.php[/b] on line [b]6[/b]

 

its the first line as well... any ideas? looking at tutorials now and it seems i am doing it right and have no extra lines or anything...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

       <?php
           session_start();

      	 $video = $_REQUEST['code'];

           error_reporting(E_ALL); 

	    //..... then rest of code

 

thats the top of the file

 if(!isset($_SESSION['viewed']))
{
  $views = $views + 1;
  mysql_query("UPDATE videos SET views = $views WHERE code = '$video'");
  $_SESSION['viewed'] = 1;
}

 

Still seems to not be working. In the database i will check what one of the video pages is and say its 13 i will view it and it will still print 13. Then i refresh twice or so and it will turn into 15 and then wont change after that. Then once i move to another video page same thing.

 

Edit: Putting session_start at the very start of the file worked by the way thanks Psycho.

sorry for this post but couldn't edit either of my last ones fro some reason...

 

anyway i have done the following instead...

$views = $row['views'];	

if(!session_is_registered($title))
{
$views++;
mysql_query("UPDATE videos SET views = $views' WHERE code = '$video'");
session_register($title);

}
echo $views;

 

it seems to work except the first time i view the page it will update right but moment i go back or refresh it will return to the original value and stay that way. So a bit closer but also stranger :(

 

edit: fixed... notive the ' after $views? well yeh i just did lol -.-

A better idea would be to add the extra view in your SQL update query

UPDATE videos SET views = views + 1 WHERE .....

 

 

...NOTE.. and yes, there is no $view variable in that query. All that query will do is increment the views field by one.

  • 2 weeks later...

remarked as not solved because its playing up again...

 

if(!session_is_registered($title))
{
    mysql_query("UPDATE videos SET views = views + 1 WHERE code = '$video'");
    session_register($title);            
}

 

not sure what the problem is and title is a variable

 

edit: problem is like in the past doesn't update the view when i click on the page. But then when i refresh will skip any number (so far has been from 3 or even as high as 6)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.