PHP - Returning A Single Error From An Array
Hi Guys,
I have 6 file upload fileds in an array. When i try to return the error messages at this link: http://www.php.net/manual/en/features.file-upload.errors.php i get an error displayed for every upload box. I was wondering if it is possible to simply return 1 error instead of the 6? For example rather than getting "No File Uploaded No File Uploaded No File Uploaded No File Uploaded No File Uploaded No File Uploaded" i simply get "No File Uploaded". Also If only some files are uploaded no error should be displayed. The code i am using is: foreach ($_FILES['image']['error'] as $key => $error) { if ($error == UPLOAD_ERR_NO_FILE) { echo "No File Uploaded"; } I have tried using "break;" which works in leaving only 1 error, however the error is still displayed if less than 6 files are uploaded. All help greatly appreciated. Thanks Similar TutorialsHi guys, I am using this oAuth library https://github.com/elbunce/oauth2-php But more specifically these lines of code: protected function getToken($token, $isRefresh = true) { try { $tableName = $isRefresh ? self::TABLE_REFRESH : self::TABLE_TOKENS; $tokenName = $isRefresh ? 'refresh_token' : 'oauth_token'; $sql = "SELECT $tokenName, client_id, expires, scope, user_id FROM $tableName WHERE token = :token"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':token', $token, PDO::PARAM_STR); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result !== FALSE ? $result : NULL; } catch (PDOException $e) { $this->handleException($e); } } However, this is retuning no value. If I modify the code to be: protected function getToken($token, $isRefresh = true) { return $token; } It returns the $token value, so the $token is definitely being passed to the function. The code should return an associative array: i.e., $token["expires"], $token["client_id"], $token["userd_id"], $token["scope"], etc Also $token should not === NULL. PS. I run a few checks on $tableName = $isRefresh ? self::TABLE_REFRESH : self::TABLE_TOKENS; $tokenName = $isRefresh ? 'refresh_token' : 'oauth_token'; And they are returning the correct values. Which from my thinking narrows it down to: $sql = "SELECT $tokenName, client_id, expires, scope, user_id FROM $tableName WHERE token = :token"; $stmt = $this->db->prepare($sql); $stmt->bindParam(':token', $token, PDO::PARAM_STR); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result !== FALSE ? $result : NULL; Any and all help is greatly appreciated. Thanks in advance. Hi I have a simple form and when the user submits, php is putting a \ before every single quote entered in the field. So for example, if a user enters O'Neill, once i do $lastName = $_POST["lastname"]; $lastName comes back as: O\'Neill is there some way I can turn this off? I am retrieving values in form of array from a database table and out of the I have to build multidimensional array depending upon the parent->child relationship in the same array. The result is as => Array ( => Array ( [label] => Shirt [uri] => # ) [1] => Array ( [label] => Jeans [uri] => # ) [2] => Array ( [label] => Lowers [uri] => # ) [3] => Array ( [label] => T-Shirts [uri] => # ) [4] => Array ( [label] => cotton shirt [uri] => # ) [5] => Array ( [label] => Trousers [uri] => # ) ) each is related to some parent-id. Can any body me any idea. Hey there, Now I was curious if there was a way I could return an array in my function like the following, I currently get a error though: Code: [Select] Catchable fatal error: Object of class panel_accounts could not be converted to string in C:\wamp\www\X-HostLTD - Panel\PanelFrontend\index.php on line 21 But can you only return strings?. Here is the function that it errors on: function returnAccountInformation($AccountID) { return mysql_fetch_array(mysql_query("SELECT * FROM ****_***** WHERE *****_***** = '".mysql_escape_string($AccountID)."'")); } Could somebody help me on the matter?, Thank you. P.S sorry for staring out the table names but I don't really want people knowing my database structure hehe. I am using a sloppy 3rd party API that doesn't return error codes, just error messages. See below Code: [Select] $err = $object->getErrorMessage(); if( strlen($err) > 0 ) { header("Location: step1.php?err=$err"); } As you can see this is sloppy because anyone can just modify the address bar of step1.php and inject their own error message, or javascript or their own HTML buttons, etc. As a work around, I thought maybe I could use POST instead of GET... At least then the "err" variable would be hidden for the most part Any ideas how I can work around this? Thanks! Hey Guys, I am hoping you can help me find out why a function of mine is only returning 1 record when I am asking for 10. Here is the function I am using to get the data. When I run the $sql that is printed in phpmyadmin.... I get then records. But when I print the $event_data I am only getting 1 record. Any help would be greatly appreciated function get_events($data) { //print_r($data); $lat = $data['lat']; $long = $data['long']; $offset = $data['offset']; $radius = $data['radius']; $amount = $data['amount']; //the events query $sql = sprintf("SELECT *, ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance FROM events WHERE `status` = '0' HAVING distance < '%s' ORDER BY distance LIMIT $amount OFFSET $offset", mysql_real_escape_string($lat), mysql_real_escape_string($long), mysql_real_escape_string($lat), mysql_real_escape_string($radius)); //debugging print_r($sql); $event_data = array(); $event_data = mysql_fetch_array(mysql_query($sql)); //debugging print_r($event_data); return $event_data; } Trying to retun an array which gets a file from a directory and then returns the filename as the key and the complete file url as the value but when returning it it prints out "Array" for each file in the directory rather than the file name: Doing this in wordpress. Code: [Select] function wsme_select_css_theme(){ $alt_css_template_path = WSME_THEME_CSS; // Define path to files $alt_widgets_template = array(); // set array $out = ''; // Set var if ( is_dir($alt_css_template_path) ) { // If directory exists if ($alt_css_template_dir = opendir($alt_css_template_path) ) { //opens directory while ( ($alt_css_template_file = readdir($alt_css_template_dir)) !== false ) { //if files are in the directory if(stristr($alt_css_template_file, ".css") !== false) { //if the files are .css files $out[] = array($alt_css_template_file => WSME_THEME_CSS.'/'.$alt_css_template_file); //create the array(filename => file path) for each file in the directory } } } return $out; // return array } } Code: [Select] array( 'name' => 'Style', 'id' => WS_THEME_PREFIX . '_style', 'headings' => array( array( 'name' => 'Theme CSS', 'options' => array( array('name' => 'Homepage', 'desc' => ' select the css file of the theme you want for your site', 'id' => WS_THEME_PREFIX . '_theme_css', 'value' => '', 'options' => wsme_select_css_theme(), 'type' => 'select' ) ) ) ) Any suggestions? Hi, Could somebody please explain to me why the following code returns a 400 error. I've been sitting looking at it for hours and I can't see anything wrong with it, but then again I don't know too much about cURL. Code: [Select] <?php // INSTANTIATE CURL. $curl = curl_init(); // CURL SETTINGS. curl_setopt($curl, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/96966578.xml"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); // GRAB THE XML FILE. $response = curl_exec($curl); // Get information about the response $responseInfo=curl_getinfo($curl); // Close the CURL connection curl_close($curl); curl_close($curl); // Make sure we received a response from Twitter if(intval($responseInfo['http_code'])==200){ // Display the response from Twitter $content .= "Success code response:". $response; }else{ // Something went wrong $content .= "Error: " . $responseInfo['http_code']; } // SET UP XML OBJECT. $xmlObjTwitter = simplexml_load_string( $response ); $content .="<h3>Your last 10 twitter posts....</h3>\n" ; $content .= "<ul> \n"; $tempCounter = 0; foreach ( $xmlObjTwitter -> item as $item ) { // DISPLAY ONLY 10 ITEMS. if ( $tempCounter < 11 ) { $content .= "<li><a href=\"{$item -> guid}\">{$item -> title}</a></li> "; } $tempCounter += 1; } $content .="</ul>\n"; echo $content ; ?> Hi fellow developers, I'm having a real problem at the moment, I'm trying to capture everything in between <body></body> tags using the following code but it does not print anything: $lines = file("http://www.bbc.co.uk/"); foreach ($lines as $line_num => $line) { $thecontent .= htmlspecialchars($line) . "<br />\n"; } preg_match('/<body.*?>(.*?)<\/body >/', $thecontent, $htmltext); $moretext = $htmltext[1]; echo $moretext; When you do place a "print($thecontent);" into the code the entire html for [whatever the website] does display but I want to capture only the html code in between the body tags. I've tried everything but I just can't get this to work. I would appreciate anyone's help and I'd like to thank you in advance. M I have a script that runs a query against a MySQL database, then, if it returns a resultset, it takes the 'freindly name from an array containg the database connections, then adds the data for the resultset. Unfortunately at the minute, it doesn't quite work the way that I want. So far I have: //get list of servers to query, and choose them one at a time for($a = 0; $a <sizeof($slaveRes_array); $a++) { $con = mysql_connect($slaveRes_array[$a]['server'], $slaveRes_array[$a]['user'], $slaveRes_array[$a]['password']); mysql_select_db($dbs, $con); //get list of MySQL Queries, and run them against the current server, one at a time for($b = 0; $b <sizeof($query_array); $b++) { $SlaveState = mysql_query($query_array[$b]['query1'], $con); // 1st Query // If there is a resultset, get data and put into array while($row = mysql_fetch_assoc($SlaveState)) { for($c = 0; $c <mysql_num_rows($SlaveState); $c++) { $slave_array[]['name'] = $slaveRes_array[$a]['database']; for($d = 0; $d <mysql_num_fields($SlaveState); $d++) { $slave_array[][mysql_field_name($SlaveState,$d)] = mysql_result($SlaveState,$c,mysql_field_name($SlaveState,$d)); }} } } // Run Query2...Query3....etc. } The problem is that at the minute it puts each field into a separate part of the array e.g. Array ( => Array ( [name] => MySQL02_5083 ) [1] => Array ( [Slave_IO_State] => Waiting for master to send event ) [2] => Array ( [Master_Host] => localhost ) [3] => Array ( [Master_User] => root ) Whereas what I am trying to achieve is more like: Array ( => Array ( [name] => MySQL02 ) [Slave_IO_State] => Waiting for master to send event ) [Master_Host] => localhost ) [Master_User] => root )... [1] => Array ( [name] => MySQL03 etc. etc. But I can't see how to achieve this? Originally, I would get both, and unfortunately would inconsistently use both. Then, I wanted more consistently, so configured php.ini to only return objects as I felt accessing them was more concise. And then later, I found myself needing arrays more often, and initially would just typecast them to arrays but eventually my standard was to set the PDO's fetch style to an array. And now I find myself almost always explicitly requesting arrays and occasionally requesting columns or named values. Do you configure ATTR_DEFAULT_FETCH_MODE, and if so to what? PS. Anyone use FETCH_CLASS, FETCH_INTO or FETCH_NUM? If so, what would be a good use case? I am trying to return all the photos in the database that has the albumid associated with that table info. I can echo the $album->id (albumid) no problem, but my query it think is somewhat off. Please anyone. Code: [Select] <div id="photo-items" class="photo-list-item"> <?php echo $album->id.'<br>'; // fetch album photos and ids $database =& JFactory::getDBO(); $query = "SELECT * FROM jos_photos where albumid = ".$album->id." ORDER BY ASC"; $photos = mysql_query($query); //This returns and array of photos, but then needs to display all the photos in loop below, but it not retuning none, even if there is 100 photos in table and in the folder directory if($photos) { for( $i=0; $i<count($photos); $i++ ){ $row =& $photos[$i]; ?> <div class="photo-item" id="photo-<?php echo $i;?>" title="<?php echo $this->escape($row->caption);?>"> <a href="<?php echo $row->link;?>"><img class="" src="<?php echo $row->getThumbURI();?>" alt="<?php echo $this->escape($row->caption);?>" id="photoid-<?php echo $row->id;?>" /></a> <?php if( $isOwner ) { ?> <div class="photo-action"> <a href="javascript:void(0);('<?php echo $row->id;?>');" class="remove"><?php echo JText::_('CC REMOVE');?></a> </div> <?php } ?> </div> <?php } } else { ?> <div class="empty-list"><?php echo JText::_('CC NO PHOTOS UPLOADED YET');?> <button class="button button-upload" href="javascript: void(0);&userid=88" id="upload-photos-button">Start Uploading</button></div> <?php } ?> </div> Hello can anyone help me out with code to create a 2 dimension array from 2 single dimension array. for example $path = array('base', 'category', 'subcategory', 'item'); $location=array('india','USA','UK','RUSSIA',); now i need to have a @D array which have the following structure $final[0]=array('base','india'); $final[1]=array('category','USA'); $final[2]=array('subcategory','UK'); $final[3]=array('item','RUSSIA'); I need to get the 2nd code working. Please help. This works $query = "SELECT DISTINCT addressz FROM abs WHERE statez = 'AZ'"; $results = mysql_query($query); But this dosen't. $SomeVar = $_POST['disloc']; $query = "SELECT DISTINCT addressz FROM abs WHERE statez = '".$SomeVar."' ORDER BY addressz ASC"; $results = mysql_query($query); hey everyone will you please assist. I'm getting data from a mysql database. And I want to assign the data to a single value, if possible For example, in my database I have 2 columns, name and group Lets say John, Peter and Cathy belongs to group 555, where Sally and Marcus belongs to group 777. So my sql query outputs all users in group 555 Is there a way to assign the search result to a vlue, for example $result = ??? and If I said echo $result, it should show the users who belongs to group 555 as an example. I tried to use row[Name][1]; but it doesnt work. The thing is, I can display the data the way I am familiar with, but I'm sending an automated email to myself, containing the users. So if I would used a for each statement, the mail will trigger and send a copy for every count, in this case, 3 times. And thats my huge problem. The mail must trigger only once, containing the users in my search query, in this case, group 555. Any help will be appreciated Thank you Hi, learning as I go here, and I appreciate the help in advance .. I have some working php code that retrieves sql results using php. I assign the resutls to an array by doing this $bobreport = array(); while ($row=db2_fetch_array($querystmt)) { array_push($bobreport, $row); } i can then write the rows of returned data after some column headers using this... foreach ($bobreport as $value) { echo "<tr><td>$value[0]</td><td>$value[1] ..... } The particular report I'm working on now has a redundant date and time in every row that I omit in the foreach loop because I just want to show it once above the table somewhere. This doesn't seem to work in accomplishing that... echo "This data was updated ".$bobreport[0][9]." at ".$bobreport[0][10] ; All I seem to get in the report is "This data was updated at". Please help. Hello all, I'm new to PHP and new to this forum (although I have benefitted from your help already -cheers!). However, this time I cannot find the answer I need/recognise/understand.. I have a form and want to conduct tests on each field returning an error message as a session variable if the test fails. The test will be different for some of the fields, and the error message is specific to each field. If there is an error in any one of the fields I want to be redirected to a failure page where all of the error messages are displayed, otherwise I am sent on to another page. I have already written and tested a function to sanitise the incoming form data, so that's not a problem - it's just how to loop through and test. I can guess that there are many ways to do this but I need to understand why one option is better than another, and follow the syntax used (it's all part of my steep learning curve) The approach I have thought to use is to create an array holding the field name, the test and the message, then loop through using foreach, applying the array values into the test and creating the error message....but it's not working for me. The other method is to declare a variable $Stop='No' and if the loop identifies an error, part of the output is to change this to 'yes' and through that redirect to the error page. I'd really welcome your advice and tuition....cheers.. my code so far is... Code: [Select] $Stop='No'; $StaffPassCheck=sanitisealphanum($_POST['PasswordCheck']); $Errors[0]['value']= sanitisealphanum($_POST['FirstName']); $Errors[0]['message']='Please re-enter your name'; $Errors[0]['test']=($StaffFname=""); $Errors[1]['value']= sanitisealphanum($_POST['Surname']); $Errors[1]['message']='Please re-enter your surname'; $Errors[1]['test']=($StaffSname=""); $Errors[2]['value']= sanitisealphanum($_POST['Post']); $Errors[2]['message']='You must select an option'; $Errors[2]['test']=($StaffPost="Select Value"); $Errors[3]['value']= sanitisealphanum($_POST['Username']); $Errors[3]['message']='You must select an option'; $Errors[3]['test']=($StaffUser=""); $Errors[4]['value']= sanitisealphanum($_POST['Password']); $Errors[4]['message']='Please re-enter your password'; $Errors[4]['test']=($StaffPass=""); $Errors[5]['value']= sanitisealphanum($_POST['PasswordCheck']); $Errors[5]['message']='Sorry, your passwords do not match'; $Errors[5]['test']=($StaffPass===$StaffPassCheck); foreach ($Errors as $key => $Value){ if ( $Errors['test']=true ){ $Stop='Yes'; return $_SESSION[$key]=$Value['message']; } } if ($Stop='Yes'){ header('Location.test.php'); die(); }else{ header('Location.indexp.php'); } This will have been posted before, but I can't find a solution that works. Most people say to try mysql_real_escape_string, I have tried lots of variations and it doesn't seem to work. Could anyone help with the below code? It is part of a form that returns a syntax error when adding a single quotation mark e.g. entering "Bryan's" into the form causes the error. I'd be really grateful for any assistance. Steven P.S. Before anyone mentions it, the mysql connect does work - I just haven't included the full page of code. Code: [Select] mysql_connect($dbserver, $dbusername, $dbpassword); mysql_select_db($dbname); $sitetitle = htmlentities($_POST[sitetitle]); $query = mysql_query("UPDATE site_settings SET sitetitle = '$sitetitle'"); echo("<b>Settings Updated!</b>"); I came up with this but it outputs the value 3 times... (because there are 3 variables) ie mathsmathsmaths How do I fix this or do it the correct way? Thanks Code: [Select] $subject = "maths"; $phone = "1235"; $colour = "red"; $all_vars = compact("subject", "phone", "colour"); get_value($subject); function get_value($variable){ global $all_vars; foreach($all_vars as $key=>$value){ if ($key = $variable) { echo $key; } } } hi everyone i got a new problem with my theme>woocommarce>content-single-product.php file.when i want to see single product then its show me this...
here is the url of image: http://awesomescreen....com/0753t8tuca
here is the site/error page url: http://championhouse...ed-rice-pack-1/
here is the my "content-single-product.php" file php coding.its getting error from 4no line.
<?php //Display Page Header global $wp_query; $postid = $wp_query->post->ID; echo page_header( get_post_meta($postid, 'qns_page_header_image', true) ); wp_reset_query(); ?> <!-- BEGIN .section --> <div class="section"> <?php do_action( 'woocommerce_before_single_product' ); ?> <div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>> <ul class="columns-content page-content clearfix"> <!-- BEGIN .col-main --> <li class="<?php echo sidebar_position('primary-content'); ?>"> <h2 class="page-title"><?php the_title(); ?></h2> <ul class="columns-2 product-single-content clearfix"> <li class="col2 clearfix"> <?php do_action( 'woocommerce_before_single_product_summary' ); ?> </li> <li class="col2 clearfix"> <div class="summary"> <?php do_action( 'woocommerce_single_product_summary' ); ?> </div><!-- .summary --> </li> </ul> <?php do_action( 'woocommerce_after_single_product_summary' ); ?> <?php do_action( 'woocommerce_after_single_product' ); ?> <!-- END .col-main --> </li> <?php get_sidebar(); ?> </ul> </div><!-- #product-<?php the_ID(); ?> --> <!-- END .section --> </div>please help me out of this... |