php-windows Digest 22 May 2008 17:13:23 -0000 Issue 3476
Topics (messages 28904 through 28906):
Re: If Question!
28904 by: James Crow
28905 by: Michael Southworth
I use Content-Disposition to open up a save as window, can I use an absolute
path?
28906 by: googling1000
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
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
>
--- End Message ---
--- Begin Message ---
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
>
>
--- End Message ---
--- Begin Message ---
Now, I have header("Content-Disposition: filename=file1.txt");
I tried to do header("Content-Disposition: filename=C:\Program
Files\file1.txt");
But, it's not working. The save as window pops up, but it doesn't give the
file the right filename (which is file1), and it doesn't know the type
(which is .txt)
So, we can't use an absolute path with Content-Disposition?
--
View this message in context:
http://www.nabble.com/I-use-Content-Disposition-to-open-up-a-save-as-window%2C-can-I-use-an-absolute-path--tp17409092p17409092.html
Sent from the Php - Windows mailing list archive at Nabble.com.
--- End Message ---