-
Posts
1,053 -
Joined
-
Last visited
Posts posted by seany123
-
-
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[season_id]=(SELECT Max([season_id]) FROM `24`)' at line 1
-
im trying to return the highest value in my table from the season_id column
this is the code i have:
$test = mysql_query("SELECT * FROM `$show` WHERE [season_id]=(SELECT Max([season_id]) FROM `$show`)");
please advise?
-
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
-
so there is no work arounds to get this to work?
-
oh, thanks that worked!
-
<?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
-
Can anyone tell me why this isnt working?
$query1 = mysql_query("SELECT DISTINCT * FROM `series` WHERE `name` LIKE 'A%' ORDER BY `name` ASC LIMIT 12");
it should not display duplicates, but it does...
-
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?
-
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
-
Using what you have given me i have made the script work with the database.
the only problem i have now is that when $show is a number EG: 24
-
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'"); } ?>
-
"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.
-
okay i have changed them all...
but im getting this error:
"Fatal error: Cannot redeclare file_get_contents()"
which is this:
"function file_get_contents($url) "
-
removing the quotes did give this output:
Array ( [ 0 ] => http://www.urltest.com )
btw its file_get_contents not get_file_contents
i dont think that correct. as this script works perfectly fine when i just insert the values in the array, (rather than getting from db)
-
What version of php do you have?
I ask because of this error:
Fatal error: Call to undefined function get_file_contents()
Usually that's because the version is less than 5.x
currently running: PHP Version 5.3.5
-
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
-
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()
-
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?
-
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.
-
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.
-
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?
-
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
-
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
-
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");
How to set new values to a Variable.
in Javascript Help
Posted
I have a star rating system which uses this update php and js:
PHP
JS
Now i decided i wanted to show the percentage so i added this to the PHP:
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