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...

Link to comment
Share on other sites

<!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

Link to comment
Share on other sites

 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.

Edited by sharpcode
Link to comment
Share on other sites

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 -.-

Edited by sharpcode
Link to comment
Share on other sites

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.

Edited by Zane
Link to comment
Share on other sites

  • 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)

Edited by sharpcode
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.