Jump to content

Can I submit a form after processing another within the same php file ?


swatisonee

Recommended Posts

I have the following login code that works. I also have a code to lead the user to a 2nd database if he needs to work there. Both codes work if they are independent Now i want to be able to insert the 2nd code into the first ie have a form within a form .

The idea is :

a. User logs in successfully.

b. Has an option to select a database (as this will move him from db1 to db2 or db3 as the case may be depending on what he needs to do)

c. He can continue to remain in the same database to process options there.

I am not able to figure out how to insert the 2nd code into the first - the entire screen goes blank even tho error reporting in on.

d. He is not allowed to select a 2nd database at login time - he has to choose it only after he has logged in - else i could have added that selection option at the time of processing the login.

Would appreciate some help . Many thanks.

Have stripped off much of  the html btw.

 

<?php
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
//Process this if statement only if form was submitted
if($_POST['submit']){
$username=$_POST['username'];
$password=$_POST['password'];
$ip=$_SERVER['REMOTE_ADDR'];
include ("../link.php");
include ("../session.php");

}
    //Test for login success
    $sql = "SELECT * FROM Users WHERE Username='$username' AND Password = '$password'";
    $result = mysql_query($sql);
    if  ($myrow = mysql_fetch_array($result)){
       
        $login_success = 'Yes'; 
        $userid = $myrow["Userid"];
       $usertype = $myrow["UTID"];
        $status = "On";
        $logout = 'logout.php';        $userFile = 'selectdb.php'; 


include ("../newsession.php")    ;


       $sql2= "insert into Log (Sessionid,Staffid,IP, Status) values('$_SESSION[id]','$userid','$ip', '$status')";
$result2 = mysql_query($sql2) or die  ('no access to database: ' . mysql_error());
//        echo mysql_error();      }

}		
?>

<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 11 (filtered)">
<title>LOGIN</title>
<link type="text/css" rel="stylesheet" href="adminlogin.css">


</head>

<body lang=EN-IN link=blue vlink=purple>

<?php

$userid = $_SESSION['userid'];
$usertype = $_SESSION['usertype'];
if($_POST['submit'] && ($login_success == 'Yes')){

$successMessage = '<p class="data"><center><font face="Tahoma" size=2>Thank you for logging in '.$username.' !<br /><br />';

$successMessage .= 'Click <a href="'.$userFile.'?Userid='.$userid.'"> here </a>to proceed to your options</p>';
print $successMessage;


$logoutMessage = 'Click <a href="'.$logout.'?Userid='.$userid.'"> here </a>to logout </p>';
print $logoutMessage;

} elseif ($_POST['submit'] && ($login_success != 'Yes')) {
  session_unset();
    $failureMessage = '<p class="data"><center><font face="Verdana" size="2" color="red">Login Failure.  Please fill in all fields with the correct information.<br /></font></center></p>';
    print $failureMessage;
?>
<form action="<?php print $PHP_SELF ?>" method="post">

<div class=Section1>
<div align=center>

    <td width=314 style='width:188.65pt;padding:0cm 0cm 0cm 0cm;height:30.0pt'>
     Username</span></b></p>
    </td>
    <td width=337 style='width:202.25pt;padding:0cm 0cm 0cm 0cm;height:30.0pt'>
    <input type ='text' class='bginput' name='username' value="<?php print ((strlen($username))? $username : '' );?>" />     </span></b></p>
    </td>
   
    <td width=314 style='width:188.65pt;padding:0cm 0cm 0cm 0cm;height:30.0pt'>
   Password</span></b></p>
    </td>
    <td width=337 style='width:202.25pt;padding:0cm 0cm 0cm 0cm;height:30.0pt'>
   <input type ='password' class='bginput' name='password' >     </span></b></p>
    </td>
   </tr>
  </table>
  </div>
</form>
<?php

} else {

?>

<FORM METHOD=post ACTION="<? echo $PHP_SELF ?>?action=login">


<div align=center>

    <td width=314 style='width:188.65pt;padding:0cm 0cm 0cm 0cm;height:30.0pt'>
Username</span></b></p>
    </td>
    <td width=337 style='width:202.25pt;padding:0cm 0cm 0cm 0cm;height:30.0pt'>
<input type ='text' class='bginput' name='username' value="<?php print ((strlen($username))? $username : '' );?>" />     </span></b></p>
    </td>
    <td width=314 style='width:188.65pt;padding:0cm 0cm 0cm 0cm;height:30.0pt'>
Password</span></b></p>
    </td>
    <td width=337 style='width:202.25pt;padding:0cm 0cm 0cm 0cm;height:30.0pt'>
    <input type ='password' class='bginput' name='password' >     </span></b></p>
    </td>
   </tr>
  </table>
  </div>
  <input name='submit' type='submit' value='Submit'> </span></b></p>

<input type="hidden" name="userid" value="<? echo $userid ?>" >
<input type="hidden" name="usertype" value="<? echo $usertype ?>" >
</form>
<?php
}
?>
</body>
</html>

 

