Jump to content


Photo

Page Control


  • Please log in to reply
36 replies to this topic

#1 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 07:11 PM

All,

Trying to read through all the manuals to determine how control is returned to the calling page for the following scenario:

<form method=post action=myproc.php>

without using the

header(Location:mypage.php)

in the myproc.php file.

Not finding anything!  Anybody help please!

OMR

#2 acdx

acdx
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 28 September 2006 - 07:14 PM

What's the problem with using header()?

Also, you could simply use the form page itself to process the form data.

You're missing some quotation marks there btw.

.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

.


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


#3 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 07:25 PM

What's the problem with using header()?

Also, you could simply use the form page itself to process the form data.

You're missing some quotation marks there btw.


Well everytime I've tried to use the header command, the page re-inits and my var values get scrubbed, so can't transfer processed var values, even with global on for that vars I'm trying to tranfer.

If you have a better way, let me know!

OMR

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 09:16 PM

Sorry, I'm lost.  You want to return to the form page after submitting the form?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 09:41 PM

Sorry, I'm lost.  You want to return to the form page after submitting the form?

Regards
Huggie


What I have is:

First Pass:
           $display_block = "<form action='../scripts/login.php' method='POST'><p><strong>User Login:</strong><br>
             				 <INPUT TYPE='text' NAME='username'></p><p><strong>Password:</strong><br>
             				 <INPUT TYPE='password' NAME='password'></p><p>&nbsp;<br>
            				 <input type=image src='../Images/btn-pale(log).jpg' name=log value=log width=120>
	            			 </form>";

Second Pass with Success:
              $display_block = "<font size=-1><b>Welcome $f_name $l_name.
                                <br>Thank you for logging in!</b></font>";

Second Pass with Failure:
           $display_block = "<font size=-1><b>Login not successful!</b></font>";

The $display_block sets on first pass, but does not set on second.  When I use header it sees the runs as first pass and resets everything, so can not get the transfer.

Should be simple, but it isn't.

OMR

#6 acdx

acdx
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 28 September 2006 - 10:01 PM

How do you know whether a user is logged on or off anyway?

.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

.


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 10:06 PM

OK, you're possibly best using just one page here...

Call the page something like login.php and set it up a little like this...

<?php

// Set any default variables, I've put these here to show you as an example
$username = "HuggieBear";
$password = "myPassword";

// Work out what to do next
if (!isset($_GET['submit'])){ // if it's the first time the page has been called then display the form
   showForm(); // Just a call to the function further down
}
else { // if the submit button's been pushed
   if (($_POST['user'] == $username) && ($_POST['pass'] == $password)){
      echo "Authenticated OK"; // Show this if the submitted username and password match up with what we have
   }
   else {
      echo "We couldn't authenticate you, please try again"; // Show this and the form if they failed to enter the correct details
      showForm();
   }
}

// Function to show the form   
function showForm {
   echo <<<HTML
   <h1>$message</h1>
   <form name="login" action="{$_SERVER['PHP_SELF']}" method="POST">
   <input type="text" name="user">
   <input type="password" name="pass">
   <input type="submit" name="submit" value="submit">
HTML;
}

Regards
Huggie

Note: This was written on the fly, so may not be 100% accurate but should give you an idea.
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#8 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 10:09 PM

How do you know whether a user is logged on or off anyway?


Per complete code as follows:
<?php
  	// check for required fields from the form
  	if (isset($_POST['log'])) {
	   	//connection to server and select database
		require ('../scripts/db_connect.php');
        // create and issue the query
      	$sql = "select usr_id, usr_name, usr_pwd from log_user where usr_name =
	  	       '$_POST[username]' AND usr_pwd = '$_POST[password]'";
  		$result = mysql_query($sql,$conn) or die(mysql_error());
  		if (mysql_num_rows($result) == 1) {
              $f_uid = mysql_result($result, 0, 'usr_id');
      	      $sql = "select inf_id from user_idx where usr_id=$f_uid";
  		      $residx = mysql_query($sql,$conn)	or die(mysql_error());
              if (mysql_num_rows($residx) == 1) {
                 $f_inf = mysql_result($residx, 0, 'inf_id');
      	         $sql = "select inf_fnam, inf_lnam from user_info where inf_id=$f_inf";
  		         $resinf = mysql_query($sql,$conn) or die(mysql_error());
              }
              // if authorized, get the value of f_name l_name
              $f_name = mysql_result($resinf, 0, 'inf_fnam');
              $l_name = mysql_result($resinf, 0, 'inf_lnam');
              // set authorization cookie
              setcookie("auth", "1", 0, "/", "localhost @mydomain.com", 0);
              //create display string
              $display_block = "<font size=-1><b>Welcome $f_name $l_name.
                                <br>Thank you for logging in!</b></font>";
echo $display_block;
		} else {           
           $display_block = "<font size=-1><b>Login not successful!</b></font>";
//           return;
//           exit;
		}
   	} else {
           $display_block = "<form action='../scripts/login.php' method='POST'><p><strong>User Login:</strong><br>
             				 <INPUT TYPE='text' NAME='username'></p><p><strong>Password:</strong><br>
             				 <INPUT TYPE='password' NAME='password'></p><p>&nbsp;<br>
            				 <input type=image src='../Images/btn-pale(log).jpg' name=log value=log width=120>
	            			 </form>";
	}
?>

