Here variable 'pass' can't parse to $_post['action']=='edit' - php

<form action="" method="post">
<div class="col-md-2 ">
<input type="type" value="<?php echo $row['rcode'];?>" name="pass" id="pass"/>
<input type="submit" name="edit" class="btn btn-primary" value="edit"/>
<input type="submit" name="delete" class="btn btn-danger" value="Delete"/>
</div>
</form>
then
if($_POST['action']=='edit'){
echo $rcode1=$_REQUEST['pass'];
$sqlup="select * from transport_details where rcode='$rcode1'";

There is no input named action. Your current code is unreachable.
The $_POST assoc gets its keys by attribute name. E.g.
<input type="text" name="authorName" />
<?php
echo $_POST['authorName'];
?>
Your code should be like (in PHP file)
if (isset($_POST['edit'])) { ... }
OR (in HTML file)
<form action="" method="post">
<div class="col-md-2 ">
<input type="type" value="<?php echo $row['rcode'];?>" name="pass" id="pass"/>
<input type="submit" name="action" class="btn btn-primary" value="edit"/>
<input type="submit" name="action" class="btn btn-danger" value="Delete"/>
</div>
</form>

You can do this in your php...
if (isset($_POST['edit'])) {
echo $rcode1=$_POST['pass'];
$sqlup="select * from transport_details where rcode='".$rcode1."'";
}
assuming your html is like this...
<form action="" method="post">
<div class="col-md-2 ">
<input type="type" value="<?php echo $row['rcode'];?>" name="pass" id="pass"/>
<input type="submit" name="action" class="btn btn-primary" value="edit"/>
<input type="submit" name="action" class="btn btn-danger" value="Delete"/>
</div>
</form>
you should be able to get the value

Related

PHP CALCULATOR USING BUTTONS

HTML CODE :
<div style="padding-left:40px">
<h2> PHP Calculator</h2>
<form method="post" action="">
Enter value: <input type="text" name="value"> <br> <br>
<div style="padding-left: 105px">
<input type="submit" value="9" name="button">
<input type="submit" value="8" name="button">
<input type="submit" value="7" name="button">
<input type="submit" value="+" name="button"> <br>
<input type="submit" value="6" name="button">
<input type="submit" value="5" name="button">
<input type="submit" value="4" name="button">
<input type="submit" value="-" name="button" style="padding-left: 9px"> <br>
<input type="submit" value="3" name="button">
<input type="submit" value="2" name="button">
<input type="submit" value="1" name="button">
<input type="submit" value="/" name="button" style="padding-left: 9px"> <br>
<input type="submit" value="0" name="button" style="padding- left:33px">
<input type="submit" value="." name="button" style="padding-right:9px">
<input type="submit" value="x" name="button" style="padding left: 7px"><br>
</div> <br>
<input type="submit" value="Calculate" name="Calculator">
</form>
</div>
PHP CODE :
<?php
if (isset($_POST["Calculate"]))
{
echo $_POST["button"];
} ?>
I'm developing a PHP calculator, actually my question is when i click to any of the input buttons the value should display in the text box. above is the code what i have tried with, but im unable to get the result. can any one help me in my work,so that how i can get the desired result.
There is nothing like you cannot do in PHP but if you could do it using Jquery it will be much more better in terms of User experience as well. Looking at your HTML , I can see you have a input type of submit which means on each click it will submit a form unless and until you have written any condition not to submit. Also your name for each button is also same and it will make difficult to track which one is clicked/entered, please make sure you have unique name field. If you want to do it in PHP only then on every submit you can save that value in session or cookies and while loading page you can check against that session variable or cookies and can show it the the input value.
You can see following code as a reference but it is using jquery.
<div style="padding-left:40px">
<h2> PHP Calculator</h2>
<form method="post" action="" id="formID">
Enter value: <input type="text" name="value" id='btnValue'> <br> <br>
<div style="padding-left: 105px">
<input type="button" value="9" name="btn1">
<input type="button" value="8" name="btn2">
<input type="button" value="7" name="btn3">
<input type="button" value="+" name="btn4"> <br>
<input type="button" value="6" name="btn5">
<input type="button" value="5" name="btn6">
<input type="button" value="4" name="btn7">
<input type="button" value="-" name="btn8" style="padding-left: 9px"> <br>
<input type="button" value="3" name="btn8">
<input type="button" value="2" name="btn9">
<input type="button" value="1" name="btn10">
<input type="button" value="/" name="btn11" style="padding-left: 9px"> <br>
<input type="button" value="0" name="btn12" style="padding- left:33px">
<input type="button" value="." name="btn13" style="padding-right:9px">
<input type="button" value="x" name="btn14" style="padding left: 7px"><br>
</div> <br>
<input type="submit" value="Calculate" name="Calculator">
</form>
</div>
$('input[type=button]').on('click',function(){
if($('#btnValue').val()==''){
$('#btnValue').val($(this).val());
}else{
$('#btnValue').val($('#btnValue').val()+($(this).val()));
}
})
Here is the jsfiddle you can look on https://jsfiddle.net/nef1qgzn/13/
Note: I have user Jquery libraray 3.3.1

REst API for Uploading Files

Can anyone help me how to use this function below... This function will upload file into to my storage but unfortunately I didn't know how to use the code. i tried numerous times already but still it doesn't work. This code is not mine I got it from github and try to use it into my project.
public function upload(){
// Check that the path is a directory
if(is_file($this->path)){
$this->status = "error";
$this->message = "Path Not A Directory";
}else{
// Handle upload
$target = $this->path . "/" . basename($_FILES['upload']['name']);
if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) {
$this->status = "success";
}else{
$this->status = "error";
$this->message = "Upload Error";
}
}
$this->respond();
}
<form action="file.php" method="get">
<input type="hidden" name="action" value="upload" readonly>
<input type="hidden" name="path" value="class/" readonly>
<input type="file" name="upload" readonly>
<!-- <input type="submit" name="create" class="btn btnsuccess btn-
sm" value="create dir/file ">
<input type="submit" name="open" class="btn btn-success btn-sm"
value="Open a file">
-->
<input type="submit" class="btn btn-success btn-sm" value="upload to specific dir">
<!-- <input type="submit" name="modify" class="btn btn-success
btn-sm" value="modify file or dir">
<input type="submit" name="delete" class="btn btn-success btn-sm"
value="delete file">
<input type="submit" name="index" class="btn btn-success btn-sm"
value="list dir">
<input type="submit" name="dublicate" class="btn btn-success btn-
sm" value="duplicate"> -->
</form>
url: http://localhost/api/archiving%20system/file.php?action=upload&path=class%2F&upload=myfile.txt
OUtput: {"status":"error","message":"Upload Error"}
You need the enctype="multipart/form-data" added to your <form> tag - and it should probably be POST for the method and not GET, and a max file size...
<form action="file.php" method="POST" enctype="multipart/form-data" >
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="hidden" name="action" value="upload" readonly>
<input type="hidden" name="path" value="class/" readonly>
<input type="file" name="upload" readonly>
<input type="submit" class="btn btn-success btn-sm" value="upload to specific dir">
</form>

