rhiannon1
asked on
Saving XML to Database using PHP
Hi, need some advice/help with saving a parsed RSS feed to my mysql database.
I am parseing, and then displaying the external RSS feed on my page, and now i want to beable to click a link after each article, which will save the article to my databse, which can be retrived at a later date.
How can i do this? I have been looking at some code in books, and it showed a little snippet , putting variables in a link followed by  . I have done this, so now it shows, save article on my page, and when you hover over the link, it shows a big long script with the values of the variables. But how do i get from this, to saving to the database?
I have created the SQL statement ... $sqlSAVE. I am probably being stupid, and it is very simple, byt i am scratching my head trying to figure this out.
I am parseing, and then displaying the external RSS feed on my page, and now i want to beable to click a link after each article, which will save the article to my databse, which can be retrived at a later date.
How can i do this? I have been looking at some code in books, and it showed a little snippet , putting variables in a link followed by  . I have done this, so now it shows, save article on my page, and when you hover over the link, it shows a big long script with the values of the variables. But how do i get from this, to saving to the database?
I have created the SQL statement ... $sqlSAVE. I am probably being stupid, and it is very simple, byt i am scratching my head trying to figure this out.
<?php
/**
*
*
**/
session_start();
/* --- If session data is correct, then Welcome to secure area, else back to the login page --- */
if (isset($_SESSION['email']) && isset($_SESSION['password']))
{
} else
{
header("Location: logformTest.php");
}
/** require the webpage class definition file also the database connection file. */
require_once ("web.class.php");
require_once ("dbconnect.php");
try
{
/* query the database */
$db = getConnection();
/* ------ End of Querys ------- */
/* create a new instance of the webpage class passing the title and an array of stylesheets to the constructor */
$page = new Webpage('Smoking RSS Feed', array('css/frfrh66.css'));
/* Parse XML from external RSS feed http://www.medicalnewstoday.com */
$rss_document = simpleXML_load_file('http://www.medicalnewstoday.com/rss/smoking.xml');
/* Get title, link, managing editor, and copyright from the document and store them in variables */
$rss_title = $rss_document->channel->title;
$rss_link = $rss_document->channel->link;
$rss_editor = $rss_document->channel->managingEditor;
$rss_copyright = $rss_document->channel->copyright;
/* -------------------Header Area-------------------- */
$page->addToBody("<div id='header'>");
$page->addToBody("<img src='images/StopSmoking1.jpg' alt='Stop Smoking' width='200' height='90' border='0' class='img' />");
$page->addToBody("<h2>$rss_title</h2>");
$page->addToBody("<h3><a href='" . $rss_link . "'>{$rss_link}</a></h3>");
$page->addToBody("<h3>$rss_editor</h3>");
$page->addToBody("<h3>$rss_copyright</h3>");
$page->addToBody("</div>");
/* -------------------End of Header------------------- */
/* -------------------Menu Div's --------------------- */
$page->addToBody("<div id='lsidebar'>");
$page->addToBody("<div class='nmenu'>");
$page->addToBody("<a class='topgap' href='home1.php'>News Article List</a>");
$page->addToBody("<a class='btmgap' href='rssNeuroScience.php'>Neuro Science</a>");
$page->addToBody("<a class='btmgap' href='searchRSS.php'>Search Articles</a>");
$page->addToBody("<a class='btmgap' href='savedRSS.php'>Saved Articles</a>");
$page->addToBody("<a class='btmgap' href='logout.php'>Logout</a>");
$page->addToBody("<div class='separator'></div>");
$page->addToBody("</div>");
/* ------------------Valid XHTML Image----------------- */
$page->addToBody("<p><a href='http://validator.w3.org/check?uri=referer'><img
src='http://www.w3.org/Icons/valid-xhtml10-blue'
alt='Valid XHTML 1.0 Transitional' height='31' width='88' /></a></p>");
$page->addToBody("<div class='separator'></div>");
/* ---------------------------------------------------- */
/* ------------------Valid CSS image------------------- */
$page->addToBody("<p>
<a href='http://jigsaw.w3.org/css-validator/'>
<img src='http://jigsaw.w3.org/css-validator/images/vcss-blue'
alt='Valid CSS!' /></a></p>");
/* ---------------------------------------------------- */
$page->addToBody("</div>");
/* ------------------End of Menu Div's----------------- */
/* ------------------Main Content Area----------------- */
$page->addToBody("<div id='contentarea'>");
$page->addToBody("<div class='content'>");
/* Display XML articles on my page */
//Loop through each item in the RSS document
foreach ($rss_document->channel->item as $RSSitem)
{
// modify string from articles to printer friendly news //
$printer = str_replace(array('.php', 'articles/'), array('',
'printerfriendlynews.php?newsid='), $RSSitem->link);
/* Create variables for saving articles to database */
$subscriberID = $_SESSION['email'];
$link = $printer;
$title = $RSSitem->title;
$category = $RSSitem->category;
$body1 = file_get_contents($printer);
$body2 = strip_tags($body1);
//The variable $RSSitem will hold a different item for each loop
$page->addToBody("<b><a href='$printer' target='blank'> $RSSitem->title </a></b><br />");
$page->addToBody("<b>$RSSitem->pubDate</b><br />");
$page->addToBody("$RSSitem->description<br />");
$page->addToBody("[<a href='$subscriberID $link $title $category $body2 ' target='blank'> SAVE ARTICLE </a>]<br /><br />");
}
/* Sql statement for saveing articles to the database */
$sqlSAVE = ("INSERT INTO article (subscriberID, link, title, category, body) VALUES ('$subscriberID','$printer','$title','$category','$body2')" );
/* Prepare and execute $sqlSAVE */
//$insertSQL = $db->prepare($sqlSAVE);
//$insertSQL ->execute();
$page->addToBody("</div></div>");
/*-------------End of Main Content Area---------------- */
/* Call the getPage function from the webpage class, which will display the head, body and footer. */
echo $page->getPage();
}
catch (PDOException$e)
{
echo $e->getMessage();
}
?>
ASKER
still trying to figure this out?. I am using the same page, so the link is
<a href='rssSmoking.php?$subs criberID&n bsp;$link& nbsp;$titl e $ca tegory&nbs p;$body2&n bsp;' target='blank'> SAVE ARTICLE </a>]
but when i click this, i get : -
SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
<a href='rssSmoking.php?$subs
but when i click this, i get : -
SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
<?php
/**
*
*
**/
session_start();
/* --- If session data is correct, then Welcome to secure area, else back to the login page --- */
if (isset($_SESSION['email']) && isset($_SESSION['password']))
{
//$message = "<h3>Hello and Welcome to Medical News Today</h3>";
} else
{
//$message = "Please log in with your username and password";
header("Location: logformTest.php");
}
/** require the webpage class definition file also the database connection file. */
require_once ("web.class.php");
require_once ("dbconnect.php");
try
{
/* query the database */
$db = getConnection();
/* ------ End of Querys ------- */
/* create a new instance of the webpage class passing the title and an array of stylesheets to the constructor */
$page = new Webpage('Smoking RSS Feed', array('css/frfrh66.css'));
/* Parse XML from external RSS feed http://www.medicalnewstoday.com */
$rss_document = simpleXML_load_file('http://www.medicalnewstoday.com/rss/smoking.xml');
/* Get title, link, managing editor, and copyright from the document and store them in variables */
$rss_title = $rss_document->channel->title;
$rss_link = $rss_document->channel->link;
$rss_editor = $rss_document->channel->managingEditor;
$rss_copyright = $rss_document->channel->copyright;
/* -------------------Header Area-------------------- */
$page->addToBody("<div id='header'>");
$page->addToBody("<img src='images/StopSmoking1.jpg' alt='Stop Smoking' width='200' height='90' border='0' class='img' />");
$page->addToBody("<h2>$rss_title</h2>");
$page->addToBody("<h3><a href='" . $rss_link . "'>{$rss_link}</a></h3>");
$page->addToBody("<h3>$rss_editor</h3>");
$page->addToBody("<h3>$rss_copyright</h3>");
$page->addToBody("</div>");
/* -------------------End of Header------------------- */
/* -------------------Menu Div's --------------------- */
$page->addToBody("<div id='lsidebar'>");
$page->addToBody("<div class='nmenu'>");
$page->addToBody("<a class='topgap' href='home1.php'>News Article List</a>");
$page->addToBody("<a class='btmgap' href='rssNeuroScience.php'>Neuro Science</a>");
$page->addToBody("<a class='btmgap' href='searchRSS.php'>Search Articles</a>");
$page->addToBody("<a class='btmgap' href='savedRSS.php'>Saved Articles</a>");
$page->addToBody("<a class='btmgap' href='logout.php'>Logout</a>");
$page->addToBody("<div class='separator'></div>");
$page->addToBody("</div>");
/* ------------------Valid XHTML Image----------------- */
$page->addToBody("<p><a href='http://validator.w3.org/check?uri=referer'><img
src='http://www.w3.org/Icons/valid-xhtml10-blue'
alt='Valid XHTML 1.0 Transitional' height='31' width='88' /></a></p>");
$page->addToBody("<div class='separator'></div>");
/* ---------------------------------------------------- */
/* ------------------Valid CSS image------------------- */
$page->addToBody("<p>
<a href='http://jigsaw.w3.org/css-validator/'>
<img src='http://jigsaw.w3.org/css-validator/images/vcss-blue'
alt='Valid CSS!' /></a></p>");
/* ---------------------------------------------------- */
$page->addToBody("</div>");
/* ------------------End of Menu Div's----------------- */
/* ------------------Main Content Area----------------- */
$page->addToBody("<div id='contentarea'>");
$page->addToBody("<div class='content'>");
/* Display XML articles on my page */
//Loop through each item in the RSS document
foreach ($rss_document->channel->item as $RSSitem)
{
// modify string from articles to printer friendly news //
$printer = str_replace(array('.php', 'articles/'), array('',
'printerfriendlynews.php?newsid='), $RSSitem->link);
/* Create variables for saving articles to database */
$subscriberID = $_SESSION['email'];
$link = $printer;
$title = $RSSitem->title;
$category = $RSSitem->category;
$body1 = file_get_contents($printer);
$body2 = strip_tags($body1);
//The variable $RSSitem will hold a different item for each loop
$page->addToBody("<b><a href='$printer' target='blank'> $RSSitem->title </a></b><br />");
$page->addToBody("<b>$RSSitem->pubDate</b><br />");
$page->addToBody("$RSSitem->description<br />");
$page->addToBody("[<a href='rssSmoking.php?$subscriberID $link $title $category $body2 ' target='blank'> SAVE ARTICLE </a>]<br /><br />");
}
/* Sql statement for saveing articles to the database */
$sqlSAVE = ("INSERT INTO article (subscriberID, link, title, category, body) VALUES ('$subscriberID','$printer','$title','$category','$body2')" );
/* Prepare and execute $sqlSAVE */
$insertSQL = $db->prepare($sqlSAVE);
$insertSQL ->execute();
$page->addToBody("</div></div>");
/*-------------End of Main Content Area---------------- */
/* Call the getPage function from the webpage class, which will display the head, body and footer. */
echo $page->getPage();
}
catch (PDOException$e)
{
echo $e->getMessage();
}
?>
I'm sorry, I think I misunderstood your problem.
What kind of database module are you using (mysql? mysqli?).
The mysql one doesn't support prepared statements.
For mysqli you need to add parameters to it with bind_param().
You can read more about it here:
http://php.net/manual/en/book.mysqli.php
Kind regards,
Matthias Vance
What kind of database module are you using (mysql? mysqli?).
The mysql one doesn't support prepared statements.
For mysqli you need to add parameters to it with bind_param().
You can read more about it here:
http://php.net/manual/en/book.mysqli.php
Kind regards,
Matthias Vance
I submitted to soon, here is some more information:
http://devzone.zend.com/node/view/id/686#Heading10
http://www.petefreitag.com/item/356.cfm
Kind regards,
Matthias Vance
http://devzone.zend.com/node/view/id/686#Heading10
http://www.petefreitag.com/item/356.cfm
Kind regards,
Matthias Vance
ASKER
sorry, i should of added, i am using PDO for all my database querys's and the database itself is MySQL.
ASKER
what i need to beable to do is run the rssSmoking page, see the list of articles first. Then a user will click the saved articles link, which will then run a sql statement, which will then save that particular article to my database.
You have to bind the parameters as I stated before. Please read about "PDO and prepared statements" in the PHP manual:
http://php.net/manual/en/pdo.prepared-statements.php
Kind regards,
Matthias Vance
http://php.net/manual/en/pdo.prepared-statements.php
Kind regards,
Matthias Vance
ASKER
Ok, i am getting somewhere. When i now goto rssSmoking.php, it automaticly saves 1 article to the database. I want to get it so when i goto rssSmoking, i can click the Save Article link, then it will run the script, and save that particular article to the database.
<?php
/**
*
*
**/
session_start();
/* --- If session data is correct, then Welcome to secure area, else back to the login page --- */
if (isset($_SESSION['email']) && isset($_SESSION['password']))
{
//$message = "<h3>Hello and Welcome to Medical News Today</h3>";
} else
{
//$message = "Please log in with your username and password";
header("Location: logformTest.php");
}
/** require the webpage class definition file also the database connection file. */
require_once ("web.class.php");
require_once ("dbconnect.php");
try
{
/* query the database */
$db = getConnection();
/* ------ End of Querys ------- */
/* create a new instance of the webpage class passing the title and an array of stylesheets to the constructor */
$page = new Webpage('Smoking RSS Feed', array('css/ct.css'));
/* Parse XML from external RSS feed http://www.medicalnewstoday.com */
$rss_document = simpleXML_load_file('http://www.medicalnewstoday.com/rss/smoking.xml');
/* Get title, link, managing editor, and copyright from the document and store them in variables */
$rss_title = $rss_document->channel->title;
$rss_link = $rss_document->channel->link;
$rss_editor = $rss_document->channel->managingEditor;
$rss_copyright = $rss_document->channel->copyright;
/* -------------------Header Area-------------------- */
$page->addToBody("<div id='header'>");
$page->addToBody("<img src='images/StopSmoking1.jpg' alt='Stop Smoking' width='200' height='90' border='0' class='img' />");
$page->addToBody("<h2>$rss_title</h2>");
$page->addToBody("<h3><a href='" . $rss_link . "'>{$rss_link}</a></h3>");
$page->addToBody("<h3>$rss_editor</h3>");
$page->addToBody("<h3>$rss_copyright</h3>");
$page->addToBody("</div>");
/* -------------------End of Header------------------- */
/* -------------------Menu Div's --------------------- */
$page->addToBody("<div id='lsidebar'>");
$page->addToBody("<div class='nmenu'>");
$page->addToBody("<a class='topgap' href='home1.php'>News Article List</a>");
$page->addToBody("<a class='btmgap' href='rssNeuroScience.php'>Neuro Science</a>");
$page->addToBody("<a class='btmgap' href='searchRSS.php'>Search Articles</a>");
$page->addToBody("<a class='btmgap' href='savedRSS.php'>Saved Articles</a>");
$page->addToBody("<a class='btmgap' href='logout.php'>Logout</a>");
$page->addToBody("<div class='separator'></div>");
$page->addToBody("</div>");
/* ------------------Valid XHTML Image----------------- */
$page->addToBody("<p><a href='http://validator.w3.org/check?uri=referer'><img
src='http://www.w3.org/Icons/valid-xhtml10-blue'
alt='Valid XHTML 1.0 Transitional' height='31' width='88' /></a></p>");
$page->addToBody("<div class='separator'></div>");
/* ---------------------------------------------------- */
/* ------------------Valid CSS image------------------- */
$page->addToBody("<p>
<a href='http://jigsaw.w3.org/css-validator/'>
<img src='http://jigsaw.w3.org/css-validator/images/vcss-blue'
alt='Valid CSS!' /></a></p>");
/* ---------------------------------------------------- */
$page->addToBody("</div>");
/* ------------------End of Menu Div's----------------- */
/* ------------------Main Content Area----------------- */
$page->addToBody("<div id='contentarea'>");
$page->addToBody("<div class='content'>");
/* Display XML articles on my page */
//Loop through each item in the RSS document
foreach ($rss_document->channel->item as $RSSitem)
{
// modify string from articles to printer friendly news //
$printer = str_replace(array('.php', 'articles/'), array('',
'printerfriendlynews.php?newsid='), $RSSitem->link);
/* Create variables for saving articles to database */
$subscriberID = $_SESSION['email'];
$link = $printer;
$title = $RSSitem->title;
$category = $RSSitem->category;
$body1 = file_get_contents($printer);
$body2 = strip_tags($body1);
//The variable $RSSitem will hold a different item for each loop
$page->addToBody("<b><a href='$printer' target='blank'> $RSSitem->title </a></b><br />");
$page->addToBody("<b>$RSSitem->pubDate</b><br />");
$page->addToBody("$RSSitem->description<br />");
$page->addToBody("[<a href='rssSmoking.php?$subscriberID $link $title $category $body2 ' target='blank'> SAVE ARTICLE </a>]<br /><br />");
}
$stmt = $db->prepare("INSERT INTO article (subscriberID, link, title, category, body) VALUES (:subscriberID, :printer, :title, :category, :body2)");
$stmt->bindParam(':subscriberID', $subscriberID);
$stmt->bindParam(':printer', $printer);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':category', $category);
$stmt->bindParam(':body2', $body2);
$stmt->execute();
/* Prepare and execute $sqlSAVE */
//$insertSQL = $db->prepare($sqlSAVE);
//$insertSQL ->execute();
$page->addToBody("</div></div>");
/*-------------End of Main Content Area---------------- */
/* Call the getPage function from the webpage class, which will display the head, body and footer. */
echo $page->getPage();
}
catch (PDOException$e)
{
echo $e->getMessage();
}
?>
You should separate your save-to-db code from the code that parses/shows the RSS feed. I would suggest separate files. Otherwise it will indeed save 1 item to the database.
Kind regards,
Matthias Vance
Kind regards,
Matthias Vance
<a href="anotherfile.php?var=blaat">
ASKER
I am just dumb :( i think i should just give-in and quit php :'(
So i have created a new page saveMySQL.php, and changed the link on the rssSmoke page to saveMySQL.php, and put the sql statement ect in that. Now what do i do? How do i get it to remember the variables from the other page ? Do i just do $_GET['$subscriberID']; ect on the new page ??
So i have created a new page saveMySQL.php, and changed the link on the rssSmoke page to saveMySQL.php, and put the sql statement ect in that. Now what do i do? How do i get it to remember the variables from the other page ? Do i just do $_GET['$subscriberID']; ect on the new page ??
rsssmoke.php
<?php
/**
*
*
**/
session_start();
/* --- If session data is correct, then Welcome to secure area, else back to the login page --- */
if (isset($_SESSION['email']) && isset($_SESSION['password']))
{
//$message = "<h3>Hello and Welcome to Medical News Today</h3>";
} else
{
//$message = "Please log in with your username and password";
header("Location: logformTest.php");
}
/** require the webpage class definition file also the database connection file. */
require_once ("web.class.php");
require_once ("dbconnect.php");
try
{
/* query the database */
$db = getConnection();
/* ------ End of Querys ------- */
/* create a new instance of the webpage class passing the title and an array of stylesheets to the constructor */
$page = new Webpage('Smoking RSS Feed', array('css/ct.css'));
/* Parse XML from external RSS feed http://www.medicalnewstoday.com */
$rss_document = simpleXML_load_file('http://www.medicalnewstoday.com/rss/smoking.xml');
/* Get title, link, managing editor, and copyright from the document and store them in variables */
$rss_title = $rss_document->channel->title;
$rss_link = $rss_document->channel->link;
$rss_editor = $rss_document->channel->managingEditor;
$rss_copyright = $rss_document->channel->copyright;
/* -------------------Header Area-------------------- */
$page->addToBody("<div id='header'>");
$page->addToBody("<img src='images/StopSmoking1.jpg' alt='Stop Smoking' width='200' height='90' border='0' class='img' />");
$page->addToBody("<h2>$rss_title</h2>");
$page->addToBody("<h3><a href='" . $rss_link . "'>{$rss_link}</a></h3>");
$page->addToBody("<h3>$rss_editor</h3>");
$page->addToBody("<h3>$rss_copyright</h3>");
$page->addToBody("</div>");
/* -------------------End of Header------------------- */
/* -------------------Menu Div's --------------------- */
$page->addToBody("<div id='lsidebar'>");
$page->addToBody("<div class='nmenu'>");
$page->addToBody("<a class='topgap' href='home1.php'>News Article List</a>");
$page->addToBody("<a class='btmgap' href='rssNeuroScience.php'>Neuro Science</a>");
$page->addToBody("<a class='btmgap' href='searchRSS.php'>Search Articles</a>");
$page->addToBody("<a class='btmgap' href='savedRSS.php'>Saved Articles</a>");
$page->addToBody("<a class='btmgap' href='logout.php'>Logout</a>");
$page->addToBody("<div class='separator'></div>");
$page->addToBody("</div>");
/* ------------------Valid XHTML Image----------------- */
$page->addToBody("<p><a href='http://validator.w3.org/check?uri=referer'><img
src='http://www.w3.org/Icons/valid-xhtml10-blue'
alt='Valid XHTML 1.0 Transitional' height='31' width='88' /></a></p>");
$page->addToBody("<div class='separator'></div>");
/* ---------------------------------------------------- */
/* ------------------Valid CSS image------------------- */
$page->addToBody("<p>
<a href='http://jigsaw.w3.org/css-validator/'>
<img src='http://jigsaw.w3.org/css-validator/images/vcss-blue'
alt='Valid CSS!' /></a></p>");
/* ---------------------------------------------------- */
$page->addToBody("</div>");
/* ------------------End of Menu Div's----------------- */
/* ------------------Main Content Area----------------- */
$page->addToBody("<div id='contentarea'>");
$page->addToBody("<div class='content'>");
/* Display XML articles on my page */
//Loop through each item in the RSS document
foreach ($rss_document->channel->item as $RSSitem)
{
// modify string from articles to printer friendly news //
$printer = str_replace(array('.php', 'articles/'), array('',
'printerfriendlynews.php?newsid='), $RSSitem->link);
/* Create variables for saving articles to database */
$subscriberID = $_SESSION['email'];
$link = $printer;
$title = $RSSitem->title;
$category = $RSSitem->category;
$body1 = file_get_contents($printer);
$body2 = strip_tags($body1);
//The variable $RSSitem will hold a different item for each loop
$page->addToBody("<b><a href='$printer' target='blank'> $RSSitem->title </a></b><br />");
$page->addToBody("<b>$RSSitem->pubDate</b><br />");
$page->addToBody("$RSSitem->description<br />");
$page->addToBody("[<a href='saveMYSQL.php?$subscriberID $link $title $category $body2 ' target='blank'> SAVE ARTICLE </a>]<br /><br />");
}
$page->addToBody("</div></div>");
/*-------------End of Main Content Area---------------- */
/* Call the getPage function from the webpage class, which will display the head, body and footer. */
echo $page->getPage();
}
catch (PDOException$e)
{
echo $e->getMessage();
}
?>
saveMySQL.php
<?php
/**
*
*
**/
session_start();
/* --- If session data is correct, then Welcome to secure area, else back to the login page --- */
if (isset($_SESSION['email']) && isset($_SESSION['password']))
{
} else
{
//$message = "Please log in with your username and password";
header("Location: logformTest.php");
}
/** require the webpage class definition file also the database connection file. */
require_once ("web.class.php");
require_once ("dbconnect.php");
try
{
/* query the database */
$db = getConnection();
/* Something like this ???? */
$_GET['$subscriberID'];
/* Sql statement for saveing articles to the database */
$stmt = $db->prepare("INSERT INTO article (subscriberID, link, title, category, body) VALUES (:subscriberID, :printer, :title, :category, :body2)");
$stmt->bindParam(':subscriberID', $subscriberID);
$stmt->bindParam(':printer', $printer);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':category', $category);
$stmt->bindParam(':body2', $body2);
$stmt->execute();
$message = "Article Saved";
$message2 = "";
/* create a new instance of the webpage class passing the title and an array of stylesheets to the constructor */
$page = new Webpage('Save Articles', array('css/ct.css'));
/* -------------------Header Area-------------------- */
$page->addToBody("<div id='header'>");
$page->addToBody("<img src='images/home_clip_image001.gif' alt='Northumbria University' width='200' height='76' border='0' class='img' />");
$page->addToBody("<h2>CG0119 Web Database Systems</h2>");
$page->addToBody("<h3>Assignment, Semester 1, 2008-9</h3>");
$page->addToBody("<h3>Jonathan Imms 05031923</h3>");
$page->addToBody("</div>");
/* -------------------End of Header------------------- */
/* -------------------Menu Div's --------------------- */
$page->addToBody("<div id='lsidebar'>");
$page->addToBody("<div class='nmenu'>");
$page->addToBody("<a class='topgap' href='home1.php'>News Article List</a>");
$page->addToBody("<a class='btmgap' href='rssSmoking.php'>Smoking</a>");
$page->addToBody("<a class='btmgap' href='rssNeuroScience.php'>Neuro Science</a>");
$page->addToBody("<a class='btmgap' href='searchRSS.php'>Search Articles</a>");
$page->addToBody("<a class='btmgap' href='logout.php'>Logout</a>");
$page->addToBody("<div class='separator'></div>");
$page->addToBody("</div>");
/* ------------------Valid XHTML Image----------------- */
$page->addToBody("<p><a href='http://validator.w3.org/check?uri=referer'><img
src='http://www.w3.org/Icons/valid-xhtml10-blue'
alt='Valid XHTML 1.0 Transitional' height='31' width='88' /></a></p>");
$page->addToBody("<div class='separator'></div>");
/* ---------------------------------------------------- */
/* ------------------Valid CSS image------------------- */
$page->addToBody("<p>
<a href='http://jigsaw.w3.org/css-validator/'>
<img src='http://jigsaw.w3.org/css-validator/images/vcss-blue'
alt='Valid CSS!' /></a></p>");
/* ---------------------------------------------------- */
$page->addToBody("</div>");
/* ------------------End of Menu Div's----------------- */
/* ------------------Main Content Area----------------- */
$page->addToBody("<div id='contentarea'>");
$page->addToBody("<div class='content'>");
$page->addToBody("</div></div>");
/*-------------End of Main Content Area---------------- */
/* Call the getPage function from the webpage class, which will display the head, body and footer. */
echo $page->getPage();
}
catch (PDOException$e)
{
echo $e->getMessage();
}
?>
You're on the right track, but you have to change your link a bit (see included code snippet).
Don't give up on PHP, just be sure to read a lot of documentation and example code.
If you need any more help, or have questions, feel free to ask!
Kind regards,
Matthias Vance
Don't give up on PHP, just be sure to read a lot of documentation and example code.
If you need any more help, or have questions, feel free to ask!
Kind regards,
Matthias Vance
// You should replace this ..
$page->addToBody("[<a href='saveMYSQL.php?$subscriberID $link $title $category $body2 ' target='blank'>
// with this..
$page->addToBody("[<a href='saveMYSQL.php?subscriberID=$subscriberID&link=$link&title=$title&category=$category&body2=$body2' target='blank'>
// Then you can just do
$title = $_GET['title'];
$category = $_GET['category'];
ASKER
ok, i have changed my link to
$page->addToBody("[<a href='saveMYSQL.php?subscr iberID=$su bscriberID &link=$lin k&title=$t itle&categ ory=$categ ory&body2= $body2' target='blank'>
and then on saveMYSQL.php
/* query the database */
$db = getConnection();
$subscriberID = $_GET['subscriberID'];
$link = $_GET['link'];
$title = $_GET['title'];
$category = $_GET['category'];
$body = $_GET['body'];
/* Sql statement for saveing articles to the database */
$stmt = $db->prepare("INSERT INTO article (subscriberID, link, title, category, body) VALUES (:subscriberID, :printer, :title, :category, :body2)");
$stmt->bindParam(':subscri berID', $subscriberID);
$stmt->bindParam(':printer ', $printer);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':categor y', $category);
$stmt->bindParam(':body2', $body2);
$stmt->execute();
$message = "Article Saved";
$message2 = "<a href='savedRSS.php'> Click here to go Saved Article Page</a>";
but i am now getting Error messages when i click the saved article link.
Notice: Undefined index: subscriberID in /var/www/vhosts/numyspace. co.uk/web_ users/home /~unn_r031 923/public _html/WebD atabases/s aveMYSQL.p hp on line 28
Notice: Undefined index: body in /var/www/vhosts/numyspace. co.uk/web_ users/home /~unn_r031 923/public _html/WebD atabases/s aveMYSQL.p hp on line 32
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'subscriberID' cannot be null
$page->addToBody("[<a href='saveMYSQL.php?subscr
and then on saveMYSQL.php
/* query the database */
$db = getConnection();
$subscriberID = $_GET['subscriberID'];
$link = $_GET['link'];
$title = $_GET['title'];
$category = $_GET['category'];
$body = $_GET['body'];
/* Sql statement for saveing articles to the database */
$stmt = $db->prepare("INSERT INTO article (subscriberID, link, title, category, body) VALUES (:subscriberID, :printer, :title, :category, :body2)");
$stmt->bindParam(':subscri
$stmt->bindParam(':printer
$stmt->bindParam(':title',
$stmt->bindParam(':categor
$stmt->bindParam(':body2',
$stmt->execute();
$message = "Article Saved";
$message2 = "<a href='savedRSS.php'> Click here to go Saved Article Page</a>";
but i am now getting Error messages when i click the saved article link.
Notice: Undefined index: subscriberID in /var/www/vhosts/numyspace.
Notice: Undefined index: body in /var/www/vhosts/numyspace.
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'subscriberID' cannot be null
saveMYSQL.php
<?php
/**
*
*
**/
session_start();
/* --- If session data is correct, then Welcome to secure area, else back to the login page --- */
if (isset($_SESSION['email']) && isset($_SESSION['password']))
{
} else
{
//$message = "Please log in with your username and password";
header("Location: logformTest.php");
}
/** require the webpage class definition file also the database connection file. */
require_once ("web.class.php");
require_once ("dbconnect.php");
try
{
/* query the database */
$db = getConnection();
$subscriberID = $_GET['subscriberID'];
$link = $_GET['link'];
$title = $_GET['title'];
$category = $_GET['category'];
$body = $_GET['body'];
/* Sql statement for saveing articles to the database */
$stmt = $db->prepare("INSERT INTO article (subscriberID, link, title, category, body) VALUES (:subscriberID, :printer, :title, :category, :body2)");
$stmt->bindParam(':subscriberID', $subscriberID);
$stmt->bindParam(':printer', $printer);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':category', $category);
$stmt->bindParam(':body2', $body2);
$stmt->execute();
$message = "Article Saved";
$message2 = "<a href='savedRSS.php'> Click here to go Saved Article Page</a>";
/* create a new instance of the webpage class passing the title and an array of stylesheets to the constructor */
$page = new Webpage('Save Articles', array('css/ct.css'));
/* -------------------Header Area-------------------- */
$page->addToBody("<div id='header'>");
$page->addToBody("<img src='images/home_clip_image001.gif' alt='Northumbria University' width='200' height='76' border='0' class='img' />");
$page->addToBody("<h2>CG0119 Web Database Systems</h2>");
$page->addToBody("<h3>Assignment, Semester 1, 2008-9</h3>");
$page->addToBody("<h3>Jonathan Imms 05031923</h3>");
$page->addToBody("</div>");
/* -------------------End of Header------------------- */
/* -------------------Menu Div's --------------------- */
$page->addToBody("<div id='lsidebar'>");
$page->addToBody("<div class='nmenu'>");
$page->addToBody("<a class='topgap' href='home1.php'>News Article List</a>");
$page->addToBody("<a class='btmgap' href='rssSmoking.php'>Smoking</a>");
$page->addToBody("<a class='btmgap' href='rssNeuroScience.php'>Neuro Science</a>");
$page->addToBody("<a class='btmgap' href='searchRSS.php'>Search Articles</a>");
$page->addToBody("<a class='btmgap' href='logout.php'>Logout</a>");
$page->addToBody("<div class='separator'></div>");
$page->addToBody("</div>");
/* ------------------Valid XHTML Image----------------- */
$page->addToBody("<p><a href='http://validator.w3.org/check?uri=referer'><img
src='http://www.w3.org/Icons/valid-xhtml10-blue'
alt='Valid XHTML 1.0 Transitional' height='31' width='88' /></a></p>");
$page->addToBody("<div class='separator'></div>");
/* ---------------------------------------------------- */
/* ------------------Valid CSS image------------------- */
$page->addToBody("<p>
<a href='http://jigsaw.w3.org/css-validator/'>
<img src='http://jigsaw.w3.org/css-validator/images/vcss-blue'
alt='Valid CSS!' /></a></p>");
/* ---------------------------------------------------- */
$page->addToBody("</div>");
/* ------------------End of Menu Div's----------------- */
/* ------------------Main Content Area----------------- */
$page->addToBody("<div id='contentarea'>");
$page->addToBody("<div class='content'>");
$page->addToBody("<h3>$message</h3>");
$page->addToBody("</div></div>");
/*-------------End of Main Content Area---------------- */
/* Call the getPage function from the webpage class, which will display the head, body and footer. */
echo $page->getPage();
}
catch (PDOException$e)
{
echo $e->getMessage();
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could also start using javascript XMLHttpRequests to do it dynamically.
Kind regards,
Matthias Vance
Open in new window