i'm trying to get a value from a select but i don't get how to do it, here is my code:
<form method="post">
<select name="List">
<?php while($Adresses = mysqli_fetch_array($adress)) { ?>
<option value="<?php echo $Addresses[0];?>"><?php echo $Addresses[0]; ?> </option><?php } ?>
</select>
<input type="submit" name="Edit" value="Edit">
</form>
I need the value of the selected address here:
<?php if(isset($_POST['Edit'])):
$_SESSION['adress']= $_POST['List'];?>
<p><b>Change your adress:</b> <input type="text" name="new_adress" value= "<?php echo $_SESSION['adress']; ?> " /></p>
<input type="submit" name="save" value="Save">
<input type="submit" name="delete" value="Delete">
<?php endif; ?>
and this is the error message:
Undefined index: List
I have tried
<?php $_SESSION['adress']= $_GET['List'];
but it did not work either...
thanks for you help in advance.
PHP is a serverside language.
HTML, CSS, and JavaScript are clientside languages.
PHP is for sending out HTML, CSS, and JavaScript data. To send from HTML to PHP you need to submit your form.
In your html:
<html>
<head>
</head>
<body>
<form action='test.php' method='post'>
<?php
echo "
<input name='name' value='" . $_SESSION['name'] . "'>
<input name='address' value='" . $_SESSION['name'] . "'>
";
?>
<input type='submit' value='Update Information'>
</form>
</body>
</html>
In your 'test.php':
<?php
$_SESSION['name'] = $_POST['name'];
$_SESSION['address'] = $_POST['address'];
?>
This will save it into your session. To actually save it you need to look into SQL or XML data parsing.
The only way to process data from HTML => PHP is with form submitting. PHP is processed by the server, not your internet browser.
Use POST for getting the data.
<?php $_SESSION['adress']= $_POST['List'];
Related
I am working on a project to take two submitted variables and turn them into php variables (eventually they will multiply together) but as of now I cannot get the variables to be treated as such/echo.
I tried changing from POST to GET and the variables are sent through (appear in query line) but they don't print on the page
<?php
if (isset($_POST['submit'])) {
echo $_POST['length'];
echo $_POST['numPass'];
}
?>
<form method="post" action="">
<input type="number" name="length">
<input type="number" name="numPass">
<input type="submit">
</form>
I expect that the variables will be echoed as a regular statement.
ie. length=2 and numPass=4
24
You can get the $_GET and $_POST request using $_REQUEST
if (isset($_REQUEST['submit'])) {
echo $_REQUEST['length'];
echo $_REQUEST['numPass'];
}
<form method="post" action="">
<input type="number" name="length">
<input type="number" name="numPass">
<input type="submit" value="submit">
</form>
$POST['submit'] does not exist because your submit button does not have a name, it needs a name the same as your other inputs
It is better to check the input to avoid possible errors. You can try its example:
<?php
if( $_POST["length"] && $_POST["numPass"] ) {
echo "1: " . $_POST['length'] . "<br>";
echo "2: " . $_POST['numPass'] . "<br>";
echo $_POST['length'] * $_POST['numPass'];
}
?>
<form method="post" action = "<?php $_PHP_SELF ?>">
<input type="number" name="length">
<input type="number" name="numPass">
<input type="submit">
</form>
Here's my form
<form id="place-bid" action="placebid.php?placeBidProductId='.$row['product_id'].'" method="post" >
Your Bid:<br>
<input type="text" placeholder="$$$" name="money">
<input type="Submit" class="button_bid" name="submit" value="Place Bid">
<input type=hidden id='rowid' value=".row['product_id']." name='row_id'>
</form>
and here is my placebid.php
<?php
// $product_id=$_GET['placeBidProductId'];
$product_id=$_POST['row_id'];
echo " Id Produs : ".$product_id;
?>
My problem: I can't get the value from $row['product_id'], it will only echo the string "$row['product_id'] .$product_id;"
I'm guessing that before you are outputting that form you are doing some sort of query of a database. If that is the case then you likely want to change this line
<input type=hidden id='rowid' value=".row['product_id']." name='row_id'>
to
<input type=hidden id='rowid' value="<?php echo row['product_id'];>" name='row_id'>
Use print_r($_POST) for all form post value on form action page i.e. placebid.php. it will show you all value in form. Then make you business logic accordingly.
I am sending an id from a link
<a class="suba" href="empty.php?id=1" ></a>
and recieving this id in the empty.php page :
require_once 'connection.php';
session_start();
$id=$_GET['id'];
on refresh or on form submit the variable $id is lost :
<form action="" method="get">
<input type="submit" name="add" value="next">
</form>
<?php if(isset($_GET['add']) && $_SESSION['j'] < $filecount){
$_SESSION['j']++;
echo '<input type=hidden name=id value=' .$id. '>';
} ?>
I tried adding a hidden input in the form but it's not working also tried saving the variable in a session:
$_SESSION["word"] = $id;
You must print the Id in your form action
<form action="?id=<?= $id ?>" method="get">
<input type="submit" name="add" value="next">
</form>
I can't really use PHP and from what I've seen in tutorials this should work, but it doesn't:
<html>
<head></head>
<body>
<form>
<input type='text' name="name" value='myName'>
</form>
<p>
<?php
$name = $_POST['name'];
echo $name
?>
</p>
</body>
</html>
Is there a reason I can't get the value of name?
Sorry for asking such a simple question...
here is the fiddle http://jsfiddle.net/DCmu5/1/, so, please try what you said and send it to me only when it works before answering
PHP is a server-side language, so you'll need to submit the form in order to access its variables.
Since you didn't specify a method, GET is assumed, so you'll need the $_GET super-global:
echo $_GET['name'];
It's probably better though, to use $_POST (since it'll avoid the values being passed in the URL directly. As such, you can add method attribute to your <form> element as follows:
<form method="post">
<input type='text' name="name" value="myName" />
<input type="submit" name="go" value="Submit" />
</form>
Notice I also added a submit button for good measure, but this isn't required. Simply hitting return inside the textbox would submit the form.
Well, you have to POST your form to get the value of $_POST variables. Add this to your <form>
<form action="yourpagename.php" method="post">
<input type='text' name="name" value='myName'>
<button type="submit">Submit</button>
</form>
Click button and whatever is typed in your field will show up.
<html>
<body>
<form method="post" action="1.php">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
</body>
</html>
try this
<?php
if(isset($_REQUEST['name'])){
$name = $_REQUEST['name'];
echo $name;
}
?>
my php configuration on server are showing i can post variables to maximum size upto 8MB , thats enough .. but how to check for number of variables , sever is running ubuntu 4.4 , php .
i have a page which takes students marks and send them to a action page , but on action page doing echo for the post variables nothing is being displayed , where are doing an echo "hello"; this shows ...
this is the page which sends the variables
<form name="frm" action="marklistI.php" method="POST" class="" >
<?php $tb->displayTable() ?>
<div class="mainframe">
<input type="hidden" name="batch" value="<?php print $_GET['batch']; ?>"/>
<input type="hidden" name="sem" value="<?php print $_GET['sem']; ?>" />
<input type="hidden" name="chance" value="<?php print $_GET['chance']; ?>"/>
<input name="submit" type="submit" class="hide" value="Save"/>
<input type="hidden" name="url" value="<?php print $_SERVER['REQUEST_URI']; ?>"/>
</div>
</form>
and this are the variables are coming to action page .. but on echo they are not showing any value .
$dept =$_COOKIE['dept'];
$join=$_POST['batch'];
$type='e';
$sem=$_POST['sem'];
$chance=$_POST['chance'];
try placing this code on your action page:
if (isset($_GET)) {
echo "<h3>GET METHOD</h3>";
var_dump($_GET);
}
if (isset($_POST)) {
echo "<h3>POST METHOD</h3>";
var_dump($_POST);
}
if (isset($_COOKIE)) {
echo "<h3>COOKIE METHOD</h3>";
var_dump($_COOKIE);
}
See which method returns your variables and use it, otherwise, you are not filling any values on the form.
this is your code:
<form name="frm" action="marklistI.php" method="POST" class="" >
<?php $tb->displayTable(); ?>
<div class="mainframe"> <input type="hidden" name="batch" value="<?php print $_GET['batch']; ?>"/>
<input type="hidden" name="sem" value="<?php print $_GET['sem']; ?>" />
<input type="hidden" name="chance" value="<?php print $_GET['chance']; ?>"/>
<input name="submit" type="submit" class="hide" value="Save"/>
<input type="hidden" name="url" value="<?php print $_SERVER['REQUEST_URI']; ?>"/>
</div>
</form>
One possible reason for your issue:
You use "_GET[]" variables here but the form is POST.
GET and POST are two different methods to send data, GET is in the URL path (a=&b=&c=) while POST is hidden in the HTML headers.
So make sure you read those results as "$_POST['name']" and not GET.
I suggest this in the "receiving script" for debugging:
var_dump($_GET);
var_dump($_POST);
And in your browser use Chrome or Firefox + Firebug and Press "f12".
In that debugger you can catch the POST when you click the button and you can look which variables were sent.
That should help you debug your issue fast.
One other suggestion, I personally would write the code less "mixed".
It makes it hard to read and hard to modify.
Why not like this:
<?php
echo "
<form name='frm' action='marklistI.php' method='POST' class='' >".
$tb->displayTable().
"<div class='mainframe'>
<input type='hidden' name='batch' value='$_GET[batch]'/>
<input type='hidden' name='sem' value='$_GET[sem]' />
<input type='hidden' name='chance' value='$_GET[chance]'/>
<input name='submit' type='submit' class='hide' value='Save'/>
<input type='hidden' name='url' value='$_SERVER[REQUEST_URI]'/>
</div>
</form> ";
?>
My guess for your problem is that those values in the formular are actually empty, that's why you don't receive anything.