Jump to content

Recommended Posts

i am trying to insert some info into a mysql database but it just wont work :(

<?php
include "lastRSS.php";
function connect()
{
$username="root";
$password="";
$database="rssreader";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
}
function rsstosql($url,$table)
{
connect();
$rss = new lastRSS;
$rss->cache_dir = './temp';
$rss->cache_time = 1200;
if ($rs = $rss->get($url)) {
	$time;
	foreach($rs['items'] as $item) {
			if ($item['description']==null)
			{	
				$time = $item['title'];
			}else{
				$title = substr($item['title'],2);
				$desc = $item['description'];
				$sql = "INSERT INTO `$table` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, $time, $title, $desc, null)";
				echo $sql."<br>";
				mysql_query($sql);
				}

		}	

	}
else {
die("Error: It's not possible to reach RSS file...\n");
}
mysql_close();
}
rsstosql('http://www.tvrage.com/myrss.php',"showstoday");
?> 

also this is what the SQL query's say

INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 08:00 pm, Deal Or No Deal (US) (02x68), Episode 107, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 08:00 pm, On the Lot (01x05), 1 of 15 Directors Voted Off, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 09:00 pm, Deadliest Catch (03x10), Trials of the Greenhorns, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 09:00 pm, Punk'd (S08-Special), Punk'd Awards, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 09:00 pm, America's Got Talent (02x01), Episode 201, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 09:00 pm, The Universe (01x02), Mars: The Red Planet, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 09:00 pm, ALMA Awards (01x07), 2007 ALMA Awards, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 09:00 pm, Decorating Cents (01x01), Decorating Cents Dream Wedding, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 09:30 pm, Dog the Bounty Hunter (04x13), Fly Boy, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 09:30 pm, Scarred (01x09), Season 1, Episode 9, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, Kathy Griffin: My Life on the D-List (03x01), Season Opener, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, The Real World/Road Rules Challenge (14x11), Pane In The Glass, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, The Shield (06x10), Spanish Practices, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, Criss Angel: Mindfreak (03x01), Luxor Light, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, Secret Lives Of Women (03x05), Lipstick Lesbians, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, America's Got Talent (02x02), Episode 202, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, ECW on Sci Fi (02x23), June 5, 2007, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, Whose Wedding Is It Anyway? (US) (06x08), Now You May Kiss the...Groom?, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, Jon & Kate Plus 8 (01x08), Shopping for Ten, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:00 pm, After The Catch (01x02), Man vs. Nature, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:30 pm, Rob & Big (02x03), Season 2, Episode 3, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:30 pm, Spice Up My Kitchen (01x01), Kitchen Needs to Get Current, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 10:30 pm, Hollyoaks (12x181), Student Balls, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 11:00 pm, The Daily Show (12x74), Paul Rudd, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 11:00 pm, The Springer Hustle (01x08), Season 1, Episode 8, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 11:30 pm, The Colbert Report (03x74), Jessica Valenti, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 11:35 pm, Late Show with David Letterman (14x156), Chevy Chase, Amanda Beard, Satellite Party, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 11:35 pm, The Tonight Show with Jay Leno (15x166), George Clooney, senior-citizen band the Zimmers, Rihanna, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 12:35 am, Late Night with Conan O'Brien (14x148), Brian Williams, Leslie Mann, Los Straitjackets with Big Sandy, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 12:35 am, The Late Late Show with Craig Ferguson (03x90), Rosie Perez, David Milch, Patti Smith, null)
INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, 01:35 am, Last Call with Carson Daly (06x66), Andy Richter, Gary Jules, null)

thx in advance

Link to comment
https://forums.phpfreaks.com/topic/54352-solved-mysql-php-insert-not-working/
Share on other sites

You don't have single quotes around the inserted data.

 

				$sql = "INSERT INTO `$table` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, '$time', '".mysql_real_escape_string($title)."', '".mysql_real_escape_string($desc)."', null)";

 

Try that.

:o omw i think im going to shoot myself

INSERT INTO `showstoday` (`ID`, `time`, `name`, `title`, `link`) VALUES (NULL, '08:00 pm', 'Deal Or No Deal (US) (02x68)', 'Episode 107', null)
Column 'link' cannot be null

 

im going to edit the database and then ill come back

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.