PHP - My _post And Array Not Working Properly
So ive created a forum that I got handling several different approvals. (it is used to approve or decline all submitted notes) it works fine and it even submits fine im at the part know where i process the information and do something with it, below is my form:
<form action="course_proccess.php?action=approve" method="post"> <table align="left" border="1" cellspacing="0" cellpadding="3"> <tr> <td><b>Author</b></td> <td><b>File name</b></td> <td><b>Download</b></td> <td><b>Suggested catagory</b></td> <td><b>Select Catagory</b></td> <td>Approve</td> </tr> <td><input type="text " disabled="disabled" name="tr1_author" value="MikeH" </td> <td><input typee="text " disabled="disabled" name="tr1_name" value="A lot of my skills set back"</td> <td><a href= /uzEr%20Upl0ds/cache.zip > Download</a></td> <td>1001 Laws - Polceing </td> <td><select name="tr1_scatagory"> <option value="1"> Intro To Law </option> <option value="2"> 1001 Laws - Police Foundations </option> </select></td> <td><select name = "tr1_approve"> <option value = "1"> Yes</option> <option value = "2"> no</option> </select></td> </tr> <td><input type="text " disabled="disabled" name="tr2_author" value="MikeH" </td> <td><input typee="text " disabled="disabled" name="tr2_name" value="MM"</td> <td><a href= /uzEr%20Upl0ds/Michael Heintzman.doc > Download</a></td> <td>1001 Laws - Polceing </td> <td><select name="tr2_scatagory"> <option value="1"> Intro To Law </option> <option value="2"> 1001 Laws - Police Foundations </option> </select></td> <td><select name = "tr2_approve"> <option value = "1"> Yes</option> <option value = "2"> no</option> </select></td> </tr> <input type="hidden" name="rowCount" value="2"> <tr> <td><input type="submit" name="sendData" value="send"/></td> </tr> </table> </form> so what I do in my process file is I have a for loop for all of the "TR's" in the table and if it is approved I have an if statment and then I want to add db stuff my problem is my $_POST's are returning blank and I have no idea why. Can someone please assit me with this? (p.s i have debugged and it does get into the if approve == 1 statment. if(isset($_GET['action'])){ if ($_GET['action'] == "approve"){ if(isset($_POST['sendData'])) { $dataArray = array(); $row_count = $_POST['rowCount']; for($i=1;$i<$row_count;$i++) { $approven = "tr".$i."_approve"; $approve = $_POST[$approven]; if($approve == 1) { //Move the info over to "approved files" and delete it out of newnotes $author = "tr".$i."_author"; $location = "tr".$i."_location"; $catagory ="tr".$i."_scatagory"; $filename = "tr".$i."_name"; $submitedby = $_POST['author']; die($submitedby); $dataArray[]=array('author'=>$author,'fileName'=>$fileName,'Catagory'=>$catagory,'location'=>$location); var_dump($dataArray); }else{ //Email user saying they did not recive credits AND delete the entry } } if(!empty($dataArray)) { //now do what you want with the dataArray... var_dumb($dataArray); } } } Similar TutorialsMy code Code: [Select] <?php set_time_limit (0); include("config.php"); $data = "<td><a href='/hospitals-in/Alabama'>Alabama</a></td> <td><a href='/hospitals-in/District-of-Columbia'>District of Columbia</a></td> <td><a href='/hospitals-in/Kentucky'>Kentucky</a></td> <td><a href='/hospitals-in/Montana'>Montana</a></td> <td><a href='/hospitals-in/Ohio'>Ohio</a></td> <td><a href='/hospitals-in/Texas'>Texas</a></td> <td><a href='/hospitals-in/Alaska'>Alaska</a></td> <td><a href='/hospitals-in/Florida'>Florida</a></td> <td><a href='/hospitals-in/Louisiana'>Louisiana</a></td> <td><a href='/hospitals-in/Nebraska'>Nebraska</a></td> <td><a href='/hospitals-in/Oklahoma'>Oklahoma</a></td> <td><a href='/hospitals-in/Utah'>Utah</a></td> <td><a href='/hospitals-in/America-Samoa'>America Samoa</a></td> <td><a href='/hospitals-in/Georgia'>Georgia</a></td> <td><a href='/hospitals-in/Maine'>Maine</a></td> <td><a href='/hospitals-in/Nevada'>Nevada</a></td> <td><a href='/hospitals-in/Oregon'>Oregon</a></td> <td><a href='/hospitals-in/Vermont'>Vermont</a></td> <td><a href='/hospitals-in/Arizona'>Arizona</a></td> <td><a href='/hospitals-in/Hawaii'>Hawaii</a></td> <td><a href='/hospitals-in/Maryland'>Maryland</a></td> <td><a href='/hospitals-in/New-Hampshire'>New Hampshire</a></td> <td><a href='/hospitals-in/Pennsylvania'>Pennsylvania</a></td> <td><a href='/hospitals-in/Virgin-Islands'>Virgin Islands</a></td> <td><a href='/hospitals-in/Arkansas'>Arkansas</a></td> <td><a href='/hospitals-in/Idaho'>Idaho</a></td> <td><a href='/hospitals-in/Massachusetts'>Massachusetts</a></td> <td><a href='/hospitals-in/New-Jersey'>New Jersey</a></td> <td><a href='/hospitals-in/Puerto-Rico'>Puerto Rico</a></td> <td><a href='/hospitals-in/Virginia'>Virginia</a></td> <td><a href='/hospitals-in/California'>California</a></td> <td><a href='/hospitals-in/Illinois'>Illinois</a></td> <td><a href='/hospitals-in/Michigan'>Michigan</a></td> <td><a href='/hospitals-in/New-Mexico'>New Mexico</a></td> <td><a href='/hospitals-in/Rhode-Island'>Rhode Island</a></td> <td><a href='/hospitals-in/Washington'>Washington</a></td> <td><a href='/hospitals-in/Colorado'>Colorado</a></td> <td><a href='/hospitals-in/Indiana'>Indiana</a></td> <td><a href='/hospitals-in/Minnesota'>Minnesota</a></td> <td><a href='/hospitals-in/New-York'>New York</a></td> <td><a href='/hospitals-in/South-Carolina'>South Carolina</a></td> <td><a href='/hospitals-in/West-Virginia'>West Virginia</a></td> <td><a href='/hospitals-in/Connecticut'>Connecticut</a></td> <td><a href='/hospitals-in/Iowa'>Iowa</a></td> <td><a href='/hospitals-in/Mississippi'>Mississippi</a></td> <td><a href='/hospitals-in/North-Carolina'>North Carolina</a></td> <td><a href='/hospitals-in/South-Dakota'>South Dakota</a></td> <td><a href='/hospitals-in/Wisconsin'>Wisconsin</a></td> <td><a href='/hospitals-in/Delaware'>Delaware</a></td> <td><a href='/hospitals-in/Kansas'>Kansas</a></td> <td><a href='/hospitals-in/Missouri'>Missouri</a></td> <td><a href='/hospitals-in/North-Dakota'>North Dakota</a></td> <td><a href='/hospitals-in/Tennessee'>Tennessee</a></td> <td><a href='/hospitals-in/Wyoming'>Wyoming</a></td>"; preg_match_all("~<td><a\s+href='(.*?)'>(.*?)</a></td>~", $data, $link); echo '<pre>'; echo print_r($link); echo '</pre>' ; $countlink = count($link[1]); for($i=0 ; $i < $countlink; $i++) { if (is_array($link)) { $sitelink = "http://www.xxx.com".$link[1][$i]; $hospitallink = file_get_contents("$sitelink"); preg_match_all("~<td><a href=\"/hospital/(.*?)\">(.*?)</a></td>~", $hospitallink, $hospitalinfo); $city = $link[2][$i]; $countinfo = count($hospitalinfo[1]); for($j=0 ; $j < $countinfo ; $j++) { $infolink = "http://www.xxx.com/hospital/".$hospitalinfo[1][$j]; $getinfo = file_get_contents("$infolink"); $regex = "~<b>Name:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Address:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Phone:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Number\s+of\s+Beds:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Type:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>System:</b>\s+(.*?)\s+</p>\s+<p>\s+<b>Website:</b>\s+<a href=\"(.*?)\">(.*?)</a>\s+</p>\s+<p>\s+(.*?)</p>~s"; preg_match_all($regex, $getinfo, $critinfo); preg_match_all("~<li>\s+(.*?)</li>~s", $getinfo, $servinfo); preg_match_all("~<h4>Hospital\s+Quality\s+and\s+Rating\s+information</h4>\s+<p>Data\s+based\s+on\s+2010\s+Health\s+Quality\s+Alliance\s+database</p>\s+<p>\s+<b>(.*?)</b><br>\s+(.*?)</p>~s", $getinfo, $mortality); preg_match_all("/(\d+)?\.?(\d+)?%/", $mortality[2][0], $number); $name = $critinfo[1][0]; $address = preg_replace('/\s\s+/', ' ', $address); $number = implode(",", $number[0]); $servinfo = implode(",", $servinfo[1]); $sql = "INSERT INTO hospital (name, address, servinfo, mortality) VALUES ('$name', '$address', '$servinfo', '$number')"; $exec_sql = mysql_query($sql); } } } ?> print_r($link) shows this :- Code: [Select] Array ( [0] => Array ( [0] => Alabama [1] => District of Columbia [2] => Kentucky [3] => Montana [4] => Ohio [5] => Texas [6] => Alaska [7] => Florida [8] => Louisiana [9] => Nebraska [10] => Oklahoma [11] => Utah [12] => America Samoa [13] => Georgia [14] => Maine [15] => Nevada [16] => Oregon [17] => Vermont [18] => Arizona [19] => Hawaii [20] => Maryland [21] => New Hampshire [22] => Pennsylvania [23] => Virgin Islands [24] => Arkansas [25] => Idaho [26] => Massachusetts [27] => New Jersey [28] => Puerto Rico [29] => Virginia [30] => California [31] => Illinois [32] => Michigan [33] => New Mexico [34] => Rhode Island [35] => Washington [36] => Colorado [37] => Indiana [38] => Minnesota [39] => New York [40] => South Carolina [41] => West Virginia [42] => Connecticut [43] => Iowa [44] => Mississippi [45] => North Carolina [46] => South Dakota [47] => Wisconsin [48] => Delaware [49] => Kansas [50] => Missouri [51] => North Dakota [52] => Tennessee [53] => Wyoming ) [1] => Array ( [0] => /hospitals-in/Alabama [1] => /hospitals-in/District-of-Columbia [2] => /hospitals-in/Kentucky [3] => /hospitals-in/Montana [4] => /hospitals-in/Ohio [5] => /hospitals-in/Texas [6] => /hospitals-in/Alaska [7] => /hospitals-in/Florida [8] => /hospitals-in/Louisiana [9] => /hospitals-in/Nebraska [10] => /hospitals-in/Oklahoma [11] => /hospitals-in/Utah [12] => /hospitals-in/America-Samoa [13] => /hospitals-in/Georgia [14] => /hospitals-in/Maine [15] => /hospitals-in/Nevada [16] => /hospitals-in/Oregon [17] => /hospitals-in/Vermont [18] => /hospitals-in/Arizona [19] => /hospitals-in/Hawaii [20] => /hospitals-in/Maryland [21] => /hospitals-in/New-Hampshire [22] => /hospitals-in/Pennsylvania [23] => /hospitals-in/Virgin-Islands [24] => /hospitals-in/Arkansas [25] => /hospitals-in/Idaho [26] => /hospitals-in/Massachusetts [27] => /hospitals-in/New-Jersey [28] => /hospitals-in/Puerto-Rico [29] => /hospitals-in/Virginia [30] => /hospitals-in/California [31] => /hospitals-in/Illinois [32] => /hospitals-in/Michigan [33] => /hospitals-in/New-Mexico [34] => /hospitals-in/Rhode-Island [35] => /hospitals-in/Washington [36] => /hospitals-in/Colorado [37] => /hospitals-in/Indiana [38] => /hospitals-in/Minnesota [39] => /hospitals-in/New-York [40] => /hospitals-in/South-Carolina [41] => /hospitals-in/West-Virginia [42] => /hospitals-in/Connecticut [43] => /hospitals-in/Iowa [44] => /hospitals-in/Mississippi [45] => /hospitals-in/North-Carolina [46] => /hospitals-in/South-Dakota [47] => /hospitals-in/Wisconsin [48] => /hospitals-in/Delaware [49] => /hospitals-in/Kansas [50] => /hospitals-in/Missouri [51] => /hospitals-in/North-Dakota [52] => /hospitals-in/Tennessee [53] => /hospitals-in/Wyoming ) [2] => Array ( [0] => Alabama [1] => District of Columbia [2] => Kentucky [3] => Montana [4] => Ohio [5] => Texas [6] => Alaska [7] => Florida [8] => Louisiana [9] => Nebraska [10] => Oklahoma [11] => Utah [12] => America Samoa [13] => Georgia [14] => Maine [15] => Nevada [16] => Oregon [17] => Vermont [18] => Arizona [19] => Hawaii [20] => Maryland [21] => New Hampshire [22] => Pennsylvania [23] => Virgin Islands [24] => Arkansas [25] => Idaho [26] => Massachusetts [27] => New Jersey [28] => Puerto Rico [29] => Virginia [30] => California [31] => Illinois [32] => Michigan [33] => New Mexico [34] => Rhode Island [35] => Washington [36] => Colorado [37] => Indiana [38] => Minnesota [39] => New York [40] => South Carolina [41] => West Virginia [42] => Connecticut [43] => Iowa [44] => Mississippi [45] => North Carolina [46] => South Dakota [47] => Wisconsin [48] => Delaware [49] => Kansas [50] => Missouri [51] => North Dakota [52] => Tennessee [53] => Wyoming ) ) 1 Earlier it was giving an error without if (is_array($link)) { Code: [Select] Fatal error: Cannot use string offset as an array However after adding it, it wont go to /hospitals-in/District-of-Columbia which is $link[1][1]; Can someone please point me my mistake 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 Hello pros. I've been working on a website, and i just figured out that a thing is completely wrong. I am entering the website with: "website.com/something.php?name='Hello/system/root/advance.exe'" but somehow the $_POST['name'] is null... My current php code which just prints that post data: Spoiler <?php $postedFileName = $_POST["name"]; echo $postedFileName; /*#-- Here it doesnt echo anything --#*/ ?> I am trying to post while loop array. But I dont know how to do this and I used foreach and it works for each array but doesnt loop this. My table has Que_ID, Question, choice1, choice2, choice3 and choice 4. I would like to do something like.. For each Que_id (choice1, choice2, choice3 , choice4), this should be looped for each que_id so far I have Code: [Select] $counter = 1; while( $info = mysql_fetch_array( $sqll )) //)) { echo "{$info['Que_ID']} <br />\n"; echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; $counter++; echo "<input type=\"checkbox\" name=\"choice[$counter]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $counter++; How would go on to posting these while loop and display Que_ID and all the choices that are ticked for this que_ID and if its not ticked then its 0. How do I post a for loop array in the next page. I am printing Question ID and choices for these and would like the for loop to print Question ID and choice that are checked for these. If the choice is ticked then it shoul return a 1 if the choice is empty then it should print 0. and I would like to insert this to a new table. How would I do this. Code: [Select] $intNum = 1; $intnumber = 1; while( $info = mysql_fetch_array( $sqll )){ echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> "; echo " $intNum, {$info['Que_Question']} <br />\n"; $intNum++; ?> <br> <?PHP for ($i =1; $i < 5; $i++) { echo "<input type=\"checkbox\" name=\"choice[{$intnumber}]\" />{$info['Que_Choice'.$i]}"; $intnumber++; } this is my form that print the question and it works fine. Code: [Select] <?PHP foreach ($_POST["Que_ID"] as $question) { $_POST["choice"] = $choice; echo "Question id: ".$question. $choice"<br />"; This is the post code but I know I need to do so much more but not sure how? Ayone help me or direct me to a source or tutorial or something. How do I assign the entire $_POST array to a varible? This code isn't working... <?php echo 'FormHandler'; class FormHandler{ private $formValues = array(); $this->formValues = $_POST; } ?> TomTees Hi. First timer here. I'm trying to iterate through 5 arrays in a foreach loop. Yep, I know you'll say just use a counter that increments. Sadly, that gives me horrendous results! So, I am using the next & current methods of arrays. Thing is, it gives me bad results ( items that weren't even chosen on the next page ), or it leaves the first couple of items out. I did this : Code: [Select] <?php $ID = array(); $NAME = array(); $PRICE = array(); $QUANT = array(); $checkCount = 0; foreach (array_keys($_POST) as $key) { $$key = $_POST[$key]; $iPos = strpos($key, "ID"); $nPos = strpos($key, "NAME"); $pPos = strpos($key, "PRICE"); $qPos = strpos($key, "QUANT"); $cPos = strpos($key, "CHECK"); if ($iPos !== false) { $ID[] = $$key; } else { //echo "The string ID was not found in the string "; } if ($nPos !== false) { $NAME[] = $$key; } else { //echo "The string NAME was not found in the string "; } if ($pPos !== false) { $PRICE[] = $$key; } else { //echo "The string PRICE was not found in the string "; } if ($qPos !== false) { $QUANT[] = $$key; } else { //echo "The string QUANT was not found in the string "; } if ($cPos !== false) { $checkCount++; if ($checkCount == 1) { echo "Product ID <input type = 'text' name = 'ID" . current($ID) . "' value = '" . current($ID) . "'></br>"; echo "Product Name <input type = 'text' name = 'NAME" . current($NAME) . "' value = '" . current($NAME) . "'></br>"; echo "Product Price <input type = 'text' name = 'PRICE" . current($PRICE) . "' value = '" . current($PRICE) . "'></br>"; echo "Product Quantity <input type = 'text' name = 'QUANT" . current($QUANT) . "' value = '" . current($QUANT) . "'></br>"; } if ($checkCount > 1) { echo "Product ID <input type = 'text' name = 'ID" . next($ID) . "' value = '" . next($ID) . "'></br>"; echo "Product Name <input type = 'text' name = 'NAME" . next($NAME) . "' value = '" . next($NAME) . "'></br>"; echo "Product Price <input type = 'text' name = 'PRICE" . next($PRICE) . "' value = '" . next($PRICE) . "'></br>"; echo "Product Quantity <input type = 'text' name = 'QUANT" . next($QUANT) . "' value = '" . next($QUANT) . "'></br>"; } } else { //echo "The string CHECK was not found in the string "; } } ?> You will see I did all the processing under the CHECK if statement, the reason for this is, it is easier to identify the items ordered because they have been checked on the previous page. I am having problems storing a $_POST variable from a form into a $_SESSION. When I go to the next page and echo out the $_SESSION variable its blank Page 1 code (page with self submitting form action) <?php session_start(); $email = $_POST['email]; $_SESSION['email'] = $email; ?> Page 2 (page which should be echoing out the value of the session variable) <?php session_start(); echo "Your Email Address which you submitted was: " . $_SESSION['email']; ?> When I echo that out on page 2 its blank Why is the variable value not carrying over to the 2nd page? Chad I have a form that is populating fields based on a database query. I am then trying to update the database based on any changes made in the form and passed through a POST action. The problem I am having is with the block where I declare short variable names for the $_POST variables that will be passed when the user hits the submit button. For each variable declaration I get an error message like this: Quote Encountered error: 8 in mbr_profile_updt_form.php, line 130: Undefined index: email I have tried testing the $_POST variable using the isset function but it apparently is set but empty. What would be a good way to test to see if the user has pressed the submit button before I go into the processing block that is intended to handle those values from the form? Here is where my code is at right now: Code: [Select] if (!isset($_POST)) { throw new Exception('You have not filled the form out completely - please go back' .' and try again.'); } else { //filled in so create short variable names $email=$_POST['email']; $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; Well I have a script file that loads lots of info from a form using $_POST[] method, which is quite tedious: Code: [Select] $act = $_POST["act"]; $page = $_POST["page"]; $id = $_POST["id"]; $category = $_POST["category"]; $itemname = $_POST["itemname"]; $description = $_POST["description"]; $imageurl = $_POST["imageurl"]; $existingimageurl = $_POST["existingimageurl"]; $function = $_POST["function"]; $target = $_POST["target"]; $value = $_POST["value"]; $shop = $_POST["shop"]; $price = $_POST["price"]; $tradable = $_POST["tradable"]; $consumable = $_POST["consumable"]; I was wondering if there is a way to write one or two simple lines of code to load all variables stored in superglobal array $_POST[] efficiently. The point is to store all values within $_POST[] to an array called $item[], what I was thinking about is: Code: [Select] foreach($_POST = $key as $val){ $item['{$key}'] = $val; } Seems that its not gonna work, so I wonder if anyone of you have ideas on how I am able to simplify my code with 10-20 lines of $_POST[] to just 2-3 lines. Please do lemme know if this is possible, thanks. I need to email the form http://keegenk.com/providenceltddesign/ to myself. Right now, the email is sending and the confirmation page comes up, but the email does not have any of the data that should be collected by the form. I'll attach the php file that I'm using to capture the variable and send it to the email address. Any and all help is appreciated. Thanks a bunch I have a simple log in form. By debugging I found that isset post submit function is not responding. It remains on the same page after submitting form. I have googled all the possible solutions to this problem but none worked. Any help is greatly appreciated. The form is in multiplelogin.php file and the code is in multi.php file. After login redirection is to teachers.php file. <?php session_start(); $conn = mysqli_connect("localhost", "root", "", "signup");
if(isset($_SESSION['username'])) {
?>
<head> <link rel="stylesheet" type="text/css" href="bootstrap.css"> <title> Teachers Students Login </title> </head> <body class="bg-secondary"> <div class="container"> <div class="row justify-content-center"> <div class="col-log-5 bg-light mt-5 px-0"> <h3 class="text-center text-light bg-primary py-3 px-5"> Log In </h3>
<div class="form-group px-5"> <input type="email" name="email" class="form-control form-control-lg" placeholder="Email" required> </div> <div class="form-group px-5"> <input type="password" name="password" class="form-control form-control-lg" placeholder="Password" required> </div> <div class="form-group px-5"> <input type="submit" name="submit" value="Submit" class="btn btn-primary btn-block"> </div> </form> </div> </div> </div>
<?php
ini_set( 'display_errors', 1 );
$password = $_POST['password'];
$stmt = mysqli_stmt_init($conn); header("Location: multilogin.php?error=sqlerror"); exit();
} else { mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($pwdCheck == false) {
exit(); $_SESSION['username'] = $row['username']; $_SESSION['email'] = $row['email']; header("Location: teachers.php?login=success");
exit ();
exit();
exit();
else {
exit(); Code: [Select] <?php $query = "Select * from users where username = '$user' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $test = $_POST['test1']; $ques = "Select * from questions where testname = '$test' "; $qres = mysql_query($ques) or die(mysql_error()); $qdetails = mysql_fetch_array($qres); $id = $qdetails['id']; $testname = $qdetails['testname']; $ans = "Select * from answers where qid = $id"; $ares = mysql_query($ans) or die(mysql_error()); if($qdetails) { ?> <div class="padding"> <form name="answerform" action="answer.php" method="POST"> <h3> </h3> <input name="test2" id="test2" type="text" value="<?php echo $qdetails['testname'];?>" /><h3><?php echo $qdetails['text'];?></h3> <input name="test3" id="test3" type="text" value="<?php echo $qdetails['testseries'];?>" /><h3><?php echo $qdetails['text'];?></h3> <br /> <br /> <br /> <?php while($opdetails = mysql_fetch_assoc($ares)) { ?> <input class="text" id="opt2" name="correctans" type="radio" value="<?php echo $opdetails['text']; ?>" /><br /><?php echo $opdetails['text']; ?> <?php }?> <div class="two-fields clearfix". <p class="confirm"> </p> </div> <input type="submit" value="SUBMIT ANSWER" /> </form> </div> </div> </div> <?php } this is the code for the program where i am creating the fields i want to fetch the data from the input fields with the name test 2 and test 3 in answer.php Code: [Select] $query = "Select score from users where username = '$user' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $user_score = $row['score']; print_r($_REQUEST); $tester = $_POST['test3']; $test = $_POST['test2']; print_r($_POST); var_dump($_POST); $ques = "Select * from questions where testname = '$test' And testseries = '$tester' "; $result = mysql_query($ques) or die(mysql_error()); $row = mysql_fetch_array($result); $qid = $row['id']; $score = $row['score']; if(isset($_POST['correctans'])) { $answer = $_POST['correctans']; } else { $answer = ''; } $fetch_ans = "Select * from answers where correct = 1 AND qid = $qid"; $result = mysql_query($fetch_ans) or die(mysql_error()); $row = mysql_fetch_array($result); $id = $row['id']; $correctans = $row['text']; if('$correctans' == '$answer') { $user_score += $score; $qid++; $query = "Update users set score = $user_score where username = '$user'"; $res = mysql_query($query) or die(mysql_error()); if($res) { header("Location: answer.php"); } }else { header("Location: answer.php"); } ?> THIS IS answer.php and here i try to post information from test2 and test3 fields but i am not getting any output the output shows blank array() and unidentified index test2 and unidentified index test3 i am not able to figure out the error any help will be highly appreciated and forgive me if i have made any mistakes in posting the question since i am a newbie at PHPFREAKS Hi, i'm new here and hope i've finally found a forum where i can find the perfect solution for my questions.
Well since a year now i started to work with PHP and still now and then there are some things where i seize on. My question is on of those situations.
I have the following code:
if (isset($_POST)){ foreach ($_POST as $key => $value){ if (!empty($value)){ $update_rma_detail_stmt = $dbh->prepare("UPDATE rma_detail SET $key = ? WHERE rd_rma_nr = ?"); $update_rma_detail_stmt->bindParam(1, $value); $update_rma_detail_stmt->bindParam(2, $getadmrmaid); $update_rma_detail_stmt->execute(); } } }All i want is when there is an empty (not filled in) input field because it is not mandatory the foreach still continuous to the end. When i use if (!empty($value)){It still outputs these error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ' ' However, when i dont use i got an other error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '' It is however so that the datetime is the very first empty field it come across when looping. I think my if (!empty($value)){ is doing the right thing but still gives error's on integers. Can it be? I allready tried to use trim() or array_filter() but because i previously never used it i dont know if i am doing it the right way so any help is welkom! Thanks! Edited by Raz3rt, 20 May 2014 - 02:56 AM. Hi All, There is a very interesting solved topic here (http://www.phpfreaks.com/forums/index.php?topic=304966.0) about how to access elements in embedded _POST array. But before accessing an element, it might be appropriate to check whether the array it is supposed to be in exists. According to the solution given in the topic indicated above, Code: [Select] $_POST['matType'] is an example of embedded array . Is there a way to check if this array exists? Thanks in advance for your help. Hi the above title explains it all.How to output a post array which has been given input using forms.I know you can do it my echo but what about print() Thanks There's probably an obvious reason but I can't seem to find it... I start with the $_POST array, received from a form: Code: [Select] array(9) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" ["button"]=> string(38) "updateColumnName=EnvironmentID;Value=1" } I get the button value from the array, and unset the button array value. Code: [Select] function load_POST($name) { //returns value and removes it from $_POST array. returns NULL if not existing. $debug = 0; if ( $debug == 1 ) { $backtrace = backtrace(); echo __FUNCTION__."()"; echo " <i>called by ".basename($backtrace[1]['file'])."</i><br/>\n"; } $post = NULL; if( array_key_exists($name, $_POST) ) { $post = urldecode($_POST[$name]); if ( $debug == 1 ) { echo "post $name, value: $post<br/>\n"; } } else { if ( $debug == 1 ) { echo "post $name: doesn't exist<br/>\n"; } } unset($_POST[$name]); return $post; } $_POST is now: Code: [Select] array(8) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" } Then I create the object to assign the values to: Code: [Select] object(Environment)#1 (9) { ["EnvironmentID"]=> NULL ["Name"]=> NULL ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) } So far so good Then, for each remaining $_POST value, I update the Object accordingly: First one, parametername: Name, parameter: KTN Code: [Select] object(Environment)#1 (10) { ["EnvironmentID"]=> NULL ["Name"]=> string(3) "KTN" ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) ["ColumnName=EnvironmentID;Value=1"]=> object(stdClass)#3 (1) { ["ColumnName"]=> string(1) "1" } } And there we have the problem, for some reason the button value is added to the object somehow... Any ideas? Thanks in advance! how to cross reference $_POST array 'checkboxes[]' with mysql field I have a form that is submitted so the user can select which results to print. but I am having problems getting the results to show correctly. how do I correctly cross reference the form data with the mysql Code: [Select] $getRequests = mysql_query("SELECT * FROM requests WHERE `customer_email`='{$_SESSION['FM_user']}'"); while($request = mysql_fetch_assoc($getRequests)) { if (!in_array($request['request_id'],array($_POST[request]))) { echo '<li style="font-size:10px; border-bottom: 0.1em solid #D0D0D0"> <div class="leftfloat"> <input type="checkbox" name="request[]" value="',$request['request_id'],'"> </div> <div class="leftfloat"> <em>',$request['request_id'],'</em> </div><div class="leftfloat"> | </div> <div class="leftfloat"> <em>',$request['customer_name'],'</em> </div><div class="leftfloat"> | </div> <br style="clear:both"> </li>'; } } Okay, so I am trying to make a play.php file connected to my database, this database got a table named "webclientcreate". When I go to play.php?id=1, it is showing the proper one (the 1st row wich got id 1 in it), however if I after that go to something random like play.php?fsfasd the ID 1s page still pops up.. I can also go to play.php?id=2 and still get the id 1's data. I want to make it that every row got its own information (well it does, but the php file doesnt seem to recieve it correctly). PHP version: 5.2.17 MySQL version: 5.1 Heres a picture of my table rows: I've censored the MySQL connection information, I know it is working properly. Code: [Select] <?php $connect = mysql_connect("mysql12.000webhost.com","****","******") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); $extract = mysql_query("SELECT * FROM webclientcreate"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { $id = $row['id']; $server = $row['name']; $ip = $row['ip']; $port = $row['port']; $background = $row['background']; } if (isset($ip)&&isset($port)&&!empty($ip)&&!empty($port)) { if (! $sock = @fsockopen($ip, $port, $num, $error, 1)) echo ""; else{ echo "<img src='fs/newyear/online.png'/>$ip on port $port is currently<B><FONT COLOR=lime> Online</b></FONT>"; fclose($sock); } } ?> <title>Playing <?php echo $server; ?> - ID <?php echo $id; ?> </title> <center> <body bgcolor="#000000"> <applet name=client width=765 height=503 archive='<?php echo $jars; ?>' code='client.class'> <PARAM name='java_arguments' value='-Xmx700m'> <PARAM name='server_name' value='<?php echo $server; ?>'> <PARAM name='detail' value='low'> <PARAM name='ip' value='<?php echo $ip; ?>'> <PARAM name='port' value='<?php echo $port; ?>'> <PARAM name='background_image' value='<?php echo $background; ?>'> <PARAM name='headicons' value=''> </applet> </center> Hi there, I have created an email script and i want it to email a different email depending on the subject chosen by raido boxes however the if's aren't doing what they should, If i select say recruitement it choses the last option and has the wrong subject here is my code: <html> <head> </head> <body> <form action="contact.php" method="post"> <fieldset> <legend>Contact Us</legend> Your Email:*<br> <input type="text" name="email"><br> Subject:*<br> Recruitment Enquiry:<input type="radio" name="subject" value="Recruitment"> Absense Notification:<input type="radio" name="subject" value="Absense"> General Enquiry<input type="radio" name="subject" value="Enquiry"> <br> Message:*<br> <textarea name="message" cols="50" rows="5"></textarea><br> <input type="submit" value="Send Email"> </form> Required fields are marked with a *<br><br> <?php if(isset($_POST)) { $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; //checcking that all relevent information is entered and correct if(!$email || !$message) { $errmessage ="Please fill in all required fields."; } if($subject="Recruitment") { $to="email1"; } if($subject="Notification") { $to="email2k"; } if($subject="Enquiry") { $to="email3"; } //Sending the email if nothing is wrong if(!$errmessage) { header("location:send.php?to=".$to."&subject=".$subject."&email=".$email."&message=".$message.""); }else{ echo $errmessage; } } ?> </body> </html> If anyone can help it would be greatly appriciated Thanks, blink359 |