<?
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
header("Cache-Control: public");
include ("log.php"); //db info for DB2, sessions etc

if(!isset($_SESSION['userid'])){
echo "<center><font face='Calibri' size='2' color=red>Sorry, Please login and use this page </font></center>";  exit;}

if($_POST['submit']){
$dbtype = $_POST['dbtype'];
   if ($dbtype == 'T') {
        include "t.php"; // contains dbname, pw and other info 
        $section = 'T';
    } 
if ($dbtype == 'I') {
        include "i.php"; // contains dbname, pw and other info
        $section = 'I';
        }
?>

<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 11 (filtered)">
<title>SELECTIONS</title>
</head>

<body lang=EN-IN><div class=Section1>

<form action="<?php print $PHP_SELF ?>" method="post">
<input type="hidden" name="userid" value="<? echo $userid ?>">


<?
if ($usertype == '7') { $userFile = 'sales.php';    }

$successMessage .= 'Click <a href="'.$section.'/'.$userFile.'?Userid='.$userid.'"> here </a>to proceed to your options</font></center></p>';
print $successMessage;
?>
<?php
} else {

?>

//following para is options for working in the same db

<tr style='page-break-inside:avoid;height:80.4pt'>
  <td width=297 style='width:178.25pt;border-top:3.0pt;border-left:3.0pt;
  border-bottom:1.5pt;border-right:1.5pt;border-color:#99CC00;border-style:
  solid;padding:0cm 5.4pt 0cm 5.4pt;height:80.4pt'>
  Clockin data
  </td>
  <td width=349 style='width:209.35pt;border-top:solid #99CC00 3.0pt;
  border-left:none;border-bottom:solid #99CC00 1.5pt;border-right:solid #99CC00 1.5pt;
  background:#E0E0E0;padding:0cm 5.4pt 0cm 5.4pt;height:80.4pt'>
  <a href="clockin.php?Userid=<? echo $userid ?>">Mark it</a></span></b></p>
  </td>
<FORM METHOD=post ACTION="<? echo $PHP_SELF ?>">


//now he has option to move to another db

<tr style='page-break-inside:avoid;height:85.2pt'>
  <td width=995 colspan=3 style='width:597.0pt;border-top:none;border-left:
  solid #99CC00 3.0pt;border-bottom:solid #99CC00 1.5pt;border-right:solid #99CC00 3.0pt;
  padding:0cm 5.4pt 0cm 5.4pt;height:85.2pt'>
  <a href="../COWORKIMG.jpg"><a href="../staff.html?Userid=<? echo $userid ?>"><span
  style='color:#333333;text-decoration:none'><img border=0 width=114
  height=108 src="../cow2.jpg"></span></a></span></b></p>
  </td>
</tr>
  <tr style='page-break-inside:avoid;height:85.2pt'>
  <td width=297 style='width:178.25pt;border-top:none;border-left:solid #99CC00 3.0pt;
  border-bottom:solid #99CC00 1.5pt;border-right:solid #99CC00 1.5pt;
  padding:0cm 5.4pt 0cm 5.4pt;height:85.2pt'>Select database if applicable
  </td>
  
  
<select name="dbtype">
<?php
$typesArray = array (""=>"[select One]", "A"=>"A","F"=>"F","I"=>"I" );
foreach ($typesArray AS $key=>$value) {
    print '<option value="'.$key.'" '.(($dbtype == $key)? "selected" :"").'>'.$value.'</option>';
}
?>
</select> 
<input name='submit' type='submit' value='Submit'> 

<input type="hidden" name="userid" value="<? echo $userid ?>" >
<input type="hidden" name="usertype" value="<? echo $usertype ?>" >

</form>
<?php

}
?>
</span></p>
  </td>
