I've created a simple links page that grabs the values of links (url, title, description) from a database and displays them on the page. At the base of the page, there is a form to add a new link. What I want to do is set that form's action to be the same page as the form is on, and have some sort of code at the start of the page to insert the form data into the database. The page would then go on to display the database info. I can insert and display all the info no problem, but I don't know how to write the script to ignore the inserting if it is just being displayed (as in, for the first time the page is loaded, not after the form is submitted). I have used this at the start of my page, although when the page is first displayed, it gives an error about an undifined index (because txtLink doesn't exist yet).
- Code: Select all
if(($HTTP_POST_VARS['txtLink'])!=""){
$link = $HTTP_POST_VARS['txtLink'];
$url = $HTTP_POST_VARS['txtUrl'];
$description = $HTTP_POST_VARS['txtDescription'];
$query = "INSERT INTO links (link_title, link_url, link_description)
VALUES ('$link', '$url', '$description')";
mysql_query($query) or die('Error, insert query failed');
}
It works fine when you use the form, but not when you don't. How can I do this? Can I do it with isset somehow?