Jump to content

seany123

Members
  • Posts

    1,053
  • Joined

  • Last visited

Posts posted by seany123

  1. I have a star rating system which uses this update php and js:

     

    PHP

    if($_GET['do']=='rate'){
    // do rate
    rate($show, $_GET['id']);
    } else if($_GET['do']=='getrate'){
    // get rating
    getRating($show, $_GET['id']);
    }
    
    // function to retrieve
    function getRating($show, $url){
    $rs=@mysql_fetch_array($result);
    // set width of star
    $rating = (@round($rs[value] / $rs[counter],1)) * 20; 
    echo $rating;
    }
    
    // function to insert rating
    function rate($show, $url){
    global $dbh;
    $text = strip_tags($_GET['']);
    $update = "update `" . $show . "_episodes` set counter = counter + 1, value = value + ".$_GET['rating']."  where md5(url)='".$url."'";
    $result = mysql_query($update);
    

     

    JS

    // JavaScript Document
    $(document).ready(function() {
    	// get rating function
    	function getRating(show, id){
    		$.ajax({
    			type: "GET",
    			url: "../update.php",
    			data: "do=getrate&id="+id+"&show="+show,
    			cache: false,
    			async: false,
    			success: function(result) {
    				// apply star rating to element
    				$("#current-rating-"+id+"").css({ width: "" + result + "%" });
    			},
    			error: function(result) {
    				alert("some error occured, please try again later");
    			}
    		});
    	}
    	// link handler
    	$('.ratelinks li a').click(function(){
    		// get the parent id
    		var idStar = $(this).parent().parent().attr('id');
    		var show = $(this).parent().parent().attr('show');
    		$.ajax({
    			type: "GET",
    			url: "../update.php",
    			data: "rating="+$(this).text()+"&do=rate&show="+show+"&id="+idStar,
    			cache: false,
    			async: false,
    			success: function(result) {
    				// remove #ratelinks element to prevent another rate
    				$("#ratelinks").remove();
    				// get rating after click
    				getRating(show, idStar);
    			},
    			error: function(result) {
    				alert("some error occured, please try again later");
    			}
    		});
    
    	});
    });
    

     

    Now i decided i wanted to show the percentage so i added this to the PHP:

     

    // function to retrieve Percentage
    function getPercentage($show, $url){
    $per=@mysql_fetch_array($result);
    // set percentage
    if ($per[counter] >= 1){
        $percentage = (round($per[value] * 100) / ($per[counter]*5));
        echo "( <FONT COLOR=RED>".$percentage."%</FONT>  from ".$per[counter]." votes )";
        }
        else if ($per[counter] < 1){
        echo "(No Votes Yet!)";
        }
    }
    

     

    Which does work, but requires a page reload to make it show the new percentage... (whereas the stars update automatically)

     

    so how can i set $per[counter], $per[value] and $percentage? using the javascript?

     

    Seany

  2. What i have found is that you cant have DISTINCT in a query that you are SELECT * FROM

     

    it has to be SELECT name FROM

     

    but this is very annoying, i want to select * the values, but some of the values wont pass the DISTINCT test... because they arnt unique...

     

    so im slightly confused as to what to do now... maybe i could make a query to collect all the data from the DISTINCT query.. hmm

  3. <?php
    $path = "www.DOMAINHERE.com/images/showlogos/".$showNAME."_logo.jpg";
    if (file_exists($path)){
        echo "YES";
    ?>
    <a href="index.php"><img src="/images/showlogos/<?=$showNAME?>_logo.jpg" width="190" height="62" /></a><br /><br />
    <?php
    }
    else {
        echo "NO!";
        echo $path;
    }
    ?>
    

     

    the result is echoing out NO! which means the file doesnt exist... however when i c+p the echo'd $path into my address bar, it shows the image..

     

    Thanks

  4. using a Single ' wont work becuase some of the strings use the single quotes.. which would give the same result.

     

    manually adding backslashes again wont be economical because the strings that im having this problem with are in my database and there are atleast 50,000 strings.

     

    is there no way of just stating that everything inside the initial ""s should be classed as normal text then?

  5. Is there any function i can use to make this T STRING error stop?

     

    $desc = "this is a "test" this is a test";

     

    i just want it so everything inside the initial 2 "s are classed as just normal text or whatever?

     

    Thanks

  6. Okay i already have pasted the entire code at the top, however i will paste the new edited code:

     

    
    <?php 
    
    require('connect.php');
    
        $get_query = mysql_query("SELECT * FROM `links` WHERE `processed`='0'");
        if ($row = mysql_fetch_array($get_query)){
    
            $show = $row['show'];
            $url = $row['url'];
            
        	$table_name = mysql_real_escape_string($show); // The table name to place the shows into
        	$links = array($url); // You can add your links into an array
        
                $sql = "DROP TABLE IF EXISTS `".$table_name."`";
        
                mysql_query($sql);
        
                
                //ONLY USE THIS WHEN EPISODES LIST IS EMPTY
        
                //$sql = "DROP TABLE IF EXISTS `".$table_name."_episodes`";
        
                //mysql_query($sql);
        
                //ONLY USE THIS WHEN EPISODES LIST IS EMPTY
        
                 
        
                $sql = "CREATE TABLE IF NOT EXISTS `".$table_name."` (
        
                          `season_id` int(11) NOT NULL,
        
                          `episode_id` int(11) NOT NULL,
        
                          `episode_name` varchar(255) NOT NULL,
        
                          `episode_desc` varchar(2500) NOT NULL
        
                       )";
        
                mysql_query($sql);
        
                
        
                $sql2 = "CREATE TABLE IF NOT EXISTS `".$table_name."_episodes` (
        
                          `season_id` int(11) NOT NULL,
        
                          `episode_id` int(11) NOT NULL,
        
                          `url` varchar(255) NOT NULL,
        
                          `link_name` varchar(255) NOT NULL,
        
                          `verified` tinyint(1) NOT NULL DEFAULT '0',
        
                          `processed` tinyint(1) NOT NULL,
        
                          UNIQUE KEY `url` (`url`)
        
                        )";
        
                mysql_query($sql2);        
        
            
        
            //Delets all records and changed auto-increment to 1
        
            mysql_query("DELETE FROM `" . $table_name . "`");
        
            mysql_query("ALTER TABLE `" . $table_name . "` AUTO_INCREMENT=1");
        
            
        
        	// Or you can add them like this
        
        	// $links[] = 'http://www.imdb.com/title/tt0108778/episodes';
        
        	// $links[] = 'http://www.imdb.com/title/tt0108778/episodes';
        
        	// and so on and so forth
        
        	
        
        	foreach( $links as $link ) {
            
        		$html = file_get_contents($link);
        
        		preg_match_all( '/<table(.*?)>(.*?)<\/table>/is', $html, $results );
        
        		$elements = $results[2];
        
        
        
        		foreach( $elements as $html ) {
        
        			if( strstr( $html, 'episode_slate_container' ) || strstr($html, '<h3>Season' ) ) {
        
        				preg_match_all( '/<h3>(.*?)<\/h3>/is', $html, $h3 );
        
        				preg_match( '/([0-9].*?),/is', $h3[1][0], $season);
        
        				preg_match( '/Episode(.*?)<\/a>/is', $h3[1][0], $episode );
        
        				preg_match( '/([0-9].*?):/is', $episode[1], $episode_number );
        
        
        
        				$season_number = str_ireplace( ',','', trim( $season[0] ) );
        
        				$episode_name = strip_tags( trim( $episode[0] ) );
        
        				$episode_number = trim( $episode_number[1] );
        
        				
        
        				preg_match_all( '/<br>(.*?)<\/td>/is', $html, $text );
        
        				
        
        				//$content = strip_tags( trim( $text[1][0] ) );
        
        				$episode_desc = strip_tags( trim( $text[1][0] ) );
        
        				
        
        				// Insert the data into the database (Comment out this line and uncomment those others below if you want to debug)
        
        				mysql_query("INSERT INTO " . $table_name . " (season_id,episode_id,episode_name,episode_desc) VALUES('".@mysql_escape_string($season_number)."','".@mysql_escape_string($episode_number)."','".@mysql_escape_string($episode_name)."','".@mysql_escape_string($episode_desc)."') "); 
        
        				
        
        				// I used the show info for debugging just to make sure the content was extracted correctly you can remove this line if you want
        
        				//$showInfo[] = array( $season_number, $episode_number, $episode_name, $episode_desc );
        
        			}
        
        		}
        
        		
        
        		// You dont need these two lines but I kept them in just in case you wanted to debug it.
        
        		//print_r($showInfo);
        
        		//exit;
        
        	}
        
        
        
        	function file_get_contents( $url ){
        
        		if ( !function_exists( 'file_get_contents' ) || ini_get( 'allow_url_fopen' ) == 0 || ini_get( 'allow_url_fopen' ) == 'off' || ini_get( 'allow_url_fopen' ) == '0' ) {
        
        		    $c = curl_init ( );
        
        		    curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 );
        
        		    curl_setopt( $c, CURLOPT_URL, $url );
        
        		    $contents = curl_exec( $c );
        
        		    curl_close( $c );
        
        		
        
        		    return $contents;
        
        		}
        
        		else {
        
        			$contents = @file_get_contents( $url );
        
        			
        
        			return $contents;
        
        		}         
        	}
            mysql_query("UPDATE `imdb_links` SET `processed`=1 WHERE `url`='$url'");
        }
    
    ?>
    

  7. "Fatal error: Cannot redeclare file_get_contents()"

     

    which is this:

     

    "function file_get_contents($url) "

     

    You don't need the function keyword before your call; it's a built in function and php thinks you're trying to re-write it

     

    without the function its errors out saying unexpected "{"

     

    putting the function back in actually does make it work however i have a problem that one of the $link in the db is a number... so its not inserting into that table.

  8. 1. if you are expecting more then one row to be selected, use a while loop instead of an if statement..

    2. you cannot echo an array, as it will output "Array" you need to use a foreach loop to isolate each value/key of an array..

    3. do a print_r($links) and post the output..

     

    1. no i want 1 row at a time to be selected, then at the bottom of the script ill add a refresh function.

     

    2. im using the foreach loop...?

     

    3. Array ( [0] => $url )

     

    (im confused as to why its showing like that on this forum)... ill space it out.

     

    Array ( [ 0 ] = > $url )

     

     

    Also inside the foreach loop i tried this:

     

    echo $links[0];

     

    which outputted: $url

  9. well i have already done something like that:

     

    
        $get_query = mysql_query("SELECT * FROM `links` WHERE `processed`='0'");
        if ($row = mysql_fetch_array($get_query)){
    
            $show = $row['show'];
            $url = $row['url'];
            
        	$table_name = mysql_real_escape_string('$show'); // The table name to place the shows into
        	$links = array('$url'); // You can add your links into an array
    
    

     

     

    but when echoing $links it just returns "array"

     

     

    and $links is used further down the script:

     

        	foreach( $links as $link ) {
        
        		$html = get_file_contents($link);
    

     

    where it will throw out errors...

     

    Fatal error: Call to undefined function get_file_contents()

  10. Basically i have this code:

     

    <?php 	
    ##############################	
    ######### CONFIG #############	
    ##############################	
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    
    $dbname = 'series';
    mysql_select_db($dbname);	
    #############################
    
    
    
    $table_name = mysql_real_escape_string('COL1HERECOL1HERECOL1HERE');
    
            // You can add your links into an array like this 
       $links = array(COL2HERECOL2HERECOL2HERE'); 
        
            $sql = "DROP TABLE IF EXISTS `".$table_name."`";
            mysql_query($sql);
            
            //ONLY USE THIS WHEN EPISODES LIST IS EMPTY
            //$sql = "DROP TABLE IF EXISTS `".$table_name."_episodes`";
            //mysql_query($sql);
            //ONLY USE THIS WHEN EPISODES LIST IS EMPTY
             
            $sql = "CREATE TABLE IF NOT EXISTS `".$table_name."` (
                      `season_id` int(11) NOT NULL,
                      `episode_id` int(11) NOT NULL,
                      `episode_name` varchar(255) NOT NULL,
                      `episode_desc` varchar(2500) NOT NULL
                   )";
            mysql_query($sql);
            
            $sql2 = "CREATE TABLE IF NOT EXISTS `".$table_name."_episodes` (
                      `season_id` int(11) NOT NULL,
                      `episode_id` int(11) NOT NULL,
                      `url` varchar(255) NOT NULL,
                      `link_name` varchar(255) NOT NULL,
                      `verified` tinyint(1) NOT NULL DEFAULT '0',
                      `processed` tinyint(1) NOT NULL,
                      UNIQUE KEY `url` (`url`)
                    )";
            mysql_query($sql2);        
        
        //Delets all records and changed auto-increment to 1
        mysql_query("DELETE FROM `" . $table_name . "`");
        mysql_query("ALTER TABLE `" . $table_name . "` AUTO_INCREMENT=1");
        
    // Or you can add them like this
    // $links[] = 'http://www.imdb.com/title/tt0108778/episodes';
    // $links[] = 'http://www.imdb.com/title/tt0108778/episodes';
    // and so on and so forth
    
    foreach( $links as $link ) {
    	$html = get_file_contents($link);
    	preg_match_all( '/<table(.*?)>(.*?)<\/table>/is', $html, $results );
    	$elements = $results[2];
    
    	foreach( $elements as $html ) {
    		if( strstr( $html, 'episode_slate_container' ) || strstr($html, '<h3>Season' ) ) {
    			preg_match_all( '/<h3>(.*?)<\/h3>/is', $html, $h3 );
    			preg_match( '/([0-9].*?),/is', $h3[1][0], $season);
    			preg_match( '/Episode(.*?)<\/a>/is', $h3[1][0], $episode );
    			preg_match( '/([0-9].*?):/is', $episode[1], $episode_number );
    
    			$season_number = str_ireplace( ',','', trim( $season[0] ) );
    			$episode_name = strip_tags( trim( $episode[0] ) );
    			$episode_number = trim( $episode_number[1] );
    
    			preg_match_all( '/<br>(.*?)<\/td>/is', $html, $text );
    
    			//$content = strip_tags( trim( $text[1][0] ) );
    			$episode_desc = strip_tags( trim( $text[1][0] ) );
    
    			// Insert the data into the database (Comment out this line and uncomment those others below if you want to debug)
    			mysql_query("INSERT INTO " . $table_name . " (season_id,episode_id,episode_name,episode_desc) VALUES('".@mysql_escape_string($season_number)."','".@mysql_escape_string($episode_number)."','".@mysql_escape_string($episode_name)."','".@mysql_escape_string($episode_desc)."') "); 
    
    			// I used the show info for debugging just to make sure the content was extracted correctly you can remove this line if you want
    			//$showInfo[] = array( $season_number, $episode_number, $episode_name, $episode_desc );
    		}
    	}
    
    	// You dont need these two lines but I kept them in just in case you wanted to debug it.
    	//print_r($showInfo);
    	//exit;
    }
    
    function get_file_contents( $url )
    {
    	if ( !function_exists( 'file_get_contents' ) || ini_get( 'allow_url_fopen' ) == 0 || ini_get( 'allow_url_fopen' ) == 'off' || ini_get( 'allow_url_fopen' ) == '0' ) {
    	    $c = curl_init ( );
    	    curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 );
    	    curl_setopt( $c, CURLOPT_URL, $url );
    	    $contents = curl_exec( $c );
    	    curl_close( $c );
    
    	    return $contents;
    	}
    	else {
    		$contents = @file_get_contents( $url );
    
    		return $contents;
    	}
    }
    ?>
    

     

    i also have a myql database which has value in:

     

    $table

    $url

     

    basically i want to be able to put the above values into line 17 & 20. (where i have spammed COL1HERE & COL2HERE)

     

    after the value are put in i want the entire script to run, then i want it to put the nexts db rows values in... until all the rows in the DB have been done.

     

    How would i go about this?

  11. it is echoing what i type into the form...

    -SB

     

    okay well, echo out the $password again and go into phpmyadmin and copy that as your password...

     

    then try again and see if it works...

     

    however there isnt anything we can do for you to fix this from happening again, until you can provide us with the register.php etc file.

  12. seany,

    how do i user $error? im assuming i insert it into the script but where?

    -SB

     

    you already have it in your script:

     

    $error = "Bad Login";
    

    and i was just wondering what your doing with it...

     

    try echoing

    echo $_POST['password'];
    

    if that comes out correct (without the md5 encryption.), you need to post the script that registers users into the db.

  13. seany,

    Would this though ultimately cause the page to continually redisplay the login regardless of correct / incorrect credentials?

    -SB

     

     

    actually no,

     

    if (mysql_num_rows($result) != 1) {
    $error = "Bad Login";
        include "login.html";
    
    }
    

     

    should actually pick this up, however you still need to sort your md5($password) problem

     

    you could try

     

    if (mysql_num_rows($result) < 1) {
    $error = "Bad Login";
        include "login.html";
    
    }
    

     

    however its essentially doing the same thing..

     

     

    just out of curiousity, whats $error doing?

  14. md5 is a way to encrypt the string so if someone gains access to your db they cant necessarily steal all your account details...

     

    double md5 would only occur if you have done something like this md5(md5($password))

     

    your problem appears to be in the register.php

     

    because it doesnt seem to be encrypting correctly.

     

    also the db field needs to be 32 length

  15. OK so this is an interesting development...lol

    It echos the username ok but the password which yes is in md5 format both in the dbase and the login script which im sure you noticed.

    -SB

     

     

    sorry i didnt understand that last post too well... so it does echo them correctly or not?

     

     

    You don't need to put parentheses around a string value to assign it to a variable, even if it is a query string. Same goes for include.

     

    Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value.

    hehe i wasn't too sure about that, but it was worth suggesting just in case :P

  16. Yeah, both....

    Im assuming this is not good? lol

     

    the 0 is basically saying that it found 0 results when looking through your table...

     

    replace the last echo with:

     

    echo $username;
    echo "<br/>";
    echo $password;
    

     

    and make sure it exactly the same as the credentials in the database... (the passwords in your db should be MD5 encrypted)

     

    put brackets around your query.. and use `s and also and might have to be in caps or use && see below.

     

    $query = ("select * from `users` where `username`='$username' && `password`='$password'");
    

     

    i dont know if this effects anything but its the right way of doing it so its worth a try...

     

    also do the same for includes

     

    include ("example.php");
    

     

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