I believe the same idea Matt posted is true for this line:

if ((!$_POST['fname']) || (!$_POST['lname']) || (!$_POST['company'])
|| (!$_POST['title']) || (!$_POST['degree']) || (!$_POST[
      'school']))

I am out of reach of a php processor, but I believe if a form submits
these, without populating them, the values of these will be ="".  I
generally use
if(!strlen($_POST['fname']) )
{
  // You forgot to enter a first name
}
HTH,
-Mike


On Wed, May 21, 2008 at 3:29 PM, James Crow <[EMAIL PROTECTED]> wrote:
> Matt,
>
>  Since I am using a plain text mail reader I do not see any section
> highlighted in red. I will however comment on the section I think you
> are referring to. :)
>
> This section:
> if (isset($_GET['try']))
>
> May not work correctly. If the request was something like
> http://127.0.0.1/test.php?try=
>
> then the $_GET['try'] variable will be set to NULL and the isset() will
> return FALSE. If you instead check for the key existing and then the
> value that would be better.
>
> if(array_key_exists('try',$_GET) && $_GET['try'] == "blah")
>
> Would be a more precise check on the try variable.
>
> If I am not looking at the correct line please reply with the line that
> is having the problem.
>
> Thanks,
> James
>
>
>
> On Wed, 2008-05-21 at 14:20 -0400, Matthew Gonzales wrote:
>> Hello,
>>
>> So I am trying to create a web app using some if statement logic. Right
>> now I am having some trouble getting a particular piece of the code to
>> work. (Highlighted in red below) I am trying to produce the user profile
>> and if the user does not have a profile a form will display asking the
>> user to create one. I can not get the highlighted if statement to work.
>> What am I doing wrong.
>>
>> <?php
>>
>> //Start the session
>> session_start();
>>
>> //Include profile form file
>> include "profile_form.php";
>> include "login_form.php";
>>
>> // Open a connection to the DB
>> $conn = mysql_connect('localhost', 'root', 'mg7448') or die(mysql_error());
>> mysql_select_db('newsprofs', $conn);
>>
>> //Set session_id variable
>> $session_id = $_SESSION['user_id'];
>>
>> //Check to see if the user is trying to update profile
>> if (isset($_GET['try']))
>> {
>>         //User is trying to update profile. Make sure form is filled out
>> correctly
>>         if ((!$_POST['fname']) || (!$_POST['lname']) ||
>> (!$_POST['company']) || (!$_POST['title']) || (!$_POST['degree']) ||
>> (!$_POST[
>>         'school']))
>>         {
>>             //Left fields blank on the form
>>             $msg = '<h5>Please fill out all fields of the form!</h5>';
>>
>>             //Display User profile form
>>             $print_form = $profile_form;
>>
>>         }
>>         else
>>         {
>>             //Form is filled out correctly. Insert into database
>>             //Create variables for the sql string
>>             $fname = $_POST['fname'];
>>             $lname = $_POST['lname'];
>>             $company = $_POST['company'];
>>             $title = $_POST['title'];
>>             $degree = $_POST['degree'];
>>             $school = $_POST['school'];
>>
>>
>>             //Cerate query
>>             $insert_profile = "insert into profiles (user_id, fname,
>> lname, company, title, degree, school) values ('" . $session_id .
>>              "', '" . $fname ."', '" . $lname . "', '" . $company . "',
>> '" . $title . "', '" . $degree . "', '" . $school . "')" ;
>>             $insert_results = mysql_query($insert_profile, $conn) or
>> die(mysql_error());
>>
>>             //Show success message
>>             $msg = '<h5>You have updated your profile
>> succesfully!</h5><br />
>>                     <a href="profile.php">Return to profile page</a>';
>>
>>         }
>> }
>>
>>
>> //Check to see if the user is logged in
>> elseif(isset($_SESSION['user_id']))
>> {
>>
>>     // User is logged in!
>>     $query = "SELECT username FROM users WHERE id = '" . $session_id .
>> "' LIMIT 1";
>>     $results = mysql_query ($query,$conn) or die(mysql_error());
>>
>>     //Save username
>>     list($username) = mysql_fetch_row($results);
>>
>>     // Log in message
>>     $msg= '<h3>Welcome! '. $username . '</h3>';
>>
>>     // Display User menu
>>     $menu = '<a herf="profile.php">My Account</a><br />
>>             <a href="/login/logout.php">Log Out</a>';
>>
>>     //Check to see if user has a profile
>>     $profile = "select fname, lname, company, title, degree, school from
>> profiles where user_id = '" . $session_id . "' ";
>>     $profile_results = mysql_query($profile, $conn)
>>     or die (mysql_error());
>>
>>     //Collect data for profile
>>     //Find what the user_id is
>>         while ($profile_id = mysql_fetch_array($profile_results))
>>         {
>>             $fname = $profile_id['fname'];
>>             $lname = $profile_id['lname'];
>>             $company = $profile_id['company'];
>>             $title = $profile_id['title'];
>>             $degree = $profile_id['degree'];
>>             $school = $profile_id['school'];
>>
>>             //Add Profile to display block
>>             $display_block = '
>>             <tr>
>>                 <td class="heading">First Name:</td>
>>                 <td class="input-cell"> ' . $fname . '</td>
>>             </tr>
>>             <tr>
>>                 <td class="heading">Last Name:</td>
>>                 <td class="input-cell">' . $lname . '</td>
>>             </tr>
>>             <tr>
>>                 <td class="heading">Company:</td>
>>                 <td class="input-cell">' . $company . '</td>
>>             </tr>
>>             <tr>
>>                 <td class="heading">Title:</td>
>>                 <td class="input-cell">' . $title . '</td>
>>             </tr>
>>             <tr>
>>                 <td class="heading">Degree:</td>
>>                 <td class="input-cell">' . $degree . '</td>
>>             </tr>
>>             <tr>
>>                 <td class="heading">School:</td>
>>                 <td class="input-cell">' . $school . '</td>
>>             </tr>';
>>         }
>>
>>     //If username is empty display error message
>>     if (empty($username))
>>     {
>>         //Display error message
>>         $msg = '<h5>An error has occured trying to retrieve your user
>> profile. Please contact the webmaster. You have been logged out
>>         to protect your data.</h5><br />
>>         <a href="index.php">Return to Home Page to login</a>';
>>
>>     }
>>
>>     //If profile is not there display form to submit profile
>>     elseif ($profile_results <= 0)
>>     {
>>         //Display notify message
>>         $notify_msg = '<h5>You have not created a profile yet! Please do
>> so by filling out the form below!</h5>';
>>
>>         //Display User profile form
>>         $print_form = $profile_form;
>>
>>     }
>>
>>
>> }
>>
>> //User is not logged in display message and direct user to return to
>> index page
>> else
>> {
>>
>>     // User not logged in
>>     $msg = '<h5>You must be logged in to see your profile. Please return
>> to the <a href="index.php">Home Page</a> to login!</h5>';
>>
>>
>> }
>>
>>
>> //
>>
>>
>> ?>
>> --
>> Matthew Gonzales
>> IT Professional Specialist
>> Enterprise Information Technology Services
>> University of Georgia
>> Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>> Phone: (706)542-9538
>>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to