I was wondering how can I check to see if a web page is listed in a database and if its not add it to the database.
How can I do this using PHP and MySQL.
Sorry if I'm vague I'm new to PHP and MySQL.
I was wondering how can I check to see if a web page is listed in a database and if its not add it to the database.
How can I do this using PHP and MySQL.
Sorry if I'm vague I'm new to PHP and MySQL.
A simple example.
<?php
$db = mysql_connect('host','user','pass');
$sql ="SELECT url FROM yourTable WHERE url = 'http://example.com/foo'";
$qid = mysql_query($sql, $db);
if (mysql_num_rows($qid) == 0) {
$sql ="INSERT INTO yourTable (url) VALUES ('http://example.com/foo')";
mysql_query($sql, $db);
}
However you should add error checking after the mysql_connect() and the mysql_query() functions.
See: http://php.net/mysql%5Fquery and http://php.net/mysql%5Fconnect