why cant i get value of $accept_request_id

<form method="post>
<button input type="submit" id="click" class="btn btn-info " name="<?php echo$accept_request_id; ?>"></button>
</form>
Why can't I get value of $accept_request_id? I use following code
if(isset($_POST[$accept_request_id])) {
$accept_request_id=$_POST['accept_request_id'];
}
You can use below code to get value of form. This will work
<form method="post>
<input type="hidden" name="accept_request_id" value="<?php echo $accept_request_id ?>" />
<button input type="submit" id="click" class="btn btn-info">Submit
</button>
</form>
if(isset($_POST['accept_request_id'])) {
$accept_request_id = $_POST['accept_request_id'];
}

username and password help in joomla

What I'm trying to do here is display my login information and once logged in display something else
Example is here
<?php
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1){
echo '
<form id="login-form" class="form-inline" method="post" action="/home">
<div class="topUser">
Name:
<input id="modlgn-username" class="TopinputReg" type="text" placeholder="User Name" tabindex="0" name="username" />
</div>
<div class="toppass">Password:
<input id="modlgn-passwd" class="TopinputReg" type="password" placeholder="Password" tabindex="0" name="password" pwfprops="," />
</div>
<div class="topsignin">
<input class="Signin" name="Submit" tabindex="0" type="submit" value="" />
</div>
<div class="topregister">
<input name="button" type="submit" class="Register" id="button" value="" />
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.login" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMzM=" name="return">
<input type="hidden" value="1" name="39ea5446d876078c6f6221d396ef5bd4">
</form>
';
}
else
{
echo '
<div class="topUser">Welcome Back!</div>
<div class="toppass">Enjoy you stay.</div>
<form id="login-form" class="form-vertical" method="post" action="/log-out">
<div class="topsignin">
<input class="Signout" type="submit" value="" name="Submit" />
<input type="hidden" value="com_users" name="option">
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMDE=" name="return">
<input type="hidden" value="1" name="994c61f8ab4ccf23fe9dae6546a87089">
</form>
<div class="topregister">
<input name="button" type="submit" class="account" id="button" value="" />
</div>
';
}
?>
No I know what I am doing wrong just have no clue how to fix it. the two
need to have a different generated number each time but how do i do this.
since this numbers are the same every time if i log in then out then try to log back in it will give me "Invalid Token"
When i go into the login template it gives me
this for login
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
and this for log out
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('logout_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
Now if I replace the hidden fields that already have the pregenerated numbers with the php stuff above when i try to refresh my page it goes completely blank.
I am at a loss with this see as how I am not very advanced in php. any help anyone cant provide would be massively helpful..
why not try like this,
<?php
$user = JFactory::getUser();
$status = $user->guest;
if($status == 1):
?>
<form id="login-form" class="form-inline" method="post" action="/home">
<div class="topUser">
Name:
<input id="modlgn-username" class="TopinputReg" type="text" placeholder="User Name" tabindex="0" name="username" />
</div>
<div class="toppass">Password:
<input id="modlgn-passwd" class="TopinputReg" type="password" placeholder="Password" tabindex="0" name="password" pwfprops="," />
</div>
<div class="topsignin">
<input class="Signin" name="Submit" tabindex="0" type="submit" value="" />
</div>
<div class="topregister">
<input name="button" type="submit" class="Register" id="button" value="" />
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.login" name="task">
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<?php else:
?>
<div class="topUser">Welcome Back!</div>
<div class="toppass">Enjoy you stay.</div>
<form id="login-form" class="form-vertical" method="post" action="/log-out">
<div class="topsignin">
<input class="Signout" type="submit" value="" name="Submit" />
<input type="hidden" value="com_users" name="option">
</div>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('logout_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</form>
<div class="topregister">
<input name="button" type="submit" class="account" id="button" value="" />
</div>
<?php endif;?>

HTML input field jumps

I have 2 text fields, user and password. When I enter the password, it jumps to the first one. I have no idea why that is happening. I couldn't find why it is jumping. How do I change it so the password form doesn't jump? Here is the code:
<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
</form>
<?php
}else{
?>
<form name="login_form" method="post" action="login2.php">
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
<input type="submit" name="login" id="login" action="index.php" value="Login">
</label>
</p>
</form>
<form name="Register" method="post" action="reg.php">
<input type="submit" name="register" id="register" value="Register">
</form><br />
<form name="news" method="post" action="news.php">
<input type="submit" name="news" id="news" value="News">
</form>
<?php
}
?>
You have both of the inputs wrapped in one label. The browser is getting confused and it thinks that that entire content is a label for the first input (that's how labels work, apparently). You should only use <label> to wrap text for input.
This:
<label>
<input name="user" type="text" id="user">ID<br />
<input name="pass" type="password" id="pass">Password<br />
</label>
Should be this:
<input name="user" type="text" id="user">
<label for="user">ID</label><br />
<input name="pass" type="password" id="pass">
<label for="pass">Password</label><br />

Categories