Passing variable value to URL - php

I want to pass a variable value to an url but the problem is when I first clicked the search button the value doesn't appear and when the second clicked is triggered the variable value is shown. How can i fix this? I think the fault is when i click the search button the page is refreshing. Can someone help me about this?
here's my code:
<div class="form-inline form-padding">
<form action="student.php?classid=<?php echo $classid;?>" method="post">
<input type="text" class="form-control" name="search" placeholder="Search by ID or Name">
<select name="subject" class="form-control" required>
<option value="">Select Subject...</option>
<?php while($row = mysql_fetch_array($mysubject)): ?>
<option value="<?php echo $row['id']?>" <?php if($row['id']==$classid) echo 'selected'; ?>><?php echo $row['subject'];?></option>
<?php endwhile; ?>
</select>
<button type="submit" name="submit" id="submit" class="btn btn-primary"><i class="fa fa-search"></i> Search</button>
<button type="button" name="submit" class="btn btn-success"><i class="fa fa-print"></i> Print</button>
</form>
</div>

in your
<form action="student.php?classid=<?php echo $classid;?>" method="post">
change it to
<form action="student.php" method="post">

Related

Undefined index in post php

I have a form code php
<form action="CR/add.php" method="post">
<div class="form-group">
<label>Date</label>
<input id="date" type="text" name="date" class="date" value="<?php echo $datenow; ?>" required <?php if($user!="admin"){echo "disabled";}?>>
</div>
<button type="submit" class="btn btn-primary"><span class="fa fa-edit"></span> Input Data</button>
</form>
I get some error when I click the submit button. The error is Undefined index variable $date. I want only admin users to be able to edit the fill.
Why am I getting this error, and how can I fix it?
Any help would be appreciated.
You did not include the related PHP code for where the $date variable is declared or assigned a value.
A good way to do this would be to check if the variable was supplied using isset http://php.net/manual/en/function.isset.php
Example:
$date = '';
if(isset($_POST['date'])){
$date = $_POST['date'];
}
** Will need to see more of your code to give a more specific example.
# Kurnia Rocki - Just replace your code with this:
<script>
function check()
{ var user = document.getElementById('user').value;
if(user!='admin')
{ alert('Only admin can update');
return false;
}
else
return true;
}
</script>
<form action="CR/add.php" method="post" onSubmit="return check()">
<div class="form-group">
<label>Date</label>
<input id="date" type="text" name="date" class="tanggal" value="<?php echo $datenow; ?>" >
</div>
<input id="user" type="text" name="user" value="<?php echo $user; ?>" style="display:none;">
<button type="submit" class="btn btn-primary"><span class="fa fa-edit">
</span>Input Data</button>
</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'];
}

How to get values of selected dropdown box display in url

I'm setting up an eCommerce website and I need to select product quantity user enters in drop down. I have tried this but it gives me last quantity not the selected. I'm still in the process of creating the addtocart.php file but before that I need to pass the values so that I can use them in a later stage.
I have implemented the following code
<div class="product-cartq">
<div class="product-quantity pull-left">
<span>Quantity:</span>
<select name="quantity_option">
<?php for($qty = 1; $qty < 11; $qty++){
echo '<option value="'.$qty.'">'.$qty.'</option>';
}?>
</select>
</div>
<div class="btn_addtocart">
<form method="GET" action="cart.php" enctype="multipart/form-data">
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>">
<input type="hidden" name="quantity_option" value="<?php echo $qty; ?>">
<input class="btn btn-primary btn-submit" type="submit" name="add_to_cart" value="add to cart"/>
</form>
</div>
</div>
I can't proceed as I'm unable to get the value. Any suggestions or improvements on this?
Do this:
<form method="GET" action="cart.php" enctype="multipart/form-data">
<div class="product-cartq">
<div class="product-quantity pull-left">
<span>Quantity:</span>
<select name="quantity_option">
<?php for($qty = 1; $qty < 11; $qty++){
echo '<option value="'.$qty.'">'.$qty.'</option>';
}?>
</select>
</div>
<div class="btn_addtocart">
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>">
<input type="hidden" name="quantity_option" value="<?php echo $qty; ?>">
<input class="btn btn-primary btn-submit" type="submit" name="add_to_cart" value="add to cart"/>
</div>
</div>
</form>
The select control is outside form tag.

PHP Session won't save unique value

I want to save the name="" part of this button
<button type="submit" class="btn grey large" id="taxicompany" name="<? echo $rows['company']; ?>">select</button>
So when i do this
<?php echo "".$_SESSION['POSTDATA']['taxicompany'].''; ?>
it displays the value of name=""
But it won't display?
Why do you not give the button a value
<button type="submit" class="btn grey large" id="taxicompany" name="taxicompany" value="<? echo $rows['company']; ?>">select</button>
Then when you submit your form and reference $_POST['taxicompany'] you will have the value
http://www.w3schools.com/tags/att_button_value.asp
Try this:
<form method="post">
<button type="submit" class="btn grey large" id="taxicompany" name="taxicompany" value="your company name">select</button>
</form>
// PHP code
if(isset($_POST['taxicompany']))
{
$_SESSION['POSTDATA']['taxicompany'] = $_POST['taxicompany'];
echo $_SESSION['POSTDATA']['taxicompany']; //your company name
}

Can't retrieve values from other page (Stored As Label)

I am new to PHP and I am trying to get information from a form to another page, but the data won't transfer over when I hit submit. What am I doing wrong? Should I be trying to use GET instead of POST? What is the best way to debug something like this?
The path to information.php is definitely correct.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label name="tempID"><?php echo $number; ?></label>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
This file is in a different page (information.php)
if (isset($_POST["tempID"]))
{
$infoID = $_POST['tempID'];
}
echo $infoID;
<input type="hidden" name="tempID" value="<?php echo $number; ?>" />
Add this next to your original echo, post variables can't be stored in a label. Also remove the name value from the label
You need a submit input instead of a button with the name submit. Change the button's html to:
<input type='submit' value='More Details'>
Change Label in input
<form action="information.php" method="post">
<div class="row" style="padding-bottom: 20px;">
<input name="tempID" value="<?php echo htmlentities($number); ?>"/>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
labels are only to display information. they are not submitted during form submission.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label>Number:</label>
<input name="tempID" value="<?php echo $number; ?>"/>
<input class="btn" id="submit" name="submit" type="submit" value="More Detail" />
</div>
</form>

Categories