</tr>

</div>

</body>

</html>

Link to comment
Share on other sites

a thought...

 

use session variables

 

if session logged in variable not set display, process login code

 

if session login set and some other session variable1 = x, do this

 

if session login set and some other session variable1 = y, do that

 

if session login set and some other session variable1 = z, do other

 

etc etc

 

just a thought

 

Link to comment
Share on other sites

Umm..let me see. My file newsession.php is as under :

<?php
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
$_SESSION['id']=session_id();
$_SESSION['userid']=$userid;
$_SESSION['usertype']=$usertype;
?>

 

I use it to insert login info to a mysql table.

 

If i were to modify it , would i need an if-else statement there ?

Link to comment
Share on other sites

I am not able to figure out how to insert the 2nd code into the first - the entire screen goes blank even tho error reporting in on.

 

Means you have a fatal error.  The parser cannot catch the error.  The best way to work with these is start commenting large blocks of code until you get something back (even an error message) so you can try and figure out where the error is.

 

<?

if ($usertype == '7') { $userFile = 'sales.php';    }

 

$successMessage .= 'Click <a href="'.$section.'/'.$userFile.'?Userid='.$userid.'"> here </a>to proceed to your options</font></center></p>';

print $successMessage;

?>

 

In this block use <?php

 

 

Replace

$_SESSION[id]

with {$_SESSION[id]} inside the quotes

 

<form action="<?php print $PHP_SELF ?>" method="post">

 

should be

<form action="" method="post">

 

  include "t.php"; //

should  be  include ("t.php"); //

 

include "i.php"

should be include("i.php");

 

One of these might be your fatal errors.

 

Sorry for not using code blocks with this reply, there was just too many one line entries.

Link to comment
Share on other sites

hi,

 

i think the error is because when i try to insert the 2nd code into the first, the sequence of code processing is going awry.

 

Presumably, the 2nd code should come between :


if($_POST['submit'] && ($login_success == 'Yes'))
{

// at this point, it should log in and then open up the file selectdb.php where the user can either work on the 
//current db or go to the 2nd db. But since there is an open "{" after the elseif below to enable the form action 
//that follows to process the 1st code, i get stuck.
//I dont know where to put the 2nd code as the "}" comes only at the end of the form action 

$successMessage = '<p class="data"><center><font face="Tahoma" size=2>Thank you for logging in '.$username.' !<br /><br />';
$successMessage .= 'Click <a href="..selectdb.php?Userid='.$userid.'"> here </a>to proceed to your options</p>';
print $successMessage;
} 
elseif ($_POST['submit'] && ($login_success != 'Yes')) 
{
  session_unset();
    $failureMessage = '<p class="data"><center><font face="Verdana" size="2" color="red">Login Failure.  Please fill in all fields with the correct information.<br /></font></center></p>';
    print $failureMessage;

?>
<form action="<?php print $PHP_SELF ?>" method="post">
....
</form>
<?php
} else {
?>
<FORM METHOD=post ACTION="<? echo $PHP_SELF ?>?action=login">




 

Link to comment
Share on other sites

I still haven't figured out what the sequence is supposed to be.  In your original post, does the first code block call the second code block somewhere?  What is the third code block and how does it relate?  I just need more explanation of how all this fits together.

Link to comment
Share on other sites

a. Code 1 : user logs in with un and pw - this is already a php-self processing form

 

b. If successful, he clicks on "proceed to your options" which leads him to selectdb.php which is Code 2

 

c. Instead of clicking on "proceed to your options" , i want him to get another php self processing form where he chooses the db etc . Once he makes that selection, he then proceeds to do whatever else needed.

 

d. Its similar to a 2 dropdowns in a single script, in that the login script is the first choice to be made and then the db is the 2nd choice.

 

e. However, in a dropdown scenario i make a selection from a mysql table and that selection leads me to make another choice.  Here, the user has to type in un, pw and i  have to verify if there is login success or failure and only then allow a selection .

 

Gosh, am i making this more complicated than it should be ??

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.