Informations are not sent by form - php

I wrote a code and i used Boostrap to make 2 dropdown : Sign In and Sign Up. After i complete input fields , informations aren't send ... and submit button redirect me to index.php?username="What is in username field"&password="Password typed" .
I wanna send data to informations index.php?tab=SignIn... What could be wrong ?
<ul class="nav navbar-nav nav pull-right">
<li class="animated dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-lock fa-2x"></i><br /> Register <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<?php
#$_SESSION['username2'] = $_POST['username'];
#$_SESSION['email'] = $_POST['email'];
#$_SESSION['password'] = $_POST['password'];
?>
<form class="form" id="formLogin" action="index.php?tab=SignUp">
<li><div class="form-group">
<input type="text" name="username" id="username" class="form-control" placeholder="Username" value="<?= $_SESSION['username2'] ?>" required/>
</div></li>
<li><div class="form-group">
<input type="email" name="email" id="email" class="form-control" placeholder="E-Mail Address" value="<?= $_SESSION['email'] ?>" required/>
</div></li>
<li><div class="form-group">
<input type="password" name="password" id="password" class="form-control" placeholder="Password" value="<?= $_SESSION['password'] ?>" required/>
</div></li>
<li class="divider"></li>
<input type="submit" name="register" class="btn btn-success" value="Register" tabindex="7">
</form>
</ul>
</li>
</ul>

replace this
<form class="form" id="formLogin" action="index.php?tab=SignUp">
with this
<form class="form" id="formLogin" action="index.php" method="post">
<input type="hidden" name="tab" value="SingUp" />
and in your index.php get tab parameter by $_POST['tab']

change
<form class="form" id="formLogin" action="index.php?tab=SignUp">
to
<form class="form" id="formLogin" action="index.php?tab=SignUp" method="post">

Nope. Just call index.php each time. No suffixes to the url ever. If you want a special value, then create a hidden element in the form, with the value set so the second time the user hits index.html, the value will populate...
<?php
#$_SESSION['username2'] = $_POST['username'];
#$_SESSION['tab'] = $_POST['tab']; // set in the original form in a hidden field.
#$_SESSION['email'] = $_POST['email'];
#$_SESSION['password'] = $_POST['password'];
?>
Somewhere along the line do a test if ($_POST['tab'] == "SignUp") then do whatever. If $_POST['tab'] isnt = SignUp, then you know its the first time to that page....
Keep it very simple. Less is more! (oops.. I'm a duplicate of the posting by Gabriele Pieretti) I'm upvoting GP! thx.

Related

Button implements the wrong code when press 'enter' button

I am writing code that is meant to log in users.
The login and search worked before but, ever since I combined the two the login form doesn't implement it's own code and instead, it runs the search code
EDIT: I found out why this happens, it's because I have been pressing enter instead of selecting login. So now I want to know, how do I press enter and implement the login code.
Below is the headerPublic.php which contains the search code
<?php
//---------------------BEGIN SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
if(isset($_POST["search_button"]))
{
//PHP SEARCH CODE
}
//---------------------END SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
?>
<html>
<head>
<title>VCR Exchange</title>
</head>
<body>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>Register</li>
<li>Log In</li>
</ul>
</nav>
And this is the login.php.
<?php require('connect.php'); ?>
<?php require('headerPublic.php'); ?>
<?php require('session.php'); ?>
<form class="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="inputEmail" >Email address</label>
<input type="email" name="email" placeholder="Email address">
<label for="inputPassword" >Password</label>
<input type="password" name="password" placeholder="Password">
<button name="login" type="submit">Login</button>
</form>
</body>
</html>
<?php
// IF LOGIN BUTTON IS CLICKED:
if (isset($_POST['login']))
{
//LOG IN CODE
}
?>
The search form was missing a closing form tag
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</form>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->

PHP Form passing input values to url

I have a form that the user has to input number contract and a code like so:
<form action="index.php?option=com_platiniumchristmas&cartao=<?php echo $_GET['cartao']?>&contrato=contract&codigo=code" method="post">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-user tip" title="Utilizador"></i>
</span>
<input autocomplete="off" type="text" name="contract" id="contract" class="input form-control" tabindex="0" size="18" placeholder="Num. Contrato" required="" value="">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-lock tip" title="Senha"></i>
</span>
<input autocomplete="off" type="password" name="codigo" id="code" class="input form-control" tabindex="0" size="18" placeholder="Codigo" required="" value="">
</div>
</div>
<input type="hidden" name="cartao" id="cartao" value="<?php echo $_POST['cartao']?>"/>
<input type="submit"value="Login" id="submit" class="btn btn-info pull-right" />
</form>
I have to post those values into an url so that the other page recives this values. But what is happing is instead of putting the id on my form action url it does nothing. Can any one help me with this issue.
The Hidden field is to call a function inside of a the form like so:
<?php
function validateUser($contrato, $codigo)
{
$url = 'http://managerexternal.medicare.pt/MedicareManager_External.svc?wsdl';
$client = new SoapClient($url);
$paramsMC = array('schema'=>'mctestes','numcContrato'=>$contrato, 'codigo'=>$codigo);
$paramsGC = array('schema'=>'gctestes','numcContrato'=>$contrato, 'codigo'=>$codigo);
if($client->AuthenticatedUserByContratoCodigo($paramsMC) == true){
$controller = new getInfoContact();// Instanciar Class
$controller->getuserInfo('mctestes',$contrato);
$_GET['schema']="mctestes";
$controllerNumeroCartao = new getInfoContact();// Instanciar Class
$_POST['cartao']=$controllerNumeroCartao->getNumCartao('mctestes',$contrato);
}
?>
I need to a function to get value for "cartao". Then I need to send through an url the contact and code value that where set by the user. With does two values I call a function to get the users "cartao".
First of all your code is wrong
<form action="index.php?option=com_platiniumchristmas&cartao=<?php echo $_GET['cartao']?>&contrato=contract&codigo=codigo method="get">
should be
<form action="index.php?option=com_platiniumchristmas&cartao=<?php echo $_GET['cartao'];?>&contrato=contract&codigo=codigo" method="get">

can't access viarible in the target php files [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
At first I write a simple hotel.php
<div role="main" class="ui-content">
<?php
$info = $_GET['type'];//works well $info get num= 1;
?>
<h3 class="ui-bar ui-bar-a ui-corner-all">order</h3>
<div class="ui-body ui-body-a ui-corner-all">
<form action="sendmail.php" method="get">
<ul data-role="listview" data-inset="true">
<li class="ui-field-contain">
<label for="name">name</label>
<input type="text" name="name" id="name" vlaue="" data-clear-btn="true">
</li>
<li class="ui-field-contain">
<label for="phone">phone</label>
<input type="text" name="phone" id="name2" vlaue="" data-clear-btn="true">
</li>
<li class="ui-field-contain">
<input class="invisible" type="text" name="room_info" value="<?php $_GET['type'];?>">
<label for="slider-2">num</label>
<input type="range" name="slider-2" id="slider-2" data-mini="true" data-highlight="true" min="1" max="6" value="4" data-clear-btn="true">
</li>
<li class="ui-field-contain">
<label for="arrive-time">a_time</label>
<input type="datetime-local" name="arrive-time" id="arrive-time" value="" data-clear-btn="true">
</li>
<li class="ui-field-contain">
<label for="leave-time">b_time</label>
<input type="datetime-local" name="leave-time" id="arrive-time" value="" data-clear-btn="true">
</li>
<li class="ui-body ui-body-b">
<fieldset class="ui-grid-a">
<div class="ui-block-a"><button type="reset" class="ui-btn ui-corner-all ui-btn-a">reset</div>
<div class="ui-block-b"><button type="submit" class="ui-btn ui-corner-all ui-btn-a" data-ajax="false">sbumit</div>
<fieldset>
</li>
</ul>
</form><!--end form-->
</div>
</div>
It's strange that $info = $_GET['type']; works well and the $info get the value correctly.
but when I click the submit button.
in target webpage sendmail.php
$name=$_GET['name'];
$phone=$_GET['phone'];
$roominfo=$_GET['room_info'];
$num=$_GET['slider-2'];
$a_time=$_GET['arrive-time'];
$b_time=$_GET['leave-time'];
all get the right information except the roominfo is null.
what's the problem with this">I try this">but steel not work
Try to echo:
<input class="invisible" type="text" name="room_info" value="<?php $_GET['type'];?>">
to
<input class="invisible" type="text" name="room_info" value="<?php echo $_GET['type'];?>">
EDIT
OP seems to want this element hidden so that's why there is invisible class. Well, you don't need to create a class for this case. You can use hidden.
<input type="hidden" name="room_info" value="<?php echo $_GET['type'];?>">
Use echo
<input class="invisible" type="text" name="room_info" value="<?php echo $_GET['type'];?>">

PHP session being destroyed prematurely

I am a php newbie and I am using MAC OS. I recently set up a website and test it under localhost. It works fine until one day I tried to rename my home folder, and quit halfway when switching from root back to the one that I have renamed. Then I logged out from the root user and loggin in the one that I have renamed. Then I found that I have to reset everything. The application folder had been moved outside the user home dir to the same level with the user folder.
Here's the problem(I don't know whether it is caused by the above action.)
I let a user log in with username and password, and use a session variable to store the username. I check with:
echo $_SESSION['name'];
echo session_status();
The first one shows the username I have input, and the second one prints 2
So I think that the username was stored in that session variable.
But then whenever the user enter another page, the session variable is destroyed.
What is the problem?
Here's the code that I write for every page as page header. It contains the log in box. It used to work fine.
<?php
echo '<div id="pageheader">
<div class="wrap">
<div class="logo">
<img src="pics/1.gif" height="45px">
</div>
<ul id="nav">
<li>New Arrival&nbsp&nbsp&nbsp/</li>
<li>Hot&nbsp&nbsp&nbsp/</li>
<li>By School&nbsp&nbsp&nbsp/
<ul >
<li>ADM</li>
<li>CEE</li>
<li>EEE</li>
<li>HSS</li>
<li>MAE</li>
<li>MSE</li>
<li>NBS</li>
<li>SBS</li>
<li>SCBE</li>
<li>SCI</li>
<li>SPMS</li>
<li>SCE</li>
</ul>
</li>
<li>By Course&nbsp&nbsp&nbsp/
<ul>
<li>Mathematics</li>
<li>Computing</li>
<li>Accounting</li>
<li>Business Law</li>
<li>Physics</li>
<li>Chemistry</li>
<li>Biology</li>
</ul>
</li>
<li>By Kind&nbsp&nbsp&nbsp/</li>
</ul>
<ul id="log">';
function generateLogin(){
echo ' <li id="login">
<a id="login-trigger" href="#">login&nbsp<span>&#x25BC</span></a>
<div id="login-content">
<form action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">
<fieldset class="inputs">
<input name="user" type="text" placeholder="Username" class="reqd" />
<input name="loginpw" type="password" placeholder="Password" class="reqd" />
</fieldset>
<fieldset class="actions">
<input type="submit" class="button1" value="Log in" />
<label><input name="keep" type="checkbox" value="yes" />Keep me signed in</label>
</fieldset>
</form>
</div>
</li>
<li id="signup">
<a id="signup-trigger" href="#">signup&nbsp<span>&#x25BC</span></a>
<div id="signup-content">
<form action="signup.php" method="post" enctype="multipart/form-data">
<fieldset class="inputs">
<input name="username" id="username" type="text" placeholder="Username (at least 6 characters)" class="reqd user" />
<input name="email" id="email" type="email" placeholder="john#example.com" class="reqd email" />
<input id="passwd1" type="password" placeholder="Password (at least 6 characters)" class="reqd pd" />
<input name="pswd" id="passwd2" type="password" placeholder="Confirm your password" class="reqd passwd1" />
</fieldset>
<fieldset class="actions">
<input type="submit" class="button1" value="Sign up" /> <input type="reset" class="button1" />
</fieldset>
</form>
</div>
</li>
';
}
session_start();
if(!isset($_SESSION['name']) or $_GET['logout'] == 1){
if($_GET['logout'] == 1){unset($_SESSION['name']);}
if(isset($_POST['user'])){
$link = mysqli_connect('localhost','root','root','bookstore');
if (!$link){
die('Could not connect: ' . mysqli_error());
}
try {
$sql = "SELECT username FROM user
WHERE username='$_POST[user]' AND
pswd=MD5('$_POST[loginpw]')";
$sqlUser = "SELECT username FROM user
WHERE username='$_POST[user]'";
$result1 = mysqli_query($link, $sql);
$result2 = mysqli_query($link, $sqlUser);
if (!mysqli_fetch_row($result1)){
if(!mysqli_fetch_row($result2)){
throw new Exception("User ".$_POST['user']." does not exist!");
}
else{
throw new Exception("Incorrect password!");
}
}
else{
$_SESSION['name'] = $_POST['user'];
echo '
<ul id="log">
<li>Logout</li>
<li>Hi, '.$_POST['user'].'</li>
</ul>';
}
}catch(Exception $e){
echo "<script type='text/javascript'>alert('".$e->getMessage()."');</script>";
generateLogin();
}
mysqli_close($link);
}
else{
generateLogin();
}
}
else{
$name = $_SESSION['name'];
echo '
<ul id="log">
<li>Logout</li>
<li>Hi, '.$_SESSION['name'].'</li>
</ul>';
}
echo ' </ul>
<div id="search">
<form action="book.php" name="search" method="get" enctype="multipart/form-data">
<input name="q" id="q" autocomplete="off" onkeyup="showHint(this.value)" type="text" size="100" placeholder="Search..." />
<input type="submit" class="button1" value="Search" />
</form>
</div>
<div id="suggestBox">
<ul>
<div id="txtHint">
</div>
</ul>
</div>
</div>
</div>';
?>
You have to start the session on every page you use sessions
<?php
session_start();
// now I can use my sessions in this page and
// I should start the session on each page I use them
?>
You should use session_start() before any html output so in your case move session_start() before the first echo!
<?php
// move session_start here
session_start();
echo '<div id="pageheader">
<div class="wrap">';
?>
You need to run session_start() on every page where you're expecting to use $_SESSION data...seems like you should add session_start to the top of this page, has to be included before anything is output.

how to submit login form I have below, on clicking "enter" key as i fill up the credentials?

I have a login form as below, I have tried doing this by onkeydown event, but i need this to work only for enter key..
<form action="login.php" method="post" name="login">
<div class="login-form">
<ul>
<li class="col1">E-mail Address</li>
<li class="col2"><input name="email_address" type="text" class="textfiled" /></li>
<li class="col1">Password</li>
<li class="col2"><input name="password" type="password" class="textfiled" /></li>
<li class="col1"></li>
<li class="col2"><input name="signin" type="button" class="signin-btn" onclick="javascript: login.submit();" onkeydown="javascript: login.submit();"/></li>
</ul>
</div>
</form>
How can i do this?
Try like this:
<li class="col2"><input name="signin" type="button" class="signin-btn" onclick="javascript: login.submit();" onkeydown="javascript: if (window.event.keyCode == 13) login.submit(); else window.event.keyCode = null; "/></li>
You can just change your signin button to type="submit".
<input name="signin" type="submit" class="signin-btn" value="Submit" />
No need for all those onclick handler.

Categories