I'm a somewhat experienced programmer, just starting to do some work with PHP. so far it's been a nice shift from the client side programing I'm used to.
My work on a CMS was going fine until this happened. I was happily coding a way a quick and dirty way to password protect a content publishing system, so I wrote up a quick function to check the password and then passed it to a if statement.
the idea is the pwConfirm function should return a true or false value relative to whether or not the password is correct. From here, I pass this to a if statement and if it's valid go ahead and executes the code to upload the item to the MySQL DB; otherwise it skips over it and gives a nasty error message.
Just for some background info, the grand scheme of the code is to take some data from a web form (via GET) and if the password is correct upload it to a table in a database.
Any help you can give to this fledgling PHP programmer would be greatly appreciated. I'm sure it's something simple like a syntax error I've over looked, I've written plenty of if statements in my day.
P.S. Any comments about my architecture would be greatly appreciated.
Code:
<?php
function pwConfirm($pw)
{
if($pw == "*********")
{
return TRUE;
}
else
{
return FALSE;
}
}
?>
<?php
//get GET Data Time is automagically updated when added to db
$author = $_REQUEST['txtAuthor'];
$category = $_REQUEST['category'];
$content = $_REQUEST['txtContent'];
$pw = $_REQUEST['txtPW'];
if(pwConfirm($pw))
{
if(($author != "") && ($category != "") && ($content != ""))
{
$connection = mysql_connect('localhost', '*****', '****');
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
$dbSelected = mysql_select_db("cibressu_Website", $connection);
if(!dbSelected)
{
die("Error Selecting DB: " . mysql_error());
}
$query = "INSERT INTO siteData (Author, Category, Content) VALUES (\"" . $author . "\",'" . $category . "',\"" . $content ."\");";
$result = mysql_query($query);
if(!$result)
{
die("Invalid Query: " . mysql_error() . "\n Query: " . $query);
}
mysql_close($connection);
}
else
{
print("<b>Invalid Password</b>");
}
}
?>
P.S. Not to be vain but does anyone know of a way to make my query strings look nicer? Is there a PHP equivalent to a .Resources file?