PHP - A $_post['titel[$n]'] Problem
I'm making a script for editing lines in a text file.
PHP code form form script: $n = 0; $bestand = "../test.txt"; $gegevens = file($bestand); //count lines titel.txt $lines = count(file($bestand)); while($n < $lines) { $items = explode("|", $gegevens[$n]); $titel = $items[0]; $beschrijving = $items[1]; $n=$n+1; echo "<tr> <td><input type=\"text\" class=\"edit\" name=\"titel[".$n."]\" value=\" ".$titel." \" /></td> <td><textarea name=\"beschrijving[".$n."]\">".$beschrijving."</textarea></td> </tr>"; } Code of processing script <?php $n = 1; $bestand = "../test.txt"; $lines = count(file($bestand)); while($n < $lines){ //Set variables $titel = $_POST['titel[$n]']; //Replace 'Enter' for '<br />' $_POST['beschrijving[$n]'] = preg_replace ("#\r?\n#", '<br />', $_POST['beschrijving[$n]']); $beschrijving = $_POST['beschrijving[$n]']; //Write $titel $handle = fopen($bestand, "a"); fwrite($handle, "".$titel."|"); fclose($handle); //Write $beschrijving $handle = fopen($bestand, "a+"); fwrite($handle, "".$beschrijving." "); fclose($handle); $n=$n+1; } ?> De form scripts works fine, no problems. But the processing script give me the next notices: Code: [Select] Notice: Undefined index: titel[$n] in /var/www/NellekeTekent/cms/edit.php on line 10 Notice: Undefined index: beschrijving[$n] in /var/www/NellekeTekent/cms/edit.php on line 13 Notice: Undefined index: titel[$n] in /var/www/NellekeTekent/cms/edit.php on line 10 Notice: Undefined index: titel[$n] in /var/www/NellekeTekent/cms/edit.php on line 10 Notice: Undefined index: titel[$n] in /var/www/NellekeTekent/cms/edit.php on line 10 I gues the problem is '$n' when setting $titel and $beschrijving. But I don't know how to solve it. Can you help me? Similar Tutorialshello i have a script and i keep getting an error on php4 i dont get that error only on php5 <?php session_start(); error_reporting(E_ALL); ini_set('display_errors',1); function query_str($params) { $str = ''; foreach ($params as $key => $value) { $str .= (strlen($str) < 1) ? '' : '&'; $str .= $key . '=' . rawurlencode($value); } return ($str); } if($_GET['id']=='1'){ $query=parse_str($_POST); query_str($query); $username=rtrim($username); $password=rtrim($password); // .... continue echo $username.':'.$password.chr(10); } Code: [Select] Warning: parse_str() expects parameter 1 to be string, array given in /var/www/poo/do.php on line 15 Warning: Invalid argument supplied for foreach() in /var/www/poo/do.php on line 7 Notice: Undefined variable: username in /var/www/poo/do.php on line 17 Notice: Undefined variable: password in /var/www/poo/do.php on line 18 the html code is this Code: [Select] <form name="Form_Auth" action="do.php?id=1" method="post" target="_top"> <input name="username" id="txt" value="Nome utente" class="nomeutente"> <input name="password" type="password" maxlength="32" id="pass" value="password" class="password lf"> <input name="bottone" type="submit" class="bottone rf" value="Invia" alt="accedi"> </form> Hi, I am using POST to send the id of a row in a MySQL database, this id should then be used to delete the row from MySQL, this all works fine when I use GET, but as soon as i try and use POST (for security reasons) it deletes another row. Here is the code ($_POST): Code: [Select] <?php $member = $logged['username']; //IFMESSAGES THEN SAY OTHERWISE SAY NO $seemessages = mysql_query("SELECT * FROM `rmail` WHERE `to` = '$member' && `status` = 'unread'"); $howmanymessages = mysql_num_rows($seemessages); $seereadmessages = mysql_query("SELECT * FROM `rmail` WHERE `status` = 'read' && `to` = '$member'"); $howmanyreadmessages = mysql_num_rows($seereadmessages); $totalmessages = $howmanyreadmessages + $howmanymessages; //MENU FOR USING EMAIL VIEWED ON ALL SECTIONS OF R-MAIL echo'<div id="emailmenu"><a href="rmail.php">Home</a>|<a href="rmail.php?inbox">Inbox('.$howmanymessages.'/'.$totalmessages.')</a>|<a href="rmail.php?compose">Compose</a>| </div><br/>'; if(isset($_POST['delete'])){ //DELETE MESSAGE $id = $_POST['delete']; echo $id; $newvalue = mysql_query("SELECT * FROM data"); $newvalue = mysql_fetch_array($newvalue); $newvalue = $newvalue['rmailsent']; $newvalue = $newvalue-1; mysql_query("UPDATE data SET rmailsent = '$newvalue'"); mysql_query("DELETE FROM rmail WHERE `id` = '$id'"); echo "Message has been deleted!"; } else if(isset($_GET['inbox'])){ $username = $logged['username']; //DISPLAY EMAILS FOR USER //WHEN DISPLAYING DISPLAY LINK WITH THE ID TO VIEW THE SPECIFIC MESSAGE $getemail = mysql_query("SELECT * from rmail WHERE `to` = '$username' ORDER BY `id` DESC"); echo' <table border="1"> <tr> <td> <font size="5">Check</font> </td> <td> <font size="5">Status</font></td> <td><font size="5">From</font></td> <td width="500"><font size="5">Subject</font></td> <td><font size="5">Date Sent</font></td> <td><font size="5">Time Sent</font></td> <td><font size="5">Action</font></td> </tr> '; while($email = mysql_fetch_array($getemail)){ $id = $email['id']; if($email['status'] == "unread"){ echo "<tr bgcolor='#666666'>"; }else{ echo "<tr>"; } echo '<td><input type="checkbox" name="'.$email['id'].'checked" class="check"></td>'; echo '<td>'; if($email['status'] == "unread"){ echo '<center><img src="/webimages/unread.gif" alt="Message Unread" width="30" height="25"></center>'; }else if($email['status'] == "read"){ echo '<center><img src="/webimages/read.gif" alt="Message Read" width="30" height="25"><center>'; } echo '</td>'; echo '<td>'.$email['from'].'</td>'; echo '<td><a href="rmail.php?viewmail&id='.$email['id'].'">'.$email['subject'].'</a></td>'; echo '<td>'.$email['date'].'</td>'; echo '<td>'.$email['time'].'</td>'; echo '<td><form action="rmail.php" method="post"> <input type="hidden" value="'.$email['id'].'" name="delete"><input type="image" src="/webimages/delete.png" onclick="return confirm(\'Are you sure you want to Delete?Click Ok to proceed and Delete or Cancel if you do not want to delete!\');"><a href="viewmembers.php?user='.$email['from'].'"><img src="/webimages/eye3.gif" border="0" height="25" width="30"></a></td>'; echo "</font></tr>"; } echo "</table>"; } </html> Here is the code with $_GET (this works but $_POST doesnt): Code: [Select] <?php $member = $logged['username']; //IFMESSAGES THEN SAY OTHERWISE SAY NO $seemessages = mysql_query("SELECT * FROM `rmail` WHERE `to` = '$member' && `status` = 'unread'"); $howmanymessages = mysql_num_rows($seemessages); $seereadmessages = mysql_query("SELECT * FROM `rmail` WHERE `status` = 'read' && `to` = '$member'"); $howmanyreadmessages = mysql_num_rows($seereadmessages); $totalmessages = $howmanyreadmessages + $howmanymessages; //MENU FOR USING EMAIL VIEWED ON ALL SECTIONS OF R-MAIL echo'<div id="emailmenu"><a href="rmail.php">Home</a>|<a href="rmail.php?inbox">Inbox('.$howmanymessages.'/'.$totalmessages.')</a>|<a href="rmail.php?compose">Compose</a>| </div><br/>'; if(isset($_GET['delete'])){ //DELETE MESSAGE $id = $_GET['delete']; echo $id; $newvalue = mysql_query("SELECT * FROM data"); $newvalue = mysql_fetch_array($newvalue); $newvalue = $newvalue['rmailsent']; $newvalue = $newvalue-1; mysql_query("UPDATE data SET rmailsent = '$newvalue'"); mysql_query("DELETE FROM rmail WHERE `id` = '$id'"); echo "Message has been deleted!"; } else if(isset($_GET['inbox'])){ $username = $logged['username']; //DISPLAY EMAILS FOR USER //WHEN DISPLAYING DISPLAY LINK WITH THE ID TO VIEW THE SPECIFIC MESSAGE $getemail = mysql_query("SELECT * from rmail WHERE `to` = '$username' ORDER BY `id` DESC"); echo' <table border="1"> <tr> <td> <font size="5">Check</font> </td> <td> <font size="5">Status</font></td> <td><font size="5">From</font></td> <td width="500"><font size="5">Subject</font></td> <td><font size="5">Date Sent</font></td> <td><font size="5">Time Sent</font></td> <td><font size="5">Action</font></td> </tr> '; while($email = mysql_fetch_array($getemail)){ $id = $email['id']; if($email['status'] == "unread"){ echo "<tr bgcolor='#666666'>"; }else{ echo "<tr>"; } echo '<td><input type="checkbox" name="'.$email['id'].'checked" class="check"></td>'; echo '<td>'; if($email['status'] == "unread"){ echo '<center><img src="/webimages/unread.gif" alt="Message Unread" width="30" height="25"></center>'; }else if($email['status'] == "read"){ echo '<center><img src="/webimages/read.gif" alt="Message Read" width="30" height="25"><center>'; } echo '</td>'; echo '<td>'.$email['from'].'</td>'; echo '<td><a href="rmail.php?viewmail&id='.$email['id'].'">'.$email['subject'].'</a></td>'; echo '<td>'.$email['date'].'</td>'; echo '<td>'.$email['time'].'</td>'; echo '<td><a href="rmail.php?delete='.$email['id'].'">DELETE</a><a href="viewmembers.php?user='.$email['from'].'"><img src="/webimages/eye3.gif" border="0" height="25" width="30"></a></td>'; echo "</font></tr>"; } echo "</table>"; } </html> Any Ideas? Thanks Rhys Hi there I'm trying to make this form submit...but alas, is to no avail .... i have two forms on top of each other one of them is: Code: [Select] <form name="entries_form" method="post" action="index.php"> <table> <tr> <th><label>Date</label></th> <th><label>From</label></th> <th><label>To</label></th> <th><label>Break</label></th> <th><label>Hours</label></th> <th><label>Required Hours</label></th> <th><label>Notes</label></th> </tr> <tr> <td> <input name="Date" type="text" id="Date" /> </td> <td> <input name="From" type="text" id="From" /> </td> <td> <input name="To" type="text" id="To" /> </td> <td> <input name="Break" type="text" id="Break" /> </td> <td> <input name="Hours" type="text" id="Hours" /> </td> <td> <input name="Rqrd_hrs" type="text" id="Rqrd_hrs" /> </td> <td> <input name="Notes" type="text" id="Notes" /> </td> <td> <input type="submit" name="Save" value="Save" id="Save" style="background-color:#7A70A4;" /> </td> </tr> </table> </form> to post i'm using this code (to much over the top maybe): Code: [Select] <?php $session = new Session(); $u_id = $session->get('id'); //to get the user id from session if(isset($_POST['submit']) == 'Save'){//form's button name is Save $entry->user_id = $user_id = $u_id; $entry->date = $date = trim(strtolower($_POST['Date'])); $entry->start_time = $start_time = trim(strtolower($_POST['From'])); $entry->end_time = $end_time = trim(strtolower($_POST['To'])); $entry->breaks = $break = trim(strtolower($_POST['Break'])); $entry->total_hours = $total_hours = trim(strtolower($_POST['Hours'])); $entry->reqd_hours = $required_hours = trim(strtolower($_POST['Rqrd_hrs'])); $entry->notes = $notes = trim(strtolower($_POST['Notes'])); $entry->add_entry(); }else die("Not Posted"); ?> the add entry() function does the following: Code: [Select] public function add_entry(){ global $database; $sql = "INSERT INTO sheetentries ("; $sql .= "user_id, date, start_time, end_time, break, required_hours, total_hours, notes"; $sql .= ") VALUES ('"; $sql .= $this->user_id ."', '"; $sql .= $this->date ."', '"; $sql .= $this->start_time ."', '"; $sql .= $this->end_time ."', '"; $sql .= $this->breaks ."', '"; $sql .= $this->reqd_hours ."', '"; $sql .= $this->total_hours ."', '"; $sql .= $this->notes ."')"; $database->query($sql); } the user_id or $u_id brought from the session when the user loggs in: Code: [Select] $u_id = $session->get('id'); anyway, whenever i try submitting the form nothing happens, what am i missing,,, thanks in advance Hi all, I have been working on this script for over 5 hours, the script used to work but I have recreated some html code in the html form and I think it may have something to do with why the script does not work but I can not see it. Hopefully an extra pair of eyes can help. The I have tested what the $_POST['title'] below echos in the php script and it does carry the value to the php page, but the IF statement does not work. Here it is: html form in a php page: Code: [Select] <form action="testform.php" method="post"> <fieldset style="border:none"> <ul class="controls"> <li> <label for="label">Title</label> <input name="title" id="title" type="text" class="text" maxlength="" value="grumman aa4" /> </li> <li> <label for="label">Aircraft Registration</label> <input name="reg" id="label" type="text" class="text" maxlength="6" value="G-qwea" style="text-transform:uppercase;" /> </li> <li> <input name="Button" type="submit" class="button centered" /> </li> </ul> </fieldset></form> The part of the PHP page that does not work is below. If the php below just says if ($_POST['reg'] == "")... it works but as soon as I put || $_POST['title'] it does not work. I have also tried if ($_POST['reg'] && $_POST['title'] == "")... which DOES work? testform.php <?php if ($_POST['reg'] || $_POST['title'] == "") { $fillinform = "Please fill in all the form to add a listing."; include("saleform.php"); exit(); } ?> Why doesn't this code work... Code: [Select] // Initialize variables. $form_value = ''; $form_value = $_POST['form_value']; I get this error... Quote Notice: Undefined index: form_value Thanks, Debbie I'm trying firstly to output hidden fields based on the values of the $_POST variable. Then after that I want to output the values again in a unordered list. I'm using the following code: while (list($key, $val) = each($_POST)) { if ($key != 'Submit') { echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />'; } } echo '<ul>'; while (list($key, $val) = each($_POST)) { if ($key != 'Submit') { echo '<li><strong>' . $key . '</strong>: <span class="highlight-219ddb">' . $val . '</span></li>'; } } echo '</ul>'; However the <ul> appears to be blank? Can I only use the list() function once on a particular variable? I have a problem that occurred only recently, apparently by some change my webhost made on the server. Some time ago I wrote a script that simulates a Poedit-type editor. The script has about 1500 textareas (the translation fields) with unique names, dynamically generated. All worked fine. Now suddenly I get errors (see below) when I use more than 1000 textareas. It is not a problem of $_POST size, if happens also with empty textareas. I will show here a simple php test file that I called testta.php, which creates the same error as my much more complicated real script: Code: [Select] <?php if(isset($_POST['test'])) { echo 'The textareas were posted successfully!<br>'; } $max = 1500; echo '<form action="testta.php" method="POST">'; echo '<input type="submit" name="test" value="Submit"><br>'; for($i=0; $i < $max; $i++) { echo '<textarea name="test'.$i.'">name is test'.$i.'</textarea><br>'; } echo '</form>'; ?> The error message generated in the browser: 500 Server Error: A misconfiguration on the server caused a hiccup. Check the server logs, fix the problem, then try again. From the Apache log file: [Sat Apr 28 12:47:48 2012] [error] [client 93.172.175.50] Premature end of script headers: testta.php, referer: http://****/*****/testta.php (stars added for privacy) When $max is set to a number < 1000 it works. On the web I have only found answers that deal with max size of posts, but as I mentioned that is not my case. My webhost can't help me out either. Until last Friday all worked fine. Does anyone know what server setting could create this problem? Thanks in advance, Kathy Hello, My script here is not sending POST vars from form to script. I can't figure it out. Form: Code: [Select] <form action="train2.php" method="POST"> <tr> <td colspan="4"><center><img src="pic/toppage16.gif" /></center></td> </tr> <TR> <TD><FONT COLOR="white">Reassign Miners</FONT></TD> <TD align=right><FONT COLOR="white">0 Naquadah</FONT></TD> <TD align=middle><FONT COLOR="white"><INPUT size="6" maxlength="8" value="0" name="miner>"</FONT></TD> </TR> <TR> <TD><FONT COLOR="white">Reassign Normal Attackers</FONT></TD> <TD align=right><FONT COLOR="white">0 Naquadah</FONT></TD> <TD align=middle><FONT COLOR="white"><INPUT size="6" maxlength="8" value="0" name="atsold"></FONT></TD> </TR> <TR> <TD><FONT COLOR="white">Reassign Normal Defenders</FONT></TD> <TD align=right><FONT COLOR="white">0 Naquadah</FONT></TD> <TD align=middle><FONT COLOR="white"><INPUT size=6 maxlength=8 value=0 name="defsold"></FONT></TD> </TR> <TR> <TD><FONT COLOR="white">Reassign Covert Agents</FONT></TD> <TD align=right><FONT COLOR="white">0 Naquadah</FONT></TD> <TD align=middle><FONT COLOR="white"><INPUT size=6 maxlength=8 value=0 name="spy"></FONT></TD> </TR> <TR> <TD><FONT COLOR="white">Anti Covert Agents</FONT></TD> <TD align=right><FONT COLOR="white">0 Naquadah</FONT></TD><TD align=middle><FONT COLOR="white"><INPUT size="6" maxlength=8 value=0 name="spykiller"></FONT></TD></TR> <TR> <TD align=middle colSpan=3><FONT COLOR="white"><INPUT type="submit" value="UnTrain!" name="untrain"> </FONT> </TD> </form> Code: [Select] <?php if(isset($_POST['untrain'])){ die($_POST['miner']); $miners = securevar($_POST['miner']); $nattackers = securevar($_POST['atsold']); $ndefenders = securevar($_POST['defsold']); $covertunits = securevar($_POST['spy']); $anticovertunits = securevar($_POST['spykiller']); $totalunits+=$miners; $totalunits+=$nattackers; $totalunits+=$ndefenders; $totalunits+=$covertunits; $totalunits+=$anticovertunits; if($totalunits>=1){ $q = "UPDATE `accountinfo_db` SET `miners_1` = `miners_1`-'$miner', `attackers_1` = `attackers_1`-'$natta', `defenders_1` = `defenders_1`-'$ndefe', `covertagents` = `covertagents`-'$cover', `anticovertagents` = `anticovertagents`+'$antic', `untrainedunits` = `untrainedunits`+'$totalunits' WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); if(isset($res)){ header("Location: train.php?strmsg=".$totalunits."Troops Untrained! For 0 Naquadah."); } }else{ header("Location: train.php?strmsg=You must enter atleast 1 troop to be un-trained!"); } } ?> when I die($_GET['miner'); nothing is outputed even tho I submited the data. Thank you, Brian Hi guys, running through this tutorial at the moment: http://www.tizag.com/phpT/forms.php I seem to keep having problems with the $_POST variable. Is that obsolete syntax now? Here's the part I get an error on: <html> <body> <?php $quantity=$_POST['quantity']; $item=$_POST['item']; echo "You ordered".$quantity."".$item.".<br/>."; echo "Thank you for ordering from Boombaby art supppplies!"; ?> </body> </html> Here's the error: ( ! ) Notice: Undefined index: quantity in C:\wamp\www\process.php on line 4 Call Stack # Time Memory Function Location 1 0.0009 363936 {main}( ) ..\process.php:0 ( ! ) Notice: Undefined index: item in C:\wamp\www\process.php on line 5 Call Stack # Time Memory Function Location 1 0.0009 363936 {main}( ) ..\process.php:0 You ordered. .Thank you for ordering from Boombaby art supppplies! Any help would be appreciated. I tried googling but everything didn't seem to answer my question or was too confusing. Thanks. hey guys I know this is html but I'm using the php $_POST to grab the information the user chooses, i can't figure out though how to grab the info i'm looking for in this select option form if they choose PasswordCracker v3.0 what is it i'm looking to set my $_post['']; to? <FORM action="buy.php" method="POST"> <select name="passwordcrakers"> <option value="v2.0">PasswordCracker V2.0</option> <option value="v3.0">PasswordCracker V3.0</option> <option value="v4.0">PasswordCracker V4.0</option> <option value="v5.0">PasswordCracker V5.0</option> <option value="v6.0">PasswordCracker V6.0</option> <option value="v7.0">PasswordCracker V7.0</option> <option value="v8.0">PasswordCracker V8.0</option> <option value="v9.0">PasswordCracker V9.0</option> <option value="v10">PasswordCracker V10</option> </select><br /> <input type="submit" value="Buy" name="submit" /> </FORM> ok am workin on this script its a points market for a text based game but my money is not taking the amount of the players i points on the market ... just say i post 10 points for $29.000.000 ... and when the player buys the points it takes the money from that user and give the user points but .... when the user buy the points it dont give the user the money it give $290 ?? not sure is its my SQL av post that to Code: [Select] <?php include 'header.php'; $_POST['buypoints'] = abs(intval($_POST['buypoints']));{ $result = mysql_query("SELECT * FROM `pointsmarket` WHERE `id`='".$_POST['points_id']."'"); $worked = mysql_fetch_array($result); $price = $worked['price']; $amount = $worked['amount']; $totalcost = $price * prettynum($_POST['amount']); $newpointsinmarket = $amount - prettynum($_POST['amount']); $user_points = new User($worked['owner']); if ($worked['owner'] == $user_class->id) { echo Message("You have taken ".$_POST['amount']." points off the market."); $newpoints = $user_class->points + $_POST['amount'];; $result = mysql_query("UPDATE `grpgusers` SET `points` = '".$newpoints."' WHERE `id`='".$user_class->id."'"); $user_class = new User($_SESSION['id']); if ($newpointsinmarket == 0){ $result = mysql_query("DELETE FROM `pointsmarket` WHERE `id`='".$worked['id']."'"); } else { $result = mysql_query("UPDATE `pointsmarket` SET `amount` = '".$newpointsinmarket."' WHERE `id`='".$worked['id']."'"); } include 'footer.php'; die(); } $_POST['amount'] = abs(intval($_POST['amount'])); $_POST['points_id'] = abs(intval($_POST['points_id']));{ } $_POST['amount'] = abs(intval($_POST['amount'])); $_POST['points_id'] = abs(intval($_POST['points_id']));{ } if ($totalcost > prettynum($user_class->money)){ echo Message("You don't have enough money."); } if($_POST['amount'] >= 1 && $_POST['amount'] <= $amount && $totalcost <= $user_class->money){ echo Message("You have bought ".$_POST['amount']." points for $".$totalcost); $newpoints = $user_class->points + $_POST['amount']; $newmoney = $user_class->money - $totalcost; $result = mysql_query("UPDATE `grpgusers` SET `money` = '".$newmoney."', `points` = '".$newpoints."' WHERE `id`='".$user_class->id."'"); $newmoney = $user_points->money + $totalcost; $result = mysql_query("UPDATE `grpgusers` SET `money` = '".$newmoney."' WHERE `id`='".$user_points->id."'"); $user_class = new User($_SESSION['id']); if ($newpointsinmarket == 0){ $result = mysql_query("DELETE FROM `pointsmarket` WHERE `id`='".$worked['id']."'"); } else { $result = mysql_query("UPDATE `pointsmarket` SET `amount` = '".$newpointsinmarket."' WHERE `id`='".$worked['id']."'"); } } } $_POST['addpoints'] = abs(intval($_POST['addpoints'])); $_POST['id'] = abs(intval($_POST['id']));{ } if($_POST['amount'] < 1){ } if($_POST['price'] < 1){ } if ($_POST['amount'] >= 1 && prettynum($_POST['amount']) <= $user_class->points && $_POST['price'] >= 1){ echo Message("You have added ".$_POST['amount']." points to the market a price of $".$_POST['price']." per point."); $result= mysql_query("INSERT INTO `pointsmarket` (owner, amount, price)"."VALUES ('$user_class->id', '$_POST[amount]', '$_POST[price]')"); $newpoints = $user_class->points - $_POST['amount']; $result = mysql_query("UPDATE `grpgusers` SET `points` = '".$newpoints."' WHERE `id`='".$user_class->id."'"); $user_class = new User($_SESSION['id']); } ?> <link href="style.css" rel="stylesheet" type="text/css" /> <tr><td class="contenthead">Point Market</td></tr> <tr><td align="center" class="contentcontent"> <p> </p> <p><strong>You need to be a Respected Warrior to add points to the market</strong><br> Use this form to add points to the points market.</p> <p><strong>Bank Account[<? echo prettynum($user_class->bank) ?>]</strong><strong></strong><br /> <strong><a href="pointmarket.php">[Refresh</a>]</strong></p> <form method='post'> <table align="center"> <tr> <td>Amount of points</td><td> <input name='amount' type='text' class="areatest" value='0' size='10' maxlength='20'></td> </tr> <tr> <td>Price per point</td><td>$<input name='price' type='text' class="areatest" value="0" size='10' maxlength='20'></td> <tr><td align="center" colspan="2"><input name='addpoints' type='submit' class="buttong" value='Add Points'></form></td> </tr></table> </td></tr> <tr><td class="contentcontent"> <?php $result = mysql_query("SELECT * FROM `pointsmarket` ORDER BY `price` DESC"); while($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $user_points = new User($line['owner']); if ($user_points->id == $user_class->id){ $submittext = "Remove"; } else { $submittext = "Buy"; } echo "<form method='post'>"; echo $user_points->formattedname." - ".$line['amount']." points for ".prettynum($line['price'],1)." per point <input type='text' name='amount' size='3' maxlength='20' value='".prettynum($line['amount'])."'><input type='hidden' name='points_id' value='".$line['id']."'><input type='submit' name='buypoints' value='".$submittext."'></form><br>"; } ?> </td></tr> <?php include 'footer.php'; ?> SQL Code: [Select] CREATE TABLE IF NOT EXISTS `pointsmarket` ( `owner` int(10) NOT NULL default '0', `amount` text NOT NULL, `price` text NOT NULL, `id` int(10) NOT NULL auto_increment, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=81 ; Hi guys, I have a form using radio buttons. For the radio button, lets just say i have the id name as 'rim' + number eg; rim0, rim1, rim2.... When i post the data to another file to execute the data collected, naturally i would use the: Code: [Select] $rim0=$_POST['rim0']; $rim1=$_POST['rim1']; .... $rim10=$_POST['rim10']; i tried to shorten this process using this method: Code: [Select] //$q is part of the post variable. for($x = 0; $x < count($q); $x++){ $rim[]=$_POST['"rim"."$x"']; } But i get this error Code: [Select] Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Is there something wrong with my POST syntax? I use a form to sent date and use php to display it . However , the code only can working on one page. I can not turn the page. I do not why . Please tell me reason . Thank you very much. <select name="kind"> <option >kind</option> <option value="Copier Toner">Copier Toner</option> <option value="Laser Toner">Laser Toner</option> <option value="MICR Toner">MICR Toner</option> <option value="Inkjet">Inkjet</option> php code if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 18; $select="select * from $chun where brand = '$_POST[brand]' or sort ='$_POST[kind]' or type='$_POST[type]' LIMIT $start_from, 18"; $result2=mysql_query($select, $connection) or die (mysql_error()); <?php $sql = "select count(*) from $chun where brand = '$_POST[brand]' or sort='$_POST[kind]' or type='$_POST[type]' "; $rs_result = mysql_query($sql,$connection); $row = mysql_fetch_row($rs_result); $total_records = $row[0]; $total_pages = ceil($total_records / 18); for ($i=1; $i<=$total_pages; $i++) { ?> <div class="trunpage"><a href='table2.php?page=<?php echo "$i" ; ?>&id=<?php echo "$_POST[brand]";?>&cd=<?php echo "$_POST[kind]";?>&td=<?php echo "$_POST[type]";?>' ><?php echo "$i" ; ?></a> </div> The first page is working fine. The second page I get error message. Undefined index: brand in C:\wamp\www\php1000\table2.php on line 234 Here's the result of my problem: Array ( [nav_create_title] => hel [nav_visible] => 1 [category_position] => 4 ) ( ! ) Notice: Undefined index: category_postion in C:\wamp\www\tryitandbuyit\includes\category_create_process.php on line 7 Call Stack # Time Memory Function Location 1 0.0010 370336 {main}( ) ..\category_create_process.php:0 Here's how I'm trying to assign and echo $_post. print_r($_POST); $category_pos = $_POST["category_postion"]; $nav_title=$_POST["nav_create_title"]; $nav_visible=$_POST["nav_visible"]; echo $nav_title; echo $category_pos; echo $nav_visible; As you can see, it prints the correct value and name from the array... why the heck can't I assign or echo it? Here is how I am sending it from the other page in a form (it used to be simple, but I've been trying every work around i can think of: <?php $result=mysql_query("SELECT * FROM category WHERE visible='1' ORDER BY position ASC"); $row=mysql_fetch_array($result); $positionID=$row['position']; $position=$row['position']; $selectname= "Select A Position:<br />"; $selectname .= "<select name="; $selectname .= "'category_position'"; $selectname .= ">"; echo $selectname; $rownumber=mysql_num_rows($result); $rownumber_temp=$rownumber+1; For($i=1; $i<=$rownumber_temp; $i++) { echo "<option value= $i>" . $i . "</option></br>"; } $selectname2 = "echo \"<br />\""; $selectname2 .= "echo \"<br />\""; $selectname2 .= "echo \"</select>"; echo $selectname2; I have a code designed to build buildings on space colonies. The problem is that once you click the form button, the building is built, but you need to reload the page before it will show the updated count. Is there a way to refresh a page so that the change shows up without the user doing anything? Code: [Select] <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query="SELECT * FROM IMPrints"; $result=mysql_query($query); $name = mysql_result($result, 0, 'name'); $work = mysql_result($result, 0, 'workers'); $effi = mysql_result($result, 0, 'efficiency'); $cost = mysql_result($result, 0, 'cost'); $iron = mysql_result($result, 0, 'iron'); $copp = mysql_result($result, 0, 'copper'); $silv = mysql_result($result, 0, 'silver'); $titan = mysql_result($result, 0, 'titanium'); $gold = mysql_result($result, 0, 'gold'); $uran = mysql_result($result, 0, 'uranium'); $plat = mysql_result($result, 0, 'platinum'); $diam = mysql_result($result, 0, 'diamonds'); $oil = mysql_result($result, 0, 'oil'); $water = mysql_result($result, 0, 'water'); ?> <div class="building"> <p class="bd" id="name">| Name: <?php echo $name ?></p> <p class="bd" id="workers">| Staff: <?php echo $work ?></p> <p class="bd" id="efficiency">| Effic: <?php echo $effi ?></p> <p class="bd" id="cost">| Cost: <?php echo $cost ?></p> <p class="bd" id="iron">| Ir: <?php echo $iron ?></p> <p class="bd" id="copper">| Cop: <?php echo $copp ?></p> <p class="bd" id="silver">| Silv: <?php echo $silv ?></p> <p class="bd" id="titanium">| Titan: <?php echo $titan ?></p> <p class="bd" id="gold">| Gol:<?php echo $gold ?></p> <p class="bd" id="uranium">| Uran: <?php echo $uran ?></p> <p class="bd" id="platinum">| Plat: <?php echo $plat ?></p> <p class="bd" id="diamonds">| Diam: <?php echo $diam ?></p> <p class="bd" id="oil">| Oi: <?php echo $oil ?></p> <p class="bd" id="water">| Wat: <?php echo $water ?></p> <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $queryp = "SELECT Basic FROM IMBuilt WHERE idcol = $idcol"; $resultp = mysql_query($queryp); $Basic = mysql_result($resultp, 0); if(isset($_POST['built'])) { if($_POST) { $Badd = $Basic+$_POST['built']; $queryi="UPDATE IMBuilt SET Basic=$Badd WHERE idcol = $idcol"; mysql_query($queryi); } } ?> <p class="bd" id="built">| Built: <?php echo $Basic ?> |</p> <form class="bd" method="post" action="IronMineList.php"><input type="varchar" name="built"><input type="submit" value="Build"></form> </div> Running into some problems with my code. I am having the user search the Database with either a UAID or the user's full name. It works fine when you input both the UAID and name; however, I want it to work if only one is give (i.e. just the name or just the UAID). I decided to use the isset($_POST) function of php but I am not getting it to work correctly. PHP believe it is set even though it is empty. Here is my html form. <?php @include 'accesscontrol.php'; echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" ."<html xmlns=\"http://www.w3.org/1999/xhtml\">" ."<title> Hello </title>" ."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" ."<head>" ."<style type=\"text/css\">" ."h1{" ."border-bottom-style: double;" ."border-bottom-color: black;" ."border-bottom-width: 5px;" ."}" ."p{" ."background-color:#4682B4;" ."}" ."</style>" ."</head>" ."<body style=\"background-color:#B8B8B8\">" ."<table align=\"center\" style=\"background-color:#B8B8B8\" WIDTH=\"100%\" HEIGHT=\"100%\">" ."<tr valign=\"middle\">" ."<td align=\"center\">" ."<form method=\"post\" action=\"user.php\">" ."<table align=\"center\" cellpadding=\"10\" style=\"background-color:#5CADFF\" width=\"500\" height=\"400\">" ."<tr>" ."<th colspan=6 align=\"center\"><h1>Welcome: ".$uid."</h1></th>" ."</tr>" ."<tr>" ."<td colspan=3 width=40% align=center>" ."UAID:<br> <input type=\"text\" size=\"8\" name=\"UAID\" /></td>" ."<td colspan=3 width=60% align=center>" ."Name (Last, First):<br><input type=\"text\" size=\"8\" name=\"last\"/>, <input type=\"text\" size=\"8\" name=\"first\" />" ."</tr>" ."<tr>" ."<td colspan=6 align=\"center\"><input type=\"submit\" value=\"submit\" />" ."</td>" ."</tr>" ."</tr>" ."</table>" ."<tr>" ."</tr>" ."</td>" ."</tr>" ."</table>" ."</body>" ."</html>"; ?> Here is the PHP: <?php @include 'accesscontrol.php'; //include 'common.php'; include 'db.php'; $fname = $_POST['first']; $lname = $_POST['last']; $sql = "SELECT * FROM `user` WHERE UAID='$_POST[UAID]'"; $result = mysql_query($sql); $rows = mysql_fetch_array($result); if(isset($fname) && isset($lname)) { echo "Post first $fname <br>" ."Post last $lname"; $firstname = $rows['firstname']; $lastname = $rows['lastname']; if($fname != $firstname OR $lname != $lastname) { ?> <html> <head> <script language="JavaScript"> alert(" Hello this is crap" ); history.back(); </script>"; </head> </html> <? exit; } else { echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"URL\">" ."<html xmlns=URL>" ."<title> Hi </title>" ."<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" ."<head>" ."<style type=\"text/css\">" ."h1{" ."border-bottom-style: double;" ."border-bottom-color: black;" ."border-bottom-width: 5px;" ."}" ."p{" ."background-color:#4682B4;" ."}" ."</style>" ."</head>" ."<body style=\"background-color:#B8B8B8\">" ."<table align=\"center\" style=\"background-color:#B8B8B8\" WIDTH=\"100%\" HEIGHT=\"100%\">" ."<tr valign=\"middle\">" ."<td align=\"center\">" ."<table align=\"center\" cellpadding=\"10\" style=\"background-color:#5CADFF\" width=\"600\" height=\"400\">" ."<tr>" ."<th colspan=6 align=\"center\"><h1>Welcome: ".$uid."</h1></th>" ."</tr>" ."<tr>" ."<form method=\"Post\" action=\"userview.php\">" ."<td colspan=3 width=40%>" ."UAID: <input type=\"text\" size=\"8\" name=\"UAID\" value= ".$_POST['UAID']." /></td>" ."<td colspan=3 width=60%>" ."Name (LAST, FIRST):<input type=\"text\" size=\"8\" name=\"last\" value= ".$_POST['last']." />, <input type=\"text\" size=\"8\" name=\"first\" value= ".$_POST['first']." />" ."</td>" ."</tr>" ."<tr>" ."<td colspan=3 width=40%>" ."Department:<input type=\"text\" size=\"8\" name=\"department\" value=" .$rows['BOG'].">" ."</td>" ."<td colspan=3 width=60%>" ."Employee ID:<input type=\"text\" size=\"8\" name=\"empID\" value=" .$rows['employeeID'].">" ."</td>" ."</tr>" ."<tr>" ."<td colspan=3 align=\"center\"><input type=\"submit\" value=\"View\">" ."</form>" ."</td>" ."<form method=\"Post\" action=\"homepage.php\">" ."<td colspan=3 align=\"center\"><input type=\"submit\" value=\"Back\">" ."</td>" ."</tr>" ."</tr>" ."</table>" ."<tr></tr></td></tr></table></body></html>"; }} mysql_free_result($result); ?> Is there an easy way to dump out the contents of a $_POST array and display them on my screen? (I'm trying to get more comfortable with what is stored in the $_POST array and how it is structured.) Thanks, TomTees Is it possible to redefine a $_POST after PHP has received the value of it via a HTML form? Something like this: if ($_POST['category'] == "Belts") { $_POST['category'] = "belts"; } Hi guys i am a PHP newbie trying to learn from the beginning. I am reading a php book and i can't get past a particular example because $_GET and $_POST just won't work. Below is the code i am working with: HTML File <form action="welcome1.php" method="get"> <div> <label for="firstname">First name: <input type="text" name"firstname" id="firstname"/></label> </div> <div> <label for="lastname"> Last name: <input type="text" name="lastname" id="lastname"/> </label> </div> <div> <input type="submit" value="GO" /> </div> PHP file <?php $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; print 'Welcome to our website, ' . htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' . htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!'; ?> I am working on a windows pc with Vista home edition installed. I run a localhost server installed via XAMMP. Please this has been a recurring problem for me. Each time i get to this stage in the past i always get stuck. $_GET and $_POST just does not work for me. Please heeeelp! This is what I have for code: Code: [Select] <?php $title="Login"; $metakeywords="login, email"; $metadescription="Login to Dating Snap!"; include('header.php'); $user = clean_up($_POST['email']); $pass = clean_up($_POST['password']); if($user && $pass) { $pass = md5($pass); //compare the encrypted password $sql="SELECT id,email,type,password,activation_key FROM `users` WHERE `email`='$user' AND `password`='$pass'"; $query=mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($query) > 0) { $lllrow = mysql_fetch_assoc($query); if($lllrow['activation_key'] == 0){ $_SESSION['id'] = $lllrow['id']; $_SESSION['type'] = $lllrow['type']; $_SESSION['email'] = $lllrow['email']; $_SESSION['password'] = $lllrow['password']; $date=date("M d Y"); $time=date("g:i A"); $sql3 ="UPDATE `users` SET `last_ip`='{$_SERVER['REMOTE_ADDR']}', `last_login`='$date $time' WHERE `id`='".$_SESSION['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); }else{ echo "<div class='error'>You need to activate your account first!</div>"; } echo '<meta http-equiv="REFRESH" content="0;url=index.php">'; } else { echo "<div class='error'>Email and password combination is incorrect!</div>"; } }else{ if(!$_GET['step'] && $_POST['newpassword']){ $email = clean_up($_POST['email']); $password = clean_up($_POST['newpassword']); $sql = "SELECT * FROM `users` WHERE `email`='$email'"; $query = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($query) > 0) { echo "That email is already being used, please try another."; }else{ $activation_number = rand( ); $subject = 'Activate your account on datingsnap.com'; $message = 'Dear '.$first.' '.$last.',<br>Thank you for registering for an account on Dating Snap. Please <a href="http://datingsnap.com/index.php?action=activate&id='.$activation_number.'">Click Here</a> to activate your new account.<br>All the best,<br> DatingSnap.com'; $headers = 'From: bobthewebbuilder@gmail.com' . "\r\n" . 'Content-Type: text/html; charset=\"iso-8859-1\"' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $sql = "INSERT into `users`(`activation_key`,`password`,`email`) VALUES ('$activation_number','".md5($password)."','$email');"; $query = mysql_query($sql) or die(mysql_error()); echo '<form method="post" action="index.php?action=login&step=1"><table width="100%"> <input id="email" type="hidden" name="email" value="$email"> <table width="100%"> <tr> <td class="content">*<b>First Name:</b></td> <td class="content"><input class="tarea" id="first" size="30" type="text" name="first"></td> </tr> <tr> <td class="content">*<b>Last Name:</b></td> <td class="content"><input class="tarea" id="last" size="30" type="text" name="last"></td> </tr> <tr><td width="150" class="content"></td><td class="content"><input type="submit" name="submit" value="Next step"></td></tr></form></table>'; } if($_GET['step'] == "1" && $_POST['email']){ $email = clean_up($_POST['email']); $first = clean_up($_POST['first']); $last = clean_up($_POST['last']); $sql = "UPDATE `users` SET `first`='$first',`last`='$last' WHERE `email`='$email'"; $query = mysql_query($sql) or die(mysql_error()); echo '<table width="100%"><form method="post" action="index.php?action=login&step=2"> <input id="email" type="hidden" name="email" value="$email"> <tr> <td class="content">*<b>Date of birth:</b><br><small>This will be used to calculate your age so be sure to use your correct birth date</small></td><td class="content"> <select name="month" id="month"> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="day" id="day"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="year" id="year">'; $start_year = ($start_year) ? $start_year - 1 : date('Y') - 110; $end_year = ($end_year) ? $end_year : date('Y'); for ($i = $end_year; $i > $start_year; $i -= 1) { echo '<option value="'.$i.'">'.$i.'</option>'; } echo '</select> </td> </tr><tr><td width="150" class="content"></td><td class="content"><input type="submit" name="submit" value="Next step"></td></tr></form></table>'; } if($_GET['step'] == "2" && $_POST['email']){ $email = clean_up($_POST['email']); $month=clean_up($_POST['month']); $day=clean_up($_POST['day']); $year=clean_up($_POST['year']); $sql = "UPDATE `users` SET `bdate`='$year-$month-$day' WHERE `email`='$email'"; $query = mysql_query($sql) or die(mysql_error()); echo "Done step two!"; } } //end if email } include('footer.php'); ?> How come $_POST['email'] isn't getting passed down the steps? I have a hidden field that holds it in each step... what am I overlooking? |