Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Form varibles disappering

Status
Not open for further replies.

dagoat10

Programmer
Jun 3, 2010
74
US
I am passing a varible to be used in another php form, but when i hit the submit button for the selection form the value of the Previous forms field name disappears.

Form 1:
Code:
<?php
echo "
<html>
<head>
</head>
<body>
<form action='selection.php', method='post'>
Table Name: <input type='text' name=\"Tname\" value=$Tname />
<br>
<input type='submit' name='Create' value='Create Team' />
</form>";
?>

Form 2:
Code:
echo $_POST["TeamName"];
echo $Team;



$query="SELECT * FROM NFL_Players";
$result=mysql_query($query, $conn);
echo mysql_error();

echo "<b>";
echo "<form action='selection.php' method='post'>";

echo "<select name='Plyr' size='10'>";
while ($row = mysql_fetch_array($result))
{
    echo "<option>";
    echo $row['Player'];
    echo "</option>";
    echo "<br>";
}
echo "</select>";

echo "<input type='hidden' name='TeamName' value=$Team />";

echo "<input type='submit' />";

echo "</form>";

i don't understand :(
 
the control name is not called Team Name, you have called it Tname

also you are not enclosing the value of the control in quotes.
 
ok that worked but when i do another submit on the same form the value disappears again. In other words i submit data from the first page to the second page, but when i submit data from the second page to the second page again the Post Variable disappears and turn into a backslash

Code:
echo "Which one";
$Team=$_POST["Tname"];
echo $TeamName;

$query="SELECT * FROM NFL_Players";
$result=mysql_query($query, $conn);
echo mysql_error();

echo "<b>";
echo "<form action='selection.php' method='post'>";

echo "<select name='Plyr' size='10'>";
while ($row = mysql_fetch_array($result))
{
    echo "<option>";
    echo $row['Player'];
    echo "</option>";
    echo "<br>";
}
echo "</select>";

echo "<input type='hidden' name='TeamName' value=$Team />";

echo "<input type='submit' name='Pick' value='Select Player' />";

echo "</form>";

what else is missing.
 
without that variable i can't do the following:

Code:
$check="SELECT Player from $Team";
$checkres=mysql_query($check, $conn);
echo mysql_error();

while($checkrow = mysql_fetch_array($checkres))
{
    if($_POST['Plyr'] == $checkrow['Player'])
    {
        $exists=true;
    }
}

echo $exists;
if(!$exists)
{
        $query2="INSERT INTO $Team (Player) Values('$_POST[Plyr]')";
        mysql_query($query2, $conn);
        echo mysql_error();
}
 
OUCH!!!

Please stop here and read about SQL injection. Oh, and read a good book on security for web programmers.

Look in the PHP manual for sessions ( ) and never rely on hidden variables to be hidden or untouched.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top