PHP - Dynamic Creating $_post
Hi Everyone
I found some code to decrease the writing of $_POST variables especially on big forms, but I cannot seem to get it to work: I am trying to get the $_POST variables from this: Code: [Select] <?php $callsign = $_POST['mf_callsign']; $surname = $_POST['mf_surname']; $firstnames = $_POST['mf_firstnames']; $knownas = $_POST['mf_knownas']; $rsaid = $_POST['mf_rsaid']; $birthdate = $_POST['mf_birthdate']; //more code [code] to this (see //Create $_POST Variables section) [code] <?php //Initailise Database first mysql_connect ("localhost", "***", "***") or die ('I cannot connect to the database because: ' .mysql_error()); mysql_select_db ("***"); ========================= //Create $_POST Variables foreach($_POST as $inputKey=>$inputValue): //find all form fields starting with 'mf_' if((strstr($inputKey,'mf_') === true)): $inputKey = mysql_real_escape_string($inputValue); endif; endforeach; ========================= //Then do the Insert into the Table $query="INSERT INTO personal_details (callsign, surname, firstnames, knownas, rsaid, birthdate)Values ('$mf_callsign', '$mf_surname', '$mf_firstnames', '$mf_knownas', '$mf_rsaid', '$mf_birthdate')"; mysql_query($query) or die ('Error Inserting Data into Database'); //If Insert Successful, Goto next Form header("Location: contactdetails.html"); die; ?> The //Create $_POST Variables section is not correct as it is not setting the variables correctly. If I go back to the old way and use that ($callsign = $_POST['mf_callsign'] it inserts no problem. What Am I doing wrong? Regards Allen Similar TutorialsHello guys. I'm kinda new to PHP, I've been understanding everything so far. I have trouble with "imagestring" What I want is to query a row in MySQL. I want to display some of that info in the image. It's not working properly. Here's the code: <?php $imagepath="css/images/dog.jpg"; $image=imagecreatefromjpeg($imagepath); $imgheight=imagesy($image); $color=imagecolorallocate($image, 255, 255, 255); include("config.php"); $result = mysql_query("SELECT * FROM playerinfo WHERE Level > 0 ORDER BY Level DESC", $connect); while($myrow = mysql_fetch_row($result)) { // Not working properly. imagestring($image, 5, 50, $imgheight-50, $myrow[0], $color); } // This line works like it should: //imagestring($image, 5, 50, $imgheight-50, "Using it like this works!", $color); header('Content-Type: image/jpeg'); imagejpeg($image); ?> Any help will be GREATLY appreciated it. Thanks! Hello,
I have this very frustrating problem I'm trying to make a dynamic table with only 5 columns per row. So every 5 items, I need a new row. I have tried many different examples with no success. What is the best way to approach this? Here is what I am working with, this doesn't show what I have tried, just what I am working with at the moment which of course, just outputs it one column per row. http://www.mesquitew.../inc-legend.php // Lets parse the data $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); foreach ($result as $entry): $event = $entry->children("cap", true)->event; // Set the alert colors for the legend include ('../inc-NWR-alert-colors.php'); // Lets creat some styles for the list $spanStyle = "background-color:{$alertColor};border:solid 1px #333;width:15px;height:10px;display:inline-block;'> </span><span style='font-size:12px;color:#555;"; $legend .= "<table>"; $legend .= "<tr>"; $legend .= "<td> <span style='$spanStyle'> $event</span></td>"; $legend .= "</tr>"; $legend .= "</table>"; endforeach; endif; echo $legend;-Thanks! Hi there,
I have a table in a MySQL database where I keep a list of user privileges. I am trying to create variables where the name of variable matches the privileges in the table.
This is also known as variable variables (I think).
EDIT (17/07/2014 04:02 PM): This might be a better way to describe what I'd like, so if the value from the table is admin_panel I'd like to dynamically create a variable with that name.
I have created a code so far, but all I seem to be getting is a list of Notice errors telling me that the variable is undefined. (I have supplied a list of errors a bit further down the post).
Here is the code:
<?php $host = "localhost"; $account = "***"; $password = "****"; $dbname = "****"; $connect = mysql_connect($host,$account,$password) or die("Unable To Connect"); $db = mysql_select_db($dbname,$connect) or die("Unable To Select DB"); $perm_query = "SELECT * FROM `privileges`"; $permission_query = mysql_query($perm_query); while($row = mysql_fetch_array($permission_query)) { $rows[] = $row; } foreach($rows as $row) { ${$row['privilege']}; } ?>The list of errors: Notice: Undefined variable: admin_panel in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: create_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: edit_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: delete_user in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: create_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: edit_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: delete_group in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: view_log in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: log_settings in C:\xampp\htdocs\DynamicVariables.php on line 20 Notice: Undefined variable: password_change in C:\xampp\htdocs\DynamicVariables.php on line 20 Thanks Edited by chrisrulez001, 17 July 2014 - 10:05 AM. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342341.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=357949.0 i've to populate google charts with dynamic data. the data looks llike. +----+-------+---------+-------+-----------+---------+------+ | id | name | physics | maths | chemistry | biology | sst | +----+-------+---------+-------+-----------+---------+------+ | 1 | Name1 | 10 | 25 | 35 | 42 | 62 | | 2 | Name2 | 80 | 45 | 45 | 45 | 25 | | 3 | Name3 | 63 | 25 | 63 | 36 | 36 | | 4 | Name4 | 82 | 36 | 75 | 48 | 42 | | 5 | Name5 | 45 | 45 | 78 | 25 | 24 | | 6 | Name6 | 36 | 36 | 15 | 75 | 36 | | 7 | Name7 | 99 | 45 | 24 | 24 | 45 | | 8 | Name8 | 45 | 85 | 85 | 85 | 96 | +----+-------+---------+-------+-----------+---------+------+ i have to create google charts based on this such that # namewise - such that when i select a name it displays all subject marks of that particular name in a column chart #markswise - when i select a subject, it displays all the names with marks in that particular subject. conisdiering that data may be added and i've to accumulate that also, for namewise i did // chart.php <?php include("connection.php"); $query = "SELECT name FROM csv GROUP BY name DESC"; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); ?> <!DOCTYPE html> <html> <head> <title>Google charts</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> </head> <body> <br /><br /> <div class="container"> <div class="panel panel-default"> <div class="panel-heading"> <div class="row"> <div class="col-md-9"> <h3 class="panel-title">Student Wise Marks Data</h3> </div> <div class="col-md-3"> <select name="name" class="form-control" id="name"> <option value="">Select Student</option> <?php foreach($result as $row) { echo '<option value="'.$row["name"].'">'.$row["name"].'</option>'; } ?> </select> </div> </div> </div> <div class="panel-body"> <div id="chart_area" style="width: 1000px; height: 620px;"></div> </div> </div> </div> </body> </html> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {packages: ['corechart', 'bar']}); google.charts.setOnLoadCallback(); function load_student_data(name, title) { var temp_title = title + ' '+name+''; $.ajax({ url:"fetch.php", method:"POST", data:{name:name}, dataType:"JSON", success:function(data) { drawStudentwiseChart(data, temp_title); } }); } function drawStudentwiseChart(chart_data, chart_main_title) { var jsonData = chart_data; var data = new google.visualization.DataTable(); data.addColumn('number', 'Physics'); data.addColumn('number', 'Maths'); data.addColumn('number', 'Chemistry'); data.addColumn('number', 'Biology'); data.addColumn('number', 'SST'); $.each(jsonData, function(i, jsonData){ var Physics = jsonData.Physics; var Maths = jsonData.Maths; var Chemistry = jsonData.Chemistry; var Biology = jsonData.Biology; var SST = jsonData.SST; data.addRows([[Physics,Maths,Chemistry,Biology,SST]]); }); var options = { title:chart_main_title, hAxis: { title: "Subjects" }, vAxis: { title: 'Percentage' } }; var chart = new google.visualization.ColumnChart(document.getElementById('chart_area')); chart.draw(data, options); } </script> <script> $(document).ready(function(){ $('#name').change(function(){ var name = $(this).val(); if(name != '') { load_student_data(name, 'Student wise marks data'); } }); }); </script> and in order to fetch data // fetch.php <?php //fetch.php include('connection.php'); if(isset($_POST["name"])) { $query = " SELECT * FROM csv WHERE name = '".$_POST["name"]."' ORDER BY id ASC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { $output[] = array( 'Physics' => $row["Physics"], 'Maths' => $row["Maths"], 'Chemistry' => $row["Chemistry"], 'Biology' => $row["Biology"], 'SST' => $row["SST"], ); } echo json_encode($output); } ?> it diplays a blank page. however when i play with singular values i.e one subject at a time it displays fine Edited March 19, 2019 by zetastreakFolks, I need help (Php code ) to generate a Dynamic Text on a Base Image. What i want to do is, to make this Image as header on my Site and to make this Header Specific to a Site, i want to Add the Domain Name on the Lower Left of the Image. Got the Idea? Here is the Image link: Quote http://img27.imageshack.us/i/shoppingheader1.jpg/ PHP Variable that holds the Domain name is: $domain All i need the Dynamic PHP Codes that i can put on all my sites to generate this Text on Image (Header) Dynamically... May Anyone Help me with this Please? Cheers Natasha T. Hi all I need to combine these two scripts: Firstly, the following decides which out of the following list is selected based on its value in the mySQL table: <select name="pack_choice"> <option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option> <option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option> <option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option> </select> Although this works OK, I need it also to show dynamic values like this: select name="category"> <?php $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>"; } ?> </select> I'm not sure if this is possible? Many thanks for your help. Pete 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, 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. 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 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, 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 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> 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 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 good day, im a little bit confuse. what i want to do is instead of $username = $_POST['username']; is to transform it into OOP? please help me. thanks. Hello,
I am quite new to the php and website scene and i am trying to find the best way to validate and sterilize my $_post the way i have come up with is
$id = filter_var(mysql_real_escape_string($_POST['id']),FILTER_SANITIZE_NUMBER_INT);or $id = mysql_real_escape_string($_POST['id']); $id1 = filter_var($id,FILTER_SANITIZE_NUMBER_INT);which will be the best way to do it or is there a better way. Thanks Edited by AdamHull12, 04 October 2014 - 11:15 AM. |