Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
i got this script below. How do i get the answer from the selected item?
how can i get the option back with the $_POST?
<?php
mysql_select_db("internetsites");
$query1 = "SELECT * FROM internetsites ORDER BY name_site";
$result = mysql_query($query1) or die(mysql_error());
?>
<form name="delete" action="delete.php" method="post">
choose a site you want to delete.
<select>
<?php
while($row = mysql_fetch_array($result))
{
echo "<option value=" . $row['name_site'] . "'>" . $row['name_site'] . "</option>";
}
?>
</select>
<input type="submit" value="delete">
Can someone help me?
You give your select a name atribute, then you take the whole code inside <form method="post" action="delete.php"></form> and then you use $_POST['nameattribute'].
Try this, To Post form elements need input name attribute,
<form name="delete" action="delete.php" method="post">
choose a site you want to delete.
<select name="name_site" id="name_site">
<?php
while($row = mysql_fetch_array($result))
{
echo "<option value='".$row['name_site']."'>" . $row['name_site'] . "</option>";
}
?>
</select>
<input type="submit" name="submit" value="delete">
</form>
in delete.php,
<?php
if(isset($_POST['submit'])){
echo $_POST['name_site'];
}
?>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hello i want to check if the textarea isnt empty and i still can´t get the echo that i want even when the textarea isnt empty and input is set
here is my code:
<form method="post" action="">
<input type="text" name="jmeno"/>
<textarea name="textarea" id="textarea" rows="5" cols="40"></textarea>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['jmeno']) AND !empty($_POST['textarea'])){
echo "dokončeno";
}
?>
How about this:
if (!is_null($_POST['jmeno']) && strlen(trim($_POST['jmeno'])) > 0) {
echo "dokončeno";
}
As far as I understand you want your code to check if the submit button is pressed and the textarea isn't empty. I would say the code is:
if(isset($_POST['jmeno'])){
if(strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
}
OR simply:
if(isset($_POST['jmeno']) && strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
if (isset($_POST['jmeno']) && strlen(trim($_POST['textarea']))>0)
{
echo "dokončeno";
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How do I Get This HTML 5 Form To Give PHP The Input Data Then Display It On The Screen. I want to collect data in a form. Convert it into a php variable and then echo it out in a way that I can read it.
<form>
First name:<br>
<input type="text" name="name">
</form>
<body>
<pre>
<?php
$taco = htmlspecialchars($_POST["name"]) . '!';
$taco = $_POST;
echo $taco;
?>
</pre>
</body
</html>
How about the following:
<?php
if($_POST) { // check if the page is posted not with a $_GET
foreach($_POST as $field => $value) { // Foreach field
$value = strip_tags($value); // Strip html tags (you can add more)
echo 'Field: '.$field.' has value: '.$value.'<br>'; // output
}
}
?>
<form action="" method="post">
First name: <input type="text" name="first_name">
<input type="submit" value="Display">
</form>
Just put it all in one php file. You can add as many fields as you want.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
this code is for showing data and updating data.when query string is setted text boxes appersand submit button will also appears
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<from action="category_listing.php" method="post">
<table border="5" width="250">
<?php
$queryy="select COUNT(*) from category"; //count rows
$results= mysqli_query($link, $queryy);
while ($res= mysqli_fetch_array($results))
{$total_rows=$res[0];}
$offset=$total_rows-1;
$qry="select ID from category LIMIT $offset,1";
$res= mysqli_query($link, $qry);
while ($res2= mysqli_fetch_array($res))
{
$lastvalue=$res2[0];
}
$query="select * from category";
$result= mysqli_query($link, $query);
while ($r= mysqli_fetch_array($result))
{
if(isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && ($_REQUEST['id']>=0 ) && $_REQUEST['id']<=$lastvalue)
{
$id=$_REQUEST['id'];
if($r[0]==$id)
{
$name=$r[1];
echo '<tr><td>';
echo 'Name';
echo '</td>';
echo '<td><input type=text value="'.$r[1].'"></td></tr>';
echo '<tr><td colspan="2">';
echo '<input type="submit" name="btnupdate" value="Update">';
echo '<input type="submit" value="Cancel">';
echo '</td></tr>';
}
}
else
{
static $var=1;
if($var==1){echo '<tr><th>ID</th><th>Name</th> <th>Action</th></tr>';} //headers of category
echo "<tr><td>$r[0]</td><td>$r[1]</td>";
echo "<td><a href='category_listing.php?id=$r[0]'>Edit</a></td></tr>";
$var++;
}
}
?>
</table>
<input type="hidden" name="hidden" value="<?php if(isset($id)) echo $id;?>"/>
</from>
</body>
</html>
I just set query string. when it is setted in URL. Text box appears and after pressing submit, page is not submitting.
change
<from action="category_listing.php" method="post">
to
<form action="category_listing.php" method="post">
</from> to </form>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to retrieve the id of the page but the page is dynamic depending upon the id
e.g filepath/Post.php?id=5
Data is sent through a form action where i want to get the other pages id but i don't know how to do it.
echo "<form action='../PHP/Comment.php' method='post'>" . "<input class='comment' type='text' name='comment' placeholder='Add a comment'>" . "</form>"
//then what the action does
$id = isset($_GET['id']); //trying to get the page id but it doesn't
$comment = $_POST['comment'];
//insertion into the table in the database.
mysql_query("INSERT INTO comments (id, comment) VALUES ('$id', '$comment')")
There are better ways to do this. have you tried using a dedicated $_SESSION variable? In PHP, i cud do this:-
<?php $_SESSION['PAGE_ID'] = 10;?>
then retrieve it on the form as
<?php echo $_SESSION['PAGE_ID']?>
Try this
echo "<form action='../PHP/Comment.php' method='post'>
<input class='comment' type='text' name='comment' placeholder='Add a comment'>
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
<input type="submit" value="Submit" />
</form>"
Then form processing
$id = isset($_POST['id']);
$comment = $_POST['comment'];
mysql_query("INSERT INTO comments (id, comment) VALUES ($id, '$comment')");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have accessed a MySql database, retrieved the values from the relevant table and put them in a drop down list using:
$material_query= "SELECT material FROM materials";
$material_query_run = mysql_query($material_query);
echo "<select>";
while ($material_query_array= mysql_fetch_array($material_query_run) ){
echo "<option value='' >".$material_query_array['material']."</option>";
}echo "</select>";
How would I now store the selected value from the drop down list within a variable? I think that I need to use POST however, I cannot figure out how.
So the select element needs to be inside a form, which you can then submit and the data submitted (by post or get) can then be processed.
Your select box needs to have a name attribute so that it can be identified. Also you need to have a value in the value attribute of the option elements, as this is the data that is sent.
For example, on your page (e.g. page.php) you would have your current code inside html form tags:
// The Form
<form action="page.php" method="post">
<?php
$material_query = "SELECT material FROM materials";
$material_query_run = mysql_query( $material_query );
echo "<select name='mySelect'>";
while ( $material_query_array = mysql_fetch_array( $material_query_run ) ) {
echo "<option value='".$material_query_array['material']."' >".$material_query_array['material']."</option>";
}
echo "</select>";
?>
<input type="submit" name="submit"/>
</form>
//Process the form
//check if form is submitted
if ( isset( $_POST['submit'] ) ) {
//is submitted
$variable = $_POST['mySelect'];
//DO STUFF WITH DATA
}
So here I have done the following:
Added the form tags ( SEE: http://www.w3schools.com/php/php_forms.asp )
Added the name attribute to the select tags
Added the same value that the select displays to the value attribute of the option tags
Added code to process the form when it is submitted ( See the above link again )
When the user hits the submit button, the data will need to be sent to your PHP processor, either using GET or POST. In your processor, then you would access the SELECT field values just like any other form element.
<form action="processor.php" method="POST">
// FORM ELEMENTS HERE
<input type="submit" value="Go!">
</form>
In your processor:
<?php
$selectbox = $_POST['selectbox'];
Now you can sanitize and use the variable $selectbox in your script or pass it to your database.
You need something like:
<form action="post.php" method="post" name="select_form">
<?php
$material_query="SELECT material FROM materials";
$material_query_run =mysql_query($material_query);
echo "<select name=\"selectbox\">";
while ($material_query_array= mysql_fetch_array($material_query_run) ){
echo "<option value='".$material_query_array['material']."'>".$material_query_array['material']."</option>";
}
echo "</select>";
?>
<input type="submit" value="Submit" name="submit">
</form>
Then in post.php
<?php
if($_POST){
$select=$_POST['selectbox'];
}
?>
On a side note use PDO (http://www.php.net/manual/en/book.pdo.php) or MySQLI (http://uk3.php.net/manual/en/book.mysqli.php) as the MySql interface is outdated.