PHP - How Do I Access An Array Outside Of If?
When I send values to the foreach they are not recorded in the array. $x = $getProductID; $_SESSION['pColors'] = array(); if(isset($_POST['pColors'])) { foreach($_POST['pColors'] as $colorKey => $RColors) { $_SESSION['pColors'][$colorKey] = $RColors; } } var_dump($_SESSION['pColors']); Send date with AJAX: $('.addToCart').click(function(){ $.ajax({ url:""+realLink+"cart.php", method:"POST", data:{action:action,pColors:pColors}, success:function(data){ //alert(data); } }); }); Similar TutorialsThe title makes it sound more complicated than it is. I have a recurring function that searches for a specific value in a multi-dimensional array. When it finds it, it returns an array of the index. For example, if it found the value at $array[1][4][2][0], it would return an array like this: [0]=>1 [1]=>4 [2]=>2 [3]=>0 Here's the function. Code: [Select] <?php // Other Code /** * Find's the parent of an item * Unfortunately, it takes a bit more work than just using the loudspeaker at a grocery store * @param int $parent The parent to be searched for * @param array $array * @param array $cur_index */ private function findParent($parent, $array, $cur_index) { for($i = 0; $i < count($array); $i++) { // Search the array if($array[$i]['id'] == $parent) { // If the parent is found $cur_index[count($cur_index)] = $i; return array(true, $cur_index); } if(count($array[$i][1]) > 1) { // Call findParent again to search the child $cur_index[count($cur_index)] = $i; $found_in_child = $this->findParent($parent, $array[$i], $cur_index); if($found_in_child[0]) { return $found_in_child; } } } return array(false); // Return no matches } I need to be able to call that index using the keys from the key array (as we will call it). How can I do that? Thank you in advance for your help. Array ( [game] => Array ( [id] => 2011012593950636050 [name] => Array ( [us] => Castlevania II: Belmont's Revenge [uk] => Castlevania II: Belmont's Revenge ) echo print_r($this->game[0]['name']) but undefined offset error. I don't want to loop through the first array either. Thanks what am I doing wrong? I have an assoc array, but I can't seem to access it. Code: [Select] $var = Array ( 'domain' => asdfasdf.com 'port' => 2082 'adminuser' => admin 'INST_password' => adsfasdf 'adminnickname' => admin 'adminemail' => admin@asdfasdf.com 'sitename' => Play Bingo Online Austrailia 'description' => How to play bingo online in Australia 'site_root_path' => /home/chris/public_html/ 'theme' => default 'anchor_one' => How to play bingo online in Australia 'anchor_two' => play bingo 'anchor_three' => bingo online ) if( empty($var['domain']) ) exit; the code exits everytime. What am I missing? How would you access the number 10 in the $arr array? I am trying to pull images from my Flickr account with some success except that of accessing the description to be used as a caption for the image. What I have so far is:- Code: [Select] <?php //>>> Define some variables $maximgs = 5; $images = array(); $params = array( 'api_key' => '***********************', 'method' => 'flickr.photos.search', 'user_id' => '****************', 'sort' => 'date-posted-desc', 'format' => 'php_serial', 'extras' => 'description', ); $encoded_params = array(); foreach ($params as $key => $value){ $encoded_params[] = urlencode($key) . '=' . urlencode($value); } //>>> Make request and decode the response $url = 'http://api.flickr.com/services/rest/?' . implode('&', $encoded_params); $response = file_get_contents($url); $response_object = unserialize($response); //var_dump($response_object['photos']['photo']); //>>> Why is this returning 100 results? if($response_object['stat'] !== 'ok'){ echo "Something went wrong!"; } //>>> Select the required number of images ($maximgs) for($loop = 0; $loop <= $maximgs; $loop++){ $images = $response_object['photos']['photo'][$loop]; var_dump($images); //>>> Url of the individual image location for the img src. $imgurl = 'http://farm'.$images['farm'].'.'.'static'.'.'.'flickr.com/'. $images['server'].'/'.$images['id'].'_'.$images['secret'].'_n.jpg'; //>>> Url of the individual image for the link. $flkrurl = 'http://www.flickr.com/photos/'.$images['owner'].'/'.$images['id'].'/'; /*The complete Url (<a href="link($flkrurl)"> <img alt="$images['title']" src="image location"($imgurl) width="required width of image" /> </a>) */ $compurl = '<a href="'.$flkrurl.'" target="_blank">'.'<img alt="'. $images['title'].'" src="'.$imgurl.'" width="320px" /></a>'; //>>> Display Images echo $compurl . '<br />' . $images['description']['content']; //<<<<<< Line 66 } ?> Which annoyingly throws this error:- Notice: Undefined index: content in C:\wamp\www\php\flickr_test1.php on line 66 The result of a var_dump():- array 'id' => string '6914498038' (length=10) 'owner' => string '************' (length=12) 'secret' => string '601a885f31' (length=10) 'server' => string '7137' (length=4) 'farm' => float 8 'title' => string 'newhaven_15' (length=11) 'ispublic' => int 1 'isfriend' => int 0 'isfamily' => int 0 'description' => array '_content' => string 'Great reflections found in Newhaven Harbour.' (length=44) with the info that I want to extract underlined. What I can't figure out is how to find out the name of the array below "description =>". I have been scratching my head for several hours now and am no nearer to working it out. Maybe a genius here will have the solution. Hi! I am trying to use the View Model Design Pattern in my application The problem is that it is the first time I use it and I am a beginner. So, I have the logic in the Model and the "front end" in View. I am talking about a sign up page. In the current Html file I am trying to access an error array from the model file and display it to the user above the input field.
Here is the a snippet from the Model (Signup.php) $account = new Account($con); //the account which takes as param the db connection $error = null; //the array // anything the user writes gets inside this array if (isset($_POST["submitButton"])) { $firstName = UnifyFormInput::unifyUserFLName($_POST["firstName"]); $lastName = UnifyFormInput::unifyUserFLName($_POST["lastName"]); $username = UnifyFormInput::unifyFormUserName($_POST["username"]); $email = UnifyFormInput::unifyFormEmail($_POST["email"]); $password = UnifyFormInput::unifyFormPassword($_POST["password"]); //contain true or false based on the query being successful or not $success = $account->register($firstName, $lastName, $username, $email, $password); if ($success) { $_SESSION["userLoggedIn"] = $username; header("Location:index.php"); }else{ $error = $account->getError(Constants::$registerFailed); } } //compact — creates array containing variables and their values //call render function from View file to show the register page content View::render('register', compact('error')); And here is the view: <?php if (!empty($error)) { echo $account->getError(Constants::$loginFailed); } ?> <input type="text" class="form-control" name="firstName" placeholder= "First Name" value="<?php getInputValue("firstName"); ?>" required>
Hi friends, a quick print_r() shows the following array while connecting to my database. How to get them as individual items and display on the website ? Array ( [0] => Array ( [id] => 52 [document_name] => xyz [document_ext] => gif [download_file_name] => ktm_impact.gif [upload_dt] => 2010-08-11 ) ) Hey all. another quick question. here is the output of my 2D array: Code: [Select] array(2) { ["folder.jpg"]=> array(2) { ["valid"]=> bool(true) ["error"]=> bool(false) } ["file.mp3"]=> array(2) { ["valid"]=> bool(true) ["error"]=> bool(false) } } how can i foreach my way into getting an iterator that points to the folder.jpg and file.mp3? as is now, i have something that looks like this: foreach($arr as $val){ var_dump($val) } the var_dump of $val is an *array*. Thanks for your help!
<?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); error_reporting(E_ALL | E_WARNING | E_NOTICE); ini_set('display_errors', TRUE); if (session_status() == PHP_SESSION_NONE) { session_start(); } if(!isset($_SESSION['login'])) { echo ("<script>location.href='../clogin/'</script>"); die(); } if (isset($_POST['submit'])) { include_once('db.php'); //get post details from user $UserNumber = $_POST['uNumber']; $sql = "SELECT * FROM customer WHERE user_number=?"; $stmt = $connection->prepare($sql); $stmt->bind_param('i', $UserNumber); $stmt->execute(); $result = $stmt->get_result(); $count = $result->num_rows; if($count == 1) { while($row = $result->fetch_assoc()); { $db_Uno = $row['user_number']; if($userNumber !== $db_Uno) { echo'<script>swal.fire("FAILED!!", "<strong>No Customer with the user number you entered.</strong><hr><br/><i> Check well and try Again.</i>", "error");window.setTimeout(function(){ window.location.href = "home.php"; }, 2000);</script>'; exit(); } else { } }//while loop } //end of if rslt }// end submit for transfer post ?>
Not sure how to find what is causing my issue here, I'm running smarty which gives me this error if I switch PHP version to 7.4 (was on 7.3) : - Quote
ERRNO: 8 The line the error refers to is this : -
<p class="cart_del_info_box_text"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <span class="cart_del_info_box_message"><?php echo $_smarty_tpl->tpl_vars['cart']->value->mDelivery['cartdeliverymessage'];?>
How do I go about finding which file has the actual problem? Thanks for any pointers. CMS: PHP-Fusion version 9.03.110, PHP version: 7.4.16, MySQL Server Version: 5.7.33-log, DB Driver: PDO MySQL My own support people at PHP-Fusion main site have been unable to help me with this problem and I'm hoping for some new eyes and new input on this error. First of all my script works perfectly fine and outputs the result desired. I know that my script is not using PDO prepared statements and I am not prepared to modify it to do so because too much would have to be changed. And I'm not fluent on PDO. My script is an event calendar and can be seen at this url: https://windy.whisperwillow.net/grims_blog/index.php The error only occurs 3 times on 3 lines. <?php echo "<div class='col-sm-12'>\n"; include BASEDIR."grims_blog/include/cal_func_inc.php"; $day=date('d'); $endDate=date('t',mktime(0,0,0,$cMonth,$day,$cYear)); echo "<div><span class='hdspan2'><b>".$locale['gb_510']."</b></span></div><p>\n"; echo "<table class='tbl-responsive' width='67%' align='center' border='0' cellpadding='0' cellspacing='0'><tr>\n"; echo "<td align='center' colspan='3'><img style='max-width:100%;height:auto;' src='".BASEDIR."grims_blog/images/calhead/forest.jpg'></td>\n"; echo "</tr><tr height='30' bgcolor='#960000'>\n"; echo "<td align='left'> <a class='mcaldate' href='".FUSION_SELF."?month=$prev_month&year=$prev_year' title='Last Month'>".$locale['gb_511']."</a></td><td align='center'><span class='mnthhd'>".date("F Y",strtotime($cYear."-".$cMonth."-01"))."</span></td><td align='right'><a class='mcaldate' href='".FUSION_SELF."?month=$next_month&year=$next_year' title='Next Month'>".$locale['gb_512']."</a> </td>\n"; echo "</tr></table>\n"; echo "<table width='67%' align='center' border='0' cellpadding='0' cellspacing='0'><tr><td class='cal-blank'>\n"; echo "<table width='100%' align='center' border='0' cellpadding='0' cellspacing='0'><tr bgcolor='#005E00' height='35'>\n"; foreach ($short_days as $key=>$val) { echo "<th style='text-align:center' width='14%'><span style='font-size:12px; color:yellow;'><b>".$val."</b></span></th>\n"; } echo "</tr><tr>\n"; $s=date('w', mktime (0,0,0,$cMonth,1,$cYear)); for ($ds=1; $ds<=$s; $ds++) { echo "<td class='cal-blank' height='35' style='text-align:center;' valign='middle'></td>\n"; } for ($d=1; $d<=$endDate; $d++) { if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 0) { echo "<tr>\n"; } $result = dbquery("SELECT post_id, post_title, post_date FROM ".DB_GRIMS_BLOG_POST." WHERE active='1' AND MONTH(post_date) = '$cMonth' AND DAY(post_date) = '$d'"); $data = dbarray($result); $stuff1 = $data['post_id'] ? $data['post_id'] : ""; if ($stuff1) { $id = $stuff1; } else { $id = ""; } $stuff2 = $data['post_title'] ? $data['post_title'] : ""; if ($stuff2) { $title = $stuff2; } else { $title = ""; } $stuff3 = strtotime($data['post_date']) ? strtotime($data['post_date']) : ""; if ($stuff3) { $evday = $stuff3; } else { $evday = ""; } if (date("d", intval($evday)) == $d) { echo "<td height='35' class='event' align='center' valign='middle'>\n"; } elseif ($d == $day && $cMonth == date('m') && $cYear == date('Y')) { echo "<td height='35' class='today' align='center' valign='middle'>\n"; } else { echo "<td height='35' class='cal-norm' align='center' valign='middle'>\n"; } if ($d == $day && $cMonth == date('m') && $d <> $evday) { echo "<a class='cal2' href='".BASEDIR."grims_blog/filtered.php?post_id=$id' title='".$locale['gb_513']." $title'><b>$d</b></a>\n"; } elseif ($d == $day && $cMonth == date('m') && $d == $evday) { echo "<a class='cal2' href='#'><b>$d</b></a>\n"; } elseif ($evday) { echo "<a class='ecal' href='".BASEDIR."grims_blog/filtered.php?post_id=$id' title='$title'><b>$d</b></a>\n"; } else { echo "<span class='noevt'><b>$d</b></span>\n"; } echo "</td>\n"; if (date('w',mktime (0,0,0,$cMonth,$d,$cYear)) == 6) { echo "</tr>\n"; } } echo "</table></td></tr></table>\n"; echo "</td></tr></table><p></div>\n"; ?> Well I could not add comments to the posted script. These 3 lines of the db query area give the error in my error log: 1) $stuff1 = $data['post_id'] ? $data['post_id'] : ""; /* Trying to access array offset on value of type bool */ 2) $stuff2 = $data['post_title'] ? $data['post_title'] : ""; /* Trying to access array offset on value of type bool */ 3) $stuff3 = strtotime($data['post_date']) ? strtotime($data['post_date']) : ""; /* Trying to access array offset on value of type bool */ I know I am asking a lot for help on older code but would really appreciate it if someone can take a look. Edited April 19 by OldGrimClarify error lines Hi, WHAT: So I cannot for the life of me figure out why I'm getting this error. I'm trying to create a function that will display the user information from the database in a table but I have like a ton of these errors on the page and I don't know whats wrong. STEPS TO RESOLVE: So I've gone over my code a bunch of types to make sure that all the variables and what not were spelled correctly and as far as I can tell they are. I've also googled this issue to see if I can find a solution but none of them are very helpful. I honestly don't know whats wrong so kinda hard to find ways to resolve an issue, I don't even really know what this error means. THE CODE: This is where I put the function into action <?php display_table( array( "id" => "Id", "emailaddress" => "Email", "firstname" => "First Name", "lastname" => "Last Name", "salesperson" => "Salesperson", "phonenumber" => "Phone Number", "extension" => "Extension", "type" => "Type" ) ); ?> //This is the function <?php function display_table($fields, $data, $rows, $page){ if(isset($_GET['page'])){ $page = $_GET['page']; } else { $page = 1; } $firstRecord = ($page - 1) * ROWS_PER_PAGE; $pageNumbers = ceil($rows / ROWS_PER_PAGE); echo '<div class="table-responsive w-75 mx-auto py-3"> <table class="table table-dark table-bordered table-sm"> <thead> <tr>'; foreach($fields as $key){ echo '<th class="py-2">' . $key . '</th>'; } echo '</tr> </thead> </tbody>'; $keys = array_keys($fields); for($record = $firstRecord; $record < $firstRecord + ROWS_PER_PAGE; $record++){ $row = $data[$record]; echo '<tr>'; for($recordCount = 0; $recordCount < count($keys); $recordCount++){ $column = $keys[$recordCount]; echo '<td class="py-2">' . $row[$column] . '</td>'; } echo '</tr>'; } echo '</tbody> </table'; for($pages = 1; $pages <= $pageNumbers; $pages++){ echo '<a class="btn btn-dark mx-1" href=?page=' . $pages . '</a>'; } } ?> Any help/advice would be really appreciated I am getting these errors . This is my complete HTML page. Everything seems to work fine but when i retweet a message these error show up. Here is my tweet.php and the errors are at line 32 and 41. Previously there was an error at line 24: It was like this: '.((!empty($tweet->retweetMsg) && $tweet->tweetID === $retweet['tweetID'] or $tweet->retweetID > 0) ? ' I changed it to this and the error went away '.((isset($retweet['retweetID']) ? $retweet['retweetID'] === $tweet->retweetID OR $tweet->retweetID > 0 : '') ? ' Maybe this could help! I will really appreciate any suggestion coming my way! Hi guys, I am making a site where users upload files (like images, pdfs, etc) to the server. My question is, how does Facebook handle file permissions, restricting access to files uploaded to their servers based on what a user sets? Because I need to implement a similar thing and have no idea how to do it in a clean way. I have had two thoughts on storing the files 1) in a DB or 2) in a folder out of the wwwroot, which would prevent access by anyone without knowing the path (or some such) but it is the more "real" permissions implementation I am stuck on. I obviously would like to achieve this with PHP and MySQL(i). Any help is much appreciated. Cheers in advance. I've got data in a mySql database which is updated daily. I would like to allow webmasters to place this data in a form of a widget on their websites provided they pay for access. If not payment comes through we should be able to block access.
Any suggestions how this project would be designed?
Hi, I want to control a variable (decide whether to track click if coming from a specific site oppose to hitting the final site (destination) directly. For example: www.portal.com - this will be a management site that will redirect viewers to the the final destination based on variable info - for exmample $a=123 or $a= 567 - which would come in as www.portal.com?a=123 or www.portal.com?a=567 Note: 123 would redirect to www.abc.com?a=123 and/or 567 would redirect to www.xyz.com?a=567 with said variable(s). ------ My question is this: What is the best method to authenticate (both on) www.abc.com and/or www.xyz.com that the referred viewer came from www.portal.com? I know about the super globals (HTTP_REFERER) but want to know if there are other (more) secure method to manage this interaction between external domains /websites? Any insight on this appreciated - thanks! I'm currently learning PHP and I think I have a decent grasp of procedural programming so I'm trying to set it up a little bit and get a hang of OOP. I'm finding it a little tough going but I am making progress, the syntax and coding of it is fine but I don't quite get some theory and the best way to use it yet. It's only my third day in but I have a question relating to access modifiers. It's a simple one, but what is the point? That may sound a bit narky but I keep hearing and reading that it's good programming convention but it's never really explained why. What am I missing? I get how they work but I don't really get why to use them. I've even read that private should only be rarely used, if at all as it makes testing harder and it stops you from being able to extend your classes. I'm not against using them - I want to learn to program to the very best of my ability but I'm eager to learn what benefits it actually has. Is there a technical reason, for example? Hi, i am learning WordPress and have just started, but i have a problem....when i try to access my site i get this: Warning: Cannot modify header information - headers already sent by (output started at /home/smra9/public_html/wp-content/themes/evanescence/functions.php:6) in /home/smra9/public_html/wp-includes/pluggable.php on line 890 when i open pluggable.php and i go to the line 890 it says: header("Location: $location", true, $status); i will also copy a text from line 885 to 890 so maybe you will understand better: if ( $is_IIS ) { header("Refresh: 0;url=$location"); } else { if ( php_sapi_name() != 'cgi-fcgi' ) status_header($status); // This causes problems on IIS and some FastCGI setups header("Location: $location", true, $status); } Can anyone help me, i don't know what to do Hello, folks. I am having a little trouble with this script. I want it to be able to read a directory, not just a file, and list all files in the directory along with their id3 tags. I can't get it to read all the files, it reads only the first file in the directory. Here, I'm posting the basic (stripped down) script, without mods or add-ons. I would appreciate any help. Thanks. Code: [Select] <?php require('error.inc.php'); require('id3.class.php'); $nome_arq = 'music.mp3'; $myId3 = new ID3($nome_arq); if ($myId3->getInfo()){ echo('<HTML>'); echo('<a href= "'.$nome_arq.'">Click to play: </a><br>'); echo('<table border=1> <tr> <td><strong>Artist</strong></td> <td><strong>Title</strong></font></div></td> <td><strong>Track</strong></font></div></td> <td><strong>Album/Year</strong></font></div></td> <td><strong>Genre</strong></font></div></td> <td><strong>Comments</strong></font></div></td> </tr> <tr> <td>'. $myId3->getArtist() . ' </td> <td>'. $myId3->getTitle() . ' </td> <td>'. $myId3->getTrack() . ' </td> <td>'. $myId3->getAlbum() . '/'.$myId3->getYear().' </td> <td>'. $myId3->getGender() . ' </td> <td>'. $myId3->tags['COMM']. ' </td> </tr> </table>'); echo('</HTML>'); }else{ echo($errors[$myId3->last_error_num]); } ?> If a client connects to a ReactPHP TLS socket server, is it possible to obtain the symmetric key from within the PHP code? Hoping it will allow me to decrypt analysis traffic between two using Wireshark. |