Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 1st, 2007, 02:04 PM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default If Else Trouble

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?



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie having trouble. Please help!!!!! crittag ASP.NET 2.0 Basics 0 June 24th, 2006 05:00 PM
SQL Trouble mrideout BOOK: Beginning ASP.NET 1.0 1 September 30th, 2004 12:24 PM
Please i have had a Trouble hurted Wrox Book Feedback 1 June 28th, 2004 02:18 AM
trouble databass Classic ASP Databases 2 August 16th, 2003 10:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.