I am working on my website, and I am trying to get the url parameter ‘page’ which is an integer that tells which entry to read in the MySQL database that hols the HTML for all the pages. Here is my code, with the MySQL username and password removed for security reasons:
if ($_GET['page']) { $con = mysql_connect('localhost','username','password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('jmurano_pages', $con); $title=mysql_query('SELECT title FROM pageContent WHERE pageID=' . $_GET['page']); echo '<title>' . $title . '</title>\n'; echo '</head>\n'; echo '<body>\n'; $content = mysql_query('SELECT content FROM pageContent WHERE pageID=' . $_GET['page']); echo $content; echo '\n</body>\n</html>'; }
This puts the title as ‘Resource id #2’ and the content as ‘Resource id #3’. I can’t think of what I may have done wrong.
I’m still confused. I’m a complete PHP newbie. What exactly do I need to do to access the content and title?
Apart from the injection vulnerability (see John’s answer) you should get the title from the mysql_query using
However I think it would be wise if you would follow an online mysql php tutorial.
EDIT
even better would be to just use 1 mysql_query like so:
That would save your script time and resources since there is only need for one mysql query.
This tutorial is rather good: http://www.freewebmasterhelp.com/tutorials/phpmysql