SQL code is working fine, but can't return the $display_block to the calling form!

OMR

#9 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 10:12 PM

I didn't realise you had code already written  :D lol

I'll take a look now.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#10 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 10:12 PM

OK, you're possibly best using just one page here...

Call the page something like login.php and set it up a little like this...

Regards
Huggie

Note: This was written on the fly, so may not be 100% accurate but should give you an idea.


Huggie,

Page is a little more complex. See the page at:

http://www.cleanpoli...st/cleanpcr.php

Just running test there.

OMR

#11 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 September 2006 - 10:18 PM

Off topic- the site has a good idea, I would suggest unpixelating your image though.

On topic- have no idea

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#12 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 10:20 PM

Off topic- the site has a good idea, I would suggest unpixelating your image though.

On topic- have no idea


Not a graphics geek, so don't know how!

There is another site along this line at:

www.e-worldpeace.com

But no front page to it, just a forum in the back.

OMR

#13 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 10:22 PM

OK, you're missing the echo statements... See the comments I've made in your code... marked like this // <----

<?php
  	// check for required fields from the form
  	if (isset($_POST['log'])) {
	   	//connection to server and select database
		require ('../scripts/db_connect.php');
        // create and issue the query
      	$sql = "select usr_id, usr_name, usr_pwd from log_user where usr_name =
	  	       '$_POST[username]' AND usr_pwd = '$_POST[password]'";
  		$result = mysql_query($sql,$conn) or die(mysql_error());
  		if (mysql_num_rows($result) == 1) {
              $f_uid = mysql_result($result, 0, 'usr_id');
      	      $sql = "select inf_id from user_idx where usr_id=$f_uid";
  		      $residx = mysql_query($sql,$conn)	or die(mysql_error());
              if (mysql_num_rows($residx) == 1) {
                 $f_inf = mysql_result($residx, 0, 'inf_id');
      	         $sql = "select inf_fnam, inf_lnam from user_info where inf_id=$f_inf";
  		         $resinf = mysql_query($sql,$conn) or die(mysql_error());
              }
              // if authorized, get the value of f_name l_name
              $f_name = mysql_result($resinf, 0, 'inf_fnam');
              $l_name = mysql_result($resinf, 0, 'inf_lnam');
              // set authorization cookie
              setcookie("auth", "1", 0, "/", "localhost @mydomain.com", 0);
              //create display string
              $display_block = "<font size=-1><b>Welcome $f_name $l_name.
                                <br>Thank you for logging in!</b></font>";
echo $display_block;
		} else {           
           $display_block = "<font size=-1><b>Login not successful!</b></font>";
           echo $display_block; // <---- This was missing
//           return;
//           exit;
		}
   	} else {
           $display_block = "<form action='../scripts/login.php' method='POST'><p><strong>User Login:</strong><br>
             				 <INPUT TYPE='text' NAME='username'></p><p><strong>Password:</strong><br>
             				 <INPUT TYPE='password' NAME='password'></p><p>&nbsp;<br>
            				 <input type=image src='../Images/btn-pale(log).jpg' name=log value=log width=120>
	            			 </form>";
            echo $display_block; // <---- This was also missing
	}
?>

Does that help at all?

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#14 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 September 2006 - 10:22 PM

off topic again- I saw your other site, I am amazed at one thing, you have some good ideas behind the sites you are building.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#15 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 10:24 PM

I didn't realise you had code already written  :D lol

I'll take a look now.

Regards
Huggie


H,

Echo statements are in the form file!  Do you need source or can you glean from URL?

You can see the $display_block sets in the first pass and you see the input fields and the Login button.

OMR

#16 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 September 2006 - 10:28 PM

it would be easier for you to get this to work if you would just write out the form in html, maybe even php, but you are making almost everything that is going to hit the screen into a function, it would be easier to keep it simple, for what you are trying to do you could rewrite it in a neater, simpler way and chances are you would fix all of your problems.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#17 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 10:29 PM

Ohhhh.... Lost my head for a minute.

In that case add the following to the top of every page before you output anything to the browser:
session_start();

Change each instance of $display_block to $_SESSION['display_block'];

Then on the form page type:
echo $_SESSION['display_block'];

Easiest way to take things like that between pages is through session variables.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#18 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 10:30 PM

off topic again- I saw your other site, I am amazed at one thing, you have some good ideas behind the sites you are building.

Trying to get both these working right.

Forum works good at e-worldpeace.com, but need more substance.

Substance is OK on cleanpoliticalclassifiedrevolution.com, but code bombs.

Need to fix both, so all are happy!

OMR

#19 OldManRiver

OldManRiver
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 28 September 2006 - 10:54 PM

Huggie,

Followed your advise, but now getting an error, which I'm lost on.

Take a look at the error from the URL and please advise!

I put the session_start(); in the form file but must not be at the right place or maybe it conflicts with something godaddy is putting up there?

Uploaded the form file, so you can look!

Had it in the proc file at first, and that blew chunks too!

Thanks!

OMR

[attachment deleted by admin]

#20 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 11:03 PM

ok, is session_start() at the top of all the pages?

This error is common if you're sending something to the browser before you call session_start().

I tend to make it the first thing on every page by default, e.g.

<?php
session_start();
include('header.php');
include_once('connect.php')

echo <<<HTML
<html>
 <head>
  .....
?>

If that's not the case, then maybe you could post the first say 25 lines of code for me.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users