ccirish Posted September 9, 2012 Share Posted September 9, 2012 I'm trying to create a PHP Script that looks in a file for information, displays that information, and then the user can change the information in the fields if they so wish. It pulls data just fine, but I cannot for the life of me get it to pull data from the text boxes and put it into variables. I've searched high and low and can't figure out what I am doing wrong. Thanks for your help. -bash-4.1$ vim feedmaker.php <?php if (!isset($_GET['id']) or !isset($_GET['game'])) die; $feedid = $_GET['id']; $roTa = $_GET['game']; $file = "$feedid.feed"; $filex = fopen($file, "r"); $i = 0; while (!feof($filex)) { $line_of_text .= fgets($filex); } $members = explode("\n", $line_of_text); fclose($filex); $count = count($members); $j = 0; for ($j==0; $j<=$count; $j++){ list($roTb, $aPT, $hPT, $aPTm, $hPTm, $tot, $om, $um, $aML, $hML) = explode("|",$members[$j]); if ($roTa == $roTb){break;} } function edit_line($members, $feedid){ list($roTb, $aPT, $hPT, $aPTm, $hPTm, $tot, $om, $um, $aML, $hML) = explode("|",$members); $hPTn = $_POST['hPTc']; $aPTn = $_POST['aPTc']; $totn = $_POST['totc']; echo "<html>\n"; echo "<head>\n"; echo "</head>\n"; echo "<body>\n"; echo "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" style=\"width: 250px; \">\n"; echo "<caption>\n"; echo "Game Data:</caption>\n"; echo "<form method=\"post\" action=\"feedmaker.php?update&id=",$feedid,"&game=",$roTb,"&aPT=",$aPTn,"&hPT=",$hPTn,"&tot=",$totn,"\">"; echo "<tbody>\n"; echo "<tr>\n"; echo "<td>\n"; echo "<p style=\"text-align: right; \">\n"; echo "Rotation: </p>\n"; echo "</td>\n"; echo "<td style=\"text-align: center; \">\n"; echo "\n"; echo " ",$roTb," </td>\n"; echo "<td style=\"text-align: center; \">\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td style=\"text-align: right; \">\n"; echo "Away Points:</td>\n"; echo "<td style=\"text-align: center; \">\n"; echo " ",$aPT," </td>\n"; echo "<td>\n"; echo "<p style=\"text-align: center; \">\n"; echo "<input maxlength=\"5\" name=\"aPTc\" size=\"5\" type=\"text\"></p>\n"; echo "</td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td>\n"; echo "<p style=\"text-align: right; \">\n"; echo "Home Points:</p>\n"; echo "</td>\n"; echo "<td style=\"text-align: center; \">\n"; echo " ",$hPT," </td>\n"; echo "<td style=\"text-align: center; \">\n"; echo "<input maxlength=\"5\" name=\"hPTc\" size=\"5\" type=\"text\"></td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td>\n"; echo "<p style=\"text-align: right; \">\n"; echo "Game Total:</p>\n"; echo "</td>\n"; echo "<td style=\"text-align: center; \">\n"; echo " ",$tot," </td>\n"; echo "<td style=\"text-align: center; \">\n"; echo "<input maxlength=\"5\" name=\"totc\" size=\"5\" type=\"text\"></td>\n"; echo "</tr>\n"; echo "<tr>\n"; echo "<td style=\"border-color: rgb(255, 255, 255); \">\n"; echo " </td>\n"; echo "<td style=\"border-color: rgb(255, 255, 255); \">\n"; echo " </td>\n"; echo "<td style=\"text-align: center; \">\n"; echo "<input name=\"button\" type=\"submit\" value=\"Enter\"></td>\n"; echo "</tr>\n"; echo "</tbody>\n"; echo "</table>\n"; echo"</form>"; echo "<p>\n"; echo " </p></body>\n"; echo "</html>\n"; echo "\n"; } if (isset($_GET['edit'])) edit_line($members[$j],$feedid); ?> Quote Link to comment https://forums.phpfreaks.com/topic/268173-php-form-and-textbox/ Share on other sites More sharing options...
premiso Posted September 9, 2012 Share Posted September 9, 2012 Ok, looking at your script, decided to make some improvements to it. You can choose to use it or not, I just find this a bit more manageable and less error proned. As to your issue I am not sure what you are getting at in "putting into variables" . So when as user submits the form, you want to check for that and put the POST data into a variable? Or do you want it to write it back to the file? If you can clarify that a little bit, I will be more than happy to assist. <?php if (!isset($_GET['id']) or !isset($_GET['game'])) die; $feedid = $_GET['id']; $roTa = $_GET['game']; $file = "$feedid.feed"; $members = file($file); $count = count($members); for ($j=0; $j<=$count; $j++){ list($roTb, $aPT, $hPT, $aPTm, $hPTm, $tot, $om, $um, $aML, $hML) = explode("|",$members[$j]); if ($roTa == $roTb){break;} } function edit_line($members, $feedid) { list($roTb, $aPT, $hPT, $aPTm, $hPTm, $tot, $om, $um, $aML, $hML) = explode("|",$members); $hPTn = isset($_POST['hPTc'])?$_POST['hPTc']:''; $aPTn = isset($_POST['aPTc'])?$_POST['aPTc']:''; $totn = isset($_POST['totc'])?$_POST['totc']:''; $display = <<<DISPLAY <html> <head> </head> <body> <table border="0" cellpadding="1" cellspacing="1" style="width: 250px; "> <caption> Game Data:</caption> <form method="post" action="feedmaker.php?update&id={$feedid}&game={$roTb}&aPT={$aPTn}&hPT={$hPTn}&tot={$totn}">"; <tbody> <tr> <td> <p style="text-align: right; "> Rotation: </p> </td> <td style="text-align: center; "> {$roTb} </td> <td style="text-align: center; "> </tr> <tr> <td style="text-align: right; "> Away Points:</td> <td style="text-align: center; "> {$aPT} </td> <td> <p style="text-align: center; "> <input maxlength="5" name="aPTc" size="5" type="text"></p> </td> </tr> <tr> <td> <p style="text-align: right; "> Home Points:</p> </td> <td style="text-align: center; "> {$hPT} </td> <td style="text-align: center; "> <input maxlength="5" name="hPTc" size="5" type="text"></td> </tr> <tr> <td> <p style="text-align: right; "> Game Total:</p> </td> <td style="text-align: center; "> {$tot} </td> <td style="text-align: center; "> <input maxlength="5" name="totc" size="5" type="text"></td> </tr> <tr> <td style="border-color: rgb(255, 255, 255); "> </td> <td style="border-color: rgb(255, 255, 255); "> </td> <td style="text-align: center; "> <input name="button" type="submit" value="Enter"></td> </tr> </tbody> </table> </form> <p> </p></body> </html> DISPLAY; echo $display; } if (isset($_GET['edit'])) edit_line($members[$j],$feedid); Quote Link to comment https://forums.phpfreaks.com/topic/268173-php-form-and-textbox/#findComment-1376458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.