I have 4 different pages both with one form each.
I want to gather all the entries on each of the pages and submit once.
Here is code.
Page 1
<form action="page2" method="POST">
<input type="text" name="sex">
<input type="submit" value="Submit">
</form>
Page 2
<form action="page3" method="POST">
<input type="text" name="size">
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="submit" value="Submit">
</form>
Page 3
<form action="page4" method="POST">
<input type="text" name="colors">
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="submit" value="Submit">
</form>
Page 4
<form action="verNote.php" method="POST">
<input type="text" name="likes">
<input type="hidden" name="colors" value="<?php echo $_POST['colors'] ?>" > <input type="submit" value="Submit">
</form>
Then i will like to get all the infos on verNote.php
<?php
echo $_POST['sex'];
echo '<br>';
echo $_POST['size'];
echo '<br>';
echo $_POST['color'];
echo '<br>';
echo $_POST['likes'];
?>
This code above dont seem to post entries from both pages 1 and 2, just for 3 and 4 alone gets submitted.
Will appreciate immediate assistance form anyone who understands my question.
Regards!
You need to load the hidden fields again each time
Page 3
<form action="B.php" method="POST">
<input type="text" name="colors">
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="submit" value="Submit">
</form>
Page 4
<form action="B.php" method="POST">
<input type="text" name="likes">
<input type="hidden" name="colors" value="<?php echo $_POST['colors'] ?>" >
<input type="hidden" name="sex" value="<?php echo $_POST['sex'] ?>" >
<input type="hidden" name="size" value="<?php echo $_POST['size'] ?>" >
<input type="submit" value="Submit">
</form>
I didn't understand 100% what you're trying to achieve, but have you tried using sessions?
Do this in B.php:
<?php
session_start();
if( isset($_POST['sex']))
$_SESSION['sex'] = $_POST['sex'];
if( isset($_POST['size']))
$_SESSION['size'] = $_POST['size'];
if( isset($_POST['color']))
$_SESSION['color'] = $_POST['color'];
if( isset($_POST['likes']))
$_SESSION['likes'] = $_POST['likes'];
?>
Then you can retrieve the values from any other file, just call session_start(); and use the $_SESSION superglobal.
EDIT
Using sessions, you verNote.php file could be something like this:
<?php
session_start();
echo $_SESSION['sex'];
echo '<br />';
echo $_SESSION['size'];
echo '<br />';
echo $_SESSION['color'];
echo '<br />';
echo $_SESSION['likes'];
echo '<br />';
?>
Related
I have this source code...
<form method="post" id="center" action="">
<br>SpielerName: <?php echo $SpielerName; ?>
<br>Note: <input type="text" name="note" value=<?php echo $Note ?> >
<br>Tore: <input type="text" name="tore" value=<?php echo $Tore ?> >
<br><br><input type="submit" name="submit_eingabemaskeR" value="Abschicken">
In the following code I get the values for 'note'...
if (isset($_POST["submit_eingabemaskeR"]))
{
echo ("<br/>");
//Note
echo $_POST["note"];
But how can I echo the value of the first field -> SpielerName?
SpielerName is not a form field, its just text.
If you want its data submitted you can make a hidden form field with that value.
<form method="post" id="center" action="">
<br>SpielerName: <?php echo htmlspecialchars($SpielerName); ?>
<input type="hidden name="SpielerName" value="<?php echo htmlspecialchars($SpielerName); ?>">
<br>Note: <input type="text" name="note" value=<?php echo htmlspecialchars($Note) ?> >
<br>Tore: <input type="text" name="tore" value=<?php echo htmlspecialchars($Tore) ?> >
<br><br><input type="submit" name="submit_eingabemaskeR" value="Abschicken">
Use a hidden input.
<form method="post" id="center" action="">
<br>SpielerName: <?php echo $SpielerName; ?>
<input type="hidden" name="SpielerName" value=<?php echo $SpielerName; ?> >
<br>Note: <input type="text" name="note" value=<?php echo $Note ?> >
<br>Tore: <input type="text" name="tore" value=<?php echo $Tore ?> >
<br><br><input type="submit" name="submit_eingabemaskeR" value="Abschicken">
I have the following code where I am trying to get the 'Finalize Draft Order' submit button to only appear if the 'Create Draft Order' button has been pressed/set. Right now, the button does not show up after I hit the Create Draft Order button. It only displays if I take it out of the if(isset function.
What am I doing wrong?
<form method="POST" name="form">
<input type="submit" value="Create Draft Order" name="shuffle">
</form>
Shuffled results: <br>
<div class="main-bag">
<div class="shuffle_results" id="results"></div>
<form method="post">
<?php
$count = 0;
foreach ($array as $result) :
$count++;
$shuffle_count = $count;
$shuffle_firstname = htmlentities($result['firstname']);
$shuffle_lastname = htmlentities($result['lastname']);
$shuffle_id = htmlentities($result['id']);
$shuffle_username = htmlentities($result['username']);
$shuffle_email = htmlentities($result['email']);
?>
<input type="hidden" name="count[]" value="<?php echo $shuffle_count; ?>">
<input type="hidden" name="firstname[]" value="<?php echo $shuffle_firstname; ?>">
<input type="hidden" name="lastname[]" value="<?php echo $shuffle_lastname; ?>">
<input type="hidden" name="id[]" value="<?php echo $shuffle_id; ?>">
<input type="hidden" name="username[]" value="<?php echo $shuffle_username; ?>">
<input type="hidden" name="email[]" value="<?php echo $shuffle_email; ?>">
<?php
endforeach;
// only show this button if we have done a shuffle
if ( isset($_POST['shuffle'] ) ) :
echo '<input type="submit" value="Finalize Draft Order" name="insert">';
endif;
?>
UPDATE:
$array = array();
while ($row = mysqli_fetch_assoc($query)) {
$array[] = array(
'id' => $row['id'],
'firstname' => $row['firstname'],
'lastname' => $row['lastname'],
'username' => $row['username'],
'email' => $row['email']
);
if (isset($_POST['shuffle'])) {
}
}
shuffle($array);
echo json_encode($array);
I don't think $_POST['shuffle'] is set. instead of using the submit button for it change your code to:
<form method="POST" name="form">
<input type="hidden" name="shuffle" value="true">
<input type="submit" value="Create Draft Order">
</form>
I'm pretty sure submit's name doesn't count for the POST values.
I don't know what version of PHP meame69 and ScottyMcGready are using, but you very much CAN check to see if the button was clicked by checking for the isset($_POST["submit"]) is true.
http://www.learningaboutelectronics.com/Articles/How-to-check-if-the-submit-button-is-clicked-in-PHP.php
I cannot comment yet, but I will edit this once I figure out what's wrong with Becky's code.
Here's you're issue. Your input button is named shuffle, which is not passed when submitting. If you add a new hidden input element with the name "shuffle" that will pass it through.
edit:
You've said in your question its after the create draft button is pressed. Therefore as per your example:
<form method="POST" name="form">
<input type="submit" value="Create Draft Order" name="form">
<input type="hidden" name="shuffle" value="1">
</form>
Shuffled results: <br>
<div class="main-bag">
<div class="shuffle_results" id="results"></div>
<form method="post">
<?php
$count = 0;
foreach ($array as $result) :
$count++;
$shuffle_count = $count;
$shuffle_firstname = htmlentities($result['firstname']);
$shuffle_lastname = htmlentities($result['lastname']);
$shuffle_id = htmlentities($result['id']);
$shuffle_username = htmlentities($result['username']);
$shuffle_email = htmlentities($result['email']);
?>
<input type="hidden" name="count[]" value="<?php echo $shuffle_count; ?>">
<input type="hidden" name="firstname[]" value="<?php echo $shuffle_firstname; ?>">
<input type="hidden" name="lastname[]" value="<?php echo $shuffle_lastname; ?>">
<input type="hidden" name="id[]" value="<?php echo $shuffle_id; ?>">
<input type="hidden" name="username[]" value="<?php echo $shuffle_username; ?>">
<input type="hidden" name="email[]" value="<?php echo $shuffle_email; ?>">
<?php
endforeach;
// only show this button if we have done a shuffle
if ( isset($_POST['shuffle'] ) ) :
echo '<input type="submit" value="Finalize Draft Order" name="insert">';
endif;
?>
I have this url: torneioJogo.php?equipaleft=24&equiparight=25&torneioid=8
The following code is in this url...
<form method='GET' action='torneioJogoSub.php?'>
//THESE INPUTS DOWN HERE
<input type="hidden" name="equipa1" value="<?php $_GET['equipaleft'] ?>">
<input type="hidden" name="equipa2" value="<?php $_GET['equiparight'] ?>">
<input type="hidden" name="torneioid" value="<?php $_GET['torneioid'] ?>">
<div id="pontos">
<input type="submit" name="win1" value="<=Vencedor">
<input type="submit" name="emp" value="Empate">
<input type="submit" name="win2" value="Vencedor=>">
<br>
<=Pontos=><br>
//AND THESE INPUTS DOWN HERE
<input type="text" name="pontos1" size="3">
<input type="text" name="pontos2" size="3">
<br>
</div>
</form>
When I submit the form, I need all the data from those inputs in the next page where I have this:
echo "equipa1: " . $_GET['equipa1'];
echo "equipa2: " . $_GET['equipa2'];
echo "torneioid: " . $_GET['torneioid'];
echo "pontos1: " . $_GET['pontos1'];
echo "pontos2: " . $_GET['pontos2'];
What happens is $_GET['pontos2'] and $_GET['pontos1'] work but the values from the hidden inputs (which are being pulled from the url variables), echo nothing. What's happening? Is this a problem with GETs and POSTs or am I missing something else?
You need to echo the values out
<input type="hidden" name="equipa1" value="<?php echo $_GET['equipaleft'] ?>">
<input type="hidden" name="equipa2" value="<?php echo $_GET['equiparight'] ?>">
<input type="hidden" name="torneioid" value="<?php echo $_GET['torneioid'] ?>">
You need to actually output the variables into the form fields
<input type="hidden" name="equipa1" value="<?php echo $_GET['equipaleft'] ?>">
^^^^
So i need a way to be able to echo $row['username'] and echo $row['password'] where the id is specified.
So example is i have 3 rows i need to get information from with id numbers 20, 56, 88.
Now i have made the query $query = "SELECT * FROM Card_File WHERE id = $id";
How do i echo this data (keeping in mind its not in a table and could be placed in random location on the webpage, and the forms the outputs will be going into will be different (eg, not got the same form field names.))
echo $row['username'] $id=20;
echo $row['password'] $id=20;
echo $row['username'] $id=56;
echo $row['password'] $id=56;
echo $row['username'] $id=88;
echo $row['password'] $id=88;
I have been looking arround and seen some very complicated examples but dont belive its that hard to echo a row by id. I may be wrong
Below is not a great example of what the ends result is but would give you an idea.
<!DOCTYPE html>
<html>
<head>
<?php
// Connect to the database
$link = mysqli_connect('localhost','root','pass','ACS_SHAREPOINT_ADDONS');
// Select table and arguments
$query = "SELECT * FROM Card_File WHERE id = $id";
$result = mysqli_query($link, $query);
?>
</head>
<body>
<?php foreach($row = mysqli_fetch_array($result)): ?>
<div class="loginForms">
<form target="_blank" action="https://www.website.com" method="post">
<input type="hidden" name="username" id="auth-form-login" value="<?php $id=20 echo $row['username']; ?>"/>
<input type="hidden" name="password" id="auth-form-pass" value="<?php $id=20 echo $row['password']; ?>"/>
<input type="hidden" name="redirDocument" value="user"/>
<input type="hidden" name="query" value=""/>
<input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
<input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
</form>
</div>
<div class="loginForms">
<form target="_blank" action="https://www.website.com" method="post">
<input type="hidden" name="username" id="auth-form-login" value="<?php $id=56 echo $row['username']; ?>"/>
<input type="hidden" name="password" id="auth-form-pass" value="<?php $id=56 echo $row['password']; ?>"/>
<input type="hidden" name="redirDocument" value="user"/>
<input type="hidden" name="query" value=""/>
<input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
<input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
</form>
</div>
<div class="loginForms">
<form target="_blank" action="https://www.website.com" method="post">
<input type="hidden" name="username" id="auth-form-login" value="<?php $id=88 echo $row['username']; ?>"/>
<input type="hidden" name="password" id="auth-form-pass" value="<?php $id=88 echo $row['password']; ?>"/>
<input type="hidden" name="redirDocument" value="user"/>
<input type="hidden" name="query" value=""/>
<input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
<input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
</form>
</div>
<?php endforeach; ?>
</body>
</html>
I believe this is what you want to do.
<?php
$ids_tofind = array(1,6,3); //for example
$id = implode(",",$ids_tofind);
$link = mysqli_connect('localhost','root','pass','ACS_SHAREPOINT_ADDONS');
// Select table and arguments
$query = "SELECT * FROM Card_File WHERE id IN(". $id.")";
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_array($result)){;?>
<div class="loginForms">
<form target="_blank" action="https://www.website.com" method="post">
<input type="hidden" name="username" id="auth-form-login" value="<?php echo $row['username']; ?>"/>
<input type="hidden" name="password" id="auth-form-pass" value="<?php echo $row['password']; ?>"/>
<input type="hidden" name="redirDocument" value="user"/>
<input type="hidden" name="query" value=""/>
<input type="hidden" name="urlString" value="doc-rc-login;lng-ww-en;tpl-;ver-;"/>
<input type="submit" name="authSubmit" value="AVG Resellers Center" id="auth-form-submit"/>
</form>
</div>
<?php };?>
This will echo out the form for all three users with ID 1, 6 and 3.
I am encountering a strange phenomena: When I submit a form in my code, then beside doing what is there in that form, it looks like it also trigger the comment form. So when the page is reloading, I get some blank comments or duplicate comments. In my code I have several forms with submit, and one of that is the form for input comment:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="a" value="<?php echo $_GET['id'] ?>">
<input type="hidden" name="b" value="<?php echo $_SERVER['REMOTE_ADDR'] ?>">
<input type="text" name="c" value="Name"><br>
<textarea name="d">
</textarea>
<input type="submit" />
</form>
Could any of you point out for me where it gets wrong?
As requested, I post the whole (updated) code here:
<h3>Comments</h3>
<!-- <p>Put your comments here: </p> -->
<?php
//a: commenters
$i = addslashes($_POST['a']);
$ip = addslashes($_POST['b']);
$a = addslashes($_POST['c']);
$b = addslashes($_POST['d']);
if(isset($_POST['form1'])){
if(isset($i) & isset($ip) & isset($a) & isset($b))
{
$connector= new DbConnector();
$r = mysql_query("SELECT COUNT(*) FROM `databasename`.`ban` WHERE ip=$ip"); //Check if banned
$r = mysql_fetch_array($r);
if(!$r[0]) //Phew, not banned
{ // echo "a: ".$a." b: ".$b." ip: ".$ip." i: ".$i."";
$Date4=date('Y-m-d H:i:s');
if(mysql_query("INSERT INTO `databasename`.`Comments` VALUES ('$a', '$b', '$ip', '$Date4')"))
{
?>
<script type="text/javascript">
window.location="/index.php?id=".<?php echo $i; ?>;
</script>
<?php
}
else echo "Error, in mysql query";
}
else echo "Error, You are banned.";
}
}
$x = mysql_query("SELECT * FROM `databasename`.`Comments` ORDER BY i DESC ");
while($r = mysql_fetch_object($x)) echo "<div class='c'>".$r->a."<p>".$r->b."</p> </div>";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="a" value="<?php echo $_GET['id'] ?>">
<input type="hidden" name="b" value="<?php echo $_SERVER['REMOTE_ADDR'] ?>">
<input type="text" name="c" value="Name"><br>
<textarea name="d">
</textarea>
<input type="submit" name="form1" />
</form>
You need use isset()
in HTML submit button you need to use name attribute for each and every form,
<input type="submit" name="form1" />
IN PHP,
<?php
if(isset($_POST['form1']){
echo $_POST['a'];
}
?>
Your code,
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="a" value="<?php echo $_GET['id']; ?>">
<input type="hidden" name="b" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>">
<input type="text" name="c" value="Name"><br>
<textarea name="d"></textarea>
<input type="submit" name="form1" />
</form>
I would use:
if(!empty($_POST['form1']){
echo $_POST['a'];
}
empty() will return true if the variable is an empty string, false, array(), NULL, “0?, 0, and an unset variable.
Read more: http://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/