PHP - Warning: Domxpath::evaluate(): Invalid Expression
Hello All,
I have searched these forums and the net but haven't found an exact answer. I have a "path" (could be paths) that is/are causing warnings as it/they is/are poorly formed. This is bloating our logs, therefore I need to alleviate the issue. There are thousands of paths in the database so I do not know which are causing issues. I know I can add the "@" to the call to quiet the warning. First question: does that keep the warning from going into the logs?
I would prefer not to use the method above as it bypasses the real issue. Looking at the SimpleXMLElement documentation along with DOMDocument and DOMXPAth, I can't find a way to validate the actual path. All of the below throw a warning or notice: $xpath->evaluate($path); $xpath->query($path); $node->xpath($path); Final question: Is there a "simple" way to validate the $path prior to actually making the call to one of the methods of the various XML PHP classes?
Thank you for your time and assistance. Edited November 5, 2020 by oachSimilar TutorialsHi guys, I have a problem with the print out method. I have got a warning implode, I have tried to get passed with the invalid arguments, but I keep getting this in nowhere I can find any situations. however I am still getting this: Warning: implode() [function.implode]: Invalid arguments passed in /home/mysite/public_html/mysite.com/members.php on line 82 Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where username='test' and passwd='test'' at line 1 here's line 82: if ($names = implode(',',$insert)) { And here's the update code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myuser'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $firstname = clean($_GET['firstname']); //variable in the url you posted was firstname, not value. $lastname = clean($_GET['lastname']); $email = clean($_GET['email_address']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $query = "SELECT firstname, lastname, email_address FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($query) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<p id='myfirstname'>"; echo $row['firstname'] . "</p>"; echo "<p id='mylastname'>"; echo $row['lastname'] . "</p>"; echo "<p id='email_address'>"; echo $row['email_address'] . "</p>"; } $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password' AND firstname='$firstname' AND lastname='$lastname'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_row($result); // echo "The information have already been updated in the database"; } else { if(isset($_GET['firstname'])) { $insert[] = 'firstname = \'' . clean($_GET['firstname']) .'\''; } if(isset($_GET['lastname'])) { $insert[] = 'lastname = \'' . clean($_GET['lastname']) . '\''; } if(isset($_GET['email_address'])) { $insert[] = 'email_address = \'' . clean($_GET['email_address']) . '\''; } if ($names = implode(',',$insert)) { // $names = implode(',',$insert); } else { $sql="UPDATE members SET {$names} where username='{$username}' and passwd='{$password}'"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated"; } } } ?> Can someone help me how to ignore the warning implode when I did not included the $name method?? Hi , can somebody help me with this warning?
Warning: Invalid argument supplied for foreach() in /home/wwwdesig/public_html/mailer.php on line 12
It´s just a simple php mailer
Here is the php code:
<?php
if(isset($_POST['submit'])) { I am a total newbie at PHP and I have a wordpress plugin that works well but sometimes does not return any results to the query which I believe is causing this error: Warning: Invalid argument supplied for foreach() social-media-integrated-related-content-smirc/lib/smirclib.php on line 182 From what I am reading on other forums the problem is possibly that the foreach loop is empty since the array must have elements. The solution being to add a check above the foreach loop, to count the number of elements in the array, and if it is zero, skip the foreach loop. Is this correct? Here is the code....can someone please edit it so I can see an example of how it should be done? Again total PHP newbie so please be clear if possible. Thanks so much!!! Code: [Select] <? /** * Object for getting, parsing, and prepping external related content * * @author Husani S. Oakley * @version 1.0 */ class SMIRC{ var $total_results; var $page_title; var $default_header_text = "Blog discussions:"; var $search_urls = array( "google_blogsearch_norss" => "http://blogsearch.google.com/blogsearch?client=news&um=1&hl=en&scoring=d&q=SEARCHTERM&ie=utf-8", "google_blogsearch" => "http://blogsearch.google.com/blogsearch_feeds?client=news&um=1&hl=en&scoring=d&q=SEARCHTERM&ie=utf-8&num=NUMRESULTS&output=rss", "twitter_search" => "http://search.twitter.com/search.atom?q=SEARCHTERM&rpp=NUMRESULTS" ); /** * constructor */ function SMIRC($page_title, $title_separators, $required_keyword, $data_sources, $header_text, $animation=false){ $this->page_title = $page_title; $this->title_separators = $title_separators; $this->required_keyword = $required_keyword; $this->data_sources = $data_sources; if($header_text == ""){ $this->header_text = $this->default_header_text; } else { $this->header_text = $header_text; } $this->animation = $animation; } /** * main work method. create url, get data, parse, prep and return xhtml */ function getContent(){ //don't bother doing anything if we don't have any data sources if(!is_array($this->data_sources)){ return false; } //if we have delimiter characters, use them to split up the title $searchterm = $this->_getSearchTerm(); //start assembling data foreach($this->data_sources as $source_array){ //prep url $data_source = str_replace("SEARCHTERM", $searchterm, $this->search_urls[$source_array[0]]); $data_source = str_replace("NUMRESULTS", $source_array[1], $data_source); //get data, put into array $rss_data_array[$source_array[0]]['results'] = $this->_getResults($data_source, split("\n", $source_array[2])); $rss_data_array[$source_array[0]]['header'] = $source_array[3]; } //create and return xhtml for all sources $xhtml = $this->_createXHTML($rss_data_array, $this->header_text); return $xhtml; } /** * create and return all xhtml */ function _createXHTML($rss_array, $header_text){ foreach($rss_array as $data_source => $results_and_header){ //run function to get xhtml from rss object -- name of function depends on data source. $lists_xhtml .= $this->$data_source($results_and_header['results'], $results_and_header['header']); } if($lists_xhtml == ""){ //no results = no xhtml return false; } else { $all_xhtml = '<div class="smirc_wrapper">'; $all_xhtml .= '<h2 class="collapsed">'.$this->_getHeaderXHTML().'</h2>'; $all_xhtml .= '<ul class="smirc_ul">'; //add results to overall xhtml $all_xhtml .= $lists_xhtml; $all_xhtml .= "</ul>"; $all_xhtml .= '</div>'; return $all_xhtml; } } /** * GOOGLE BLOGSEARCH: iterate through rss object and create standards-compliant xhtml for the resultset, while ignoring items in exclude list */ function google_blogsearch($rss_items, $result_header){ $list_xhtml = ""; if(count($rss_items) >= 1){ $list_xhtml = ""; foreach($rss_items as $item){ $fixed_item = $this->_parseItem($item); $list_xhtml .= '<div class="summary">'.strip_tags($fixed_item['summary']).'</div></li>'; } } return $list_xhtml; } /** * TWITTER SEARCH: iterate through rss object and create standards-compliant xhtml for the resultset * search.twitter.com doesn't seem to have results limits, so we'll have to do that manually. */ function twitter_search($rss_items, $result_header){ $list_xhtml = ""; if(count($rss_items) >= 1){ $list_xhtml = ""; foreach($rss_items as $item){ $fixed_item = $this->_parseItem($item); $list_xhtml .= '<li>'.$fixed_item['atom_content'].' by <a href="'.$fixed_item['author_uri'].'" rel="nofollow" target="_blank">'.$fixed_item['author_name'].'</a></li>'; } } return $list_xhtml; } /** * use title separators (if any) to prepare search term(s) */ function _getSearchTerm(){ if(is_array($this->title_separators)){ //make this easy -- replace all matches to items in separators array with a common character $title = $this->page_title; foreach($this->title_separators as $delimiter){ $title = str_replace($delimiter, "###", $title); } //split by this common character $arr = split("###", $title); //iterate, trim, add to array foreach($arr as $phrase){ $searchterms[] = trim($phrase); } $searchterms[] = $this->required_keyword; } else { //no separators. search terms are title and required keyword if any $searchterms[] = $this->page_title; $searchterms[] = $this->required_keyword; } //iterate through searchterms and add quotation marks / urlencode as needed $str = a; foreach($searchterms as $term){ $str .= '' . urlencode($term) . ''; } return $str; } /** * using the exclude list (if set) and MagpieRSS, return an array of data sources and results */ function _getResults($data_source, $exclude_list){ $rss = fetch_rss($data_source); //set total results $this->_setTotalResults($rss); $results = $rss->items; //is there an exclude list? if(is_array($exclude_list)){ //yes. iterate and remove foreach($exclude_list as $exclude_me){ $matches = $this->array_search_recursive($exclude_me, $results); unset($results[$matches[0]]); } } return $results; } /** * unfortunately-ghetto way to remove google's BOLDING of matching wordds */ function _parseItem($arr){ $newarr; if(!is_array($arr)){ return $arr; } foreach($arr as $key => $value){ $newval = str_replace("<b>", "", $value); $newval = str_replace("</b>", "", $newval); $newarr[$key] = $newval; } return $newarr; } /** * recursively search a multidimensional array */ function array_search_recursive($needle, $haystack, $path=array()){ foreach($haystack as $id => $val){ $path2 = $path; $path2[] = $id; if(eregi($needle, $val)){ return $path2; } else if(is_array($val)){ if($ret = $this->array_search_recursive($needle, $val, $path2)){ return $ret; } } return false; } } /** * add to total results count */ function _setTotalResults($rss){ if($rss->channel['opensearch']['totalresults']){ $this->total_results = $this->total_results + $rss->channel['opensearch']['totalresults']; } } /** * create header text / link */ function _getHeaderXHTML(){ //create link $link = str_replace("SEARCHTERM", $this->_getSearchTerm(), $this->search_urls['google_blogsearch_norss']); return " "; } } ?> I have the following code: if ( !empty($_GET['quantity']) ) { foreach ( $_GET['quantity'] as $order_code => $quantity ) { // line 13 $Cart->setItemQuantity($order_code, $quantity); } } and I'm getting the following error: Quote Warning: Invalid argument supplied for foreach() in shopping-cart/cart_action.php on line 13 $_GET['quantity']; has a value of '1' The code is working perfectly fine on localhost, but throws me that warning on my webserver(both have error reporting set to E_ALL) any help is greatly appreciated. Thanks. I keep getting the following error. Warning: Invalid argument supplied for foreach() in /home/content/46/8529846/html/wp-content/themes/super-light/functions.php on line 94 Warning: Cannot modify header information - headers already sent by (output started at /home/content/46/8529846/html/wp-content/themes/super-light/functions.php:94) in /home/content/46/8529846/html/wp-includes/pluggable.php on line 866 Code: [Select] <?php if ( ! isset( $content_width ) ) $content_width = 650; add_action( 'widgets_init', 'super_light_sidebars' ); function super_light_sidebars() { register_sidebar(array( 'name' => __( 'Sidebar Widget Area', 'super_light'), 'id' => 'sidebar-widget-area', 'description' => __( 'The sidebar widget area', 'super_light'), 'before_widget' => '<div class="widget">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>', )); } register_nav_menus( array( 'primary' => __('Header Menu', 'super_light'), 'secondary' => __('Footer Menu', 'super_light') ) ); //Multi-level pages menu function super_light_page_menu() { if (is_page()) { $highlight = "page_item"; } else {$highlight = "menu-item current-menu-item"; } echo '<ul class="menu">'; wp_list_pages('sort_column=menu_order&title_li=&link_before=&link_after=&depth=3'); echo '</ul>'; } //Single-level pages menu function super_light_menu_flat() { if (is_page()) { $highlight = "page_item"; } else {$highlight = "menu-item current-menu-item"; } echo '<ul class="menu">'; wp_list_pages('sort_column=menu_order&title_li=&link_before=&link_after=&depth=1'); echo '</ul>'; } add_editor_style(); add_theme_support('automatic-feed-links'); add_theme_support('post-thumbnails'); set_post_thumbnail_size( 120, 120, true ); // Default size // Make theme available for translation // Translations can be filed in the /languages/ directory load_theme_textdomain('super_light', get_template_directory() . '/languages'); function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img = "/images/default.jpg"; } return $first_img; } add_action('save_post','custom_field_add_tags'); function custom_field_add_tags($post_id) { $post = get_post($post_id); //get values of custom fields and put into array $tag1 = get_post_meta($post_id, 'tag_name1', true); $tag2 = get_post_meta($post_id, 'tag_name2', true); $tag3 = get_post_meta($post_id, 'tag_name3', true); $tag4 = get_post_meta($post_id, 'tag_name4', true); $tag5 = get_post_meta($post_id, 'tag_name5', true); $tag6 = get_post_meta($post_id, 'tag_name6', true); $tag7 = get_post_meta($post_id, 'tag_name7', true); $tag8 = get_post_meta($post_id, 'tag_name8', true); $tag9 = get_post_meta($post_id, 'tag_name9', true); $tags_to_add = array($tag1, $tag2, $tag3, $tag4, $tag5, $tag6, $tag7, $tag8, $tag9); //now check if tag does not already exist (if no - add tag from custom field) $add_tags = array(); foreach(get_the_terms($post_id, 'post_tag') as $term) if(!in_array($term->slug, $tags_to_add)) $add_tags[] = $term->slug; if(!empty($add_tags)) wp_add_post_tags($post_id, implode(',', $add_tags)); } ?> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355998.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319071.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=308349.0 i have a problem i cant solved for cople of hours! this is the function: function show_posts($user_id,$limit=0){ $posts = array(); $user_string = implode(',', $user_id); $extra = " and id in ($user_string) "; if ($limit > 0){ $extra = "limit $limit"; }else{ $extra = ''; } $sql = "SELECT userid, caption, stamp, filename FROM photographs WHERE userid in ($user_string) order by stamp desc $extra"; //echo $sql; $result = mysql_query($sql) or die(mysql_error()) ; while($data = mysql_fetch_object($result)){ $posts[] = array( 'stamp' => $data->stamp, 'userid' => $data->userid, 'caption' => $data->caption, 'filename' => $data->filename, ); } return $posts; } and thats the full error: Warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\includes\functions.php on line 12 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') order by stamp desc' at line 2 and the intresting thing that if i echo the sql i get a working one i checked it in phpmyadmin + it shows what it need to show in the index.php if i comment the "or die(mysql_error()) " here the sql when its do echo SELECT userid, caption, stamp, filename FROM photographs WHERE userid in (4,7,2) order by stamp desc limit 5 so y the hell this problem is keep coming? i really cant understand what wrong! tnx for the help! I am using a PHP class (it is attached) for Google Analytics that I got from this link below: http://www.acleon.co.uk/?p=173 Unfortunately, it appears the Class has a PHP error: Warning: implode() [function.implode]: Invalid arguments passed in Galvanize.php on line 114 and line 181. This is line 114: setcookie('__utmc', implode('.', $this->UTMC), 0, $this->CookiePath, $this->getDomain()); Here is line 181: $urchinUrl .= '&utmcc=__utma%3D'.implode('.', $this->UTMA).'%3B%2B__utmz%3D'.implode('.', $this->UTMZ).'%3B'; I did not see UTMC and UTMZ declared anywhere in the Class. The class file is attached. Thanks for your help in advance. Hello, I'm just a beginner (and french sorry for my language) : have some pb with my little implode function. It's Running well on my local webserver (MAMP - PHP PHP Version 5.2.17) but when tested on ovh server (PHP4) show this error : Warning: implode() [function.implode]: Invalid arguments passed in /homez.xx/myPathHere/entete.php5 on line 6 I understand 1/ that one argument is missing but don't find the right syntax 2/ I have tried to turn this file on php5 with this extension (ovh is under php4) Here is my code in page defining the value and where stay my query (entete.php5) <?php if (isset($theme)) { $t = implode(',',$theme); $lien = "aide.php5?theme=".$t; $aide = '<a href="'.$lien.'">'.$onglet[0].'</a>'; } else { $aide = ""; } ?> Here is my code in page which show result (aide.php5) $t = explode(',',$_GET['theme']); $n = count($t); if ($n == 1) { $where = "id = ".$t[0]; } else { $where = "id = ".$t[0]; for ($i=1;$i<$n;$i++) { $where .= " OR id=".$t[$i]; } } Hope someone kindly help me : thanks in advance I am getting this error in the header.php of my wordpress theme... Can anyone help? Thanks! Warning: implode() [function.implode]: Invalid arguments passed in /home/bexxx/public_html/wp-content/themes/organic_portfolio_gray/header.php on line 74 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <meta name="distribution" content="global" /> <meta name="robots" content="follow, all" /> <meta name="language" content="en" /> <title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' :'; } ?> <?php bloginfo('name'); ?></title> <link rel="Shortcut Icon" href="<?php echo bloginfo('template_url'); ?>/images/favicon.ico" type="image/x-icon" /> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" /> <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" /> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?> <?php wp_enqueue_script("jquery"); ?> <?php wp_head(); ?> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/superfish/superfish.js"></script> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/superfish/hoverIntent.js"></script> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.flow.1.1.js"></script> <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/iepngfix_tilebg.js"></script> <!--IE6 Fix--> <style type="text/css"> img, div, a, input, body, span { behavior: url(<?php bloginfo('template_url'); ?>/images/iepngfix.htc); } </style> <script type="text/javascript"> var $j = jQuery.noConflict(); $j(function() { $j("div#controller").jFlow({ slides: "#slides", width: "960px", height: "480px", timer: <?php echo ot_option('slider_interval'); ?>, duration: 400 }); }); </script> <script type="text/javascript"> $j(document).ready(function() { $j('ul.ot-menu').superfish(); }); </script> </head> <body> <div id="wrap"> <div id="header"> <div class="headercenter"> <p id="title"><a href="<?php echo get_option('home'); ?>/" title="Home"><?php bloginfo('name'); ?></a></p> </div> </div> <div id="navbar"> <div id="nav"> <div id="navbarleft"> <ul class="ot-menu"><li<?php if (is_home()) { echo " class=\"current_page_item\""; }?>><a href="<?php echo get_settings('home'); ?>"><?php _e("Home", 'organicthemes'); ?></a></li> <?php $include_categories = ot_option('include_categories'); ?> <?php wp_list_categories('depth=4&title_li=&sort_column=menu_order&include='.implode(',', $include_categories)); ?></ul> </div> <div id="navbarright"> <ul class="ot-menu"> <?php $include_pages = ot_option('include_pages'); ?> <?php wp_list_pages('title_li=&sort_column=menu_order&include='.implode(',', $include_pages)); ?> </ul> </div> </div> </div> <div style="clear:both;"></div> My error is 'Warning: implode() [function.implode]: Invalid arguments passed in /home/definiti/public_html/contact.php on line 73' Im not sure how to fix this error, as I looked online and it says that my implode() has the right layout too it.. Line 73 in my code (I took the HTML code out) is this line; Code: [Select] $message = implode("<br>\n", $messages); My whole code is; Code: [Select] <?php # PHP Copyright 2007, Thomas Boutell and Boutell.Com, Inc. # Edited by Definition Designs. $recipient = 'defenitiondesigns@googlemail.com'; $serverName = 'www.definition-designs.co.uk'; if ($_POST['send']) { sendMail(); } elseif (($_POST['cancel']) || ($_POST['continue'])) { redirect(); } else { displayForm(false); } function displayForm($messages) { global $login; $escapedEmail = htmlspecialchars($_POST['email']); $escapedRealName = htmlspecialchars($_POST['realname']); $escapedSubject = htmlspecialchars($_POST['subject']); $escapedBody = htmlspecialchars($_POST['body']); $returnUrl = $_POST['returnurl']; if (!strlen($returnUrl)) { $returnUrl = $_SERVER['HTTP_REFERER']; if (!strlen($returnUrl)) { $returnUrl = '/'; } } $escapedReturnUrl = htmlspecialchars($returnUrl); ?> <?php if (count($messages) > 0) { $message = implode("<br>\n", $messages); echo("<h4>$message</h4>\n"); } ?> <form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>"> <p> <b>Your</b> Email Address <input name="email" size="35" maxlength="35" value="<?php echo $escapedEmail?>"/> </p> <p> Your <b>Real</b> Name <input name="realname" size="35" maxlength="35" value="<?php echo $escapedRealName?>"/> </p> <p> Subject Of Your Message <input name="subject" size="35" maxlength="35" value="<?php echo $escapedSubject?>"/> </p> <p> <i>Please enter the text of your message in the field that follows.</i> </p> <textarea name="body" rows="10" cols="60"><?php echo $escapedBody?></textarea> <p> <input type="submit" name="send" value="Send Your Message"/> <input type="submit" name="cancel" value="Cancel - Never Mind"/> </p> <input type="hidden" name="returnurl" value="<?php echo $escapedReturnUrl?>"/> </form> <?php } function redirect() { global $serverName; $returnUrl = $_POST['returnurl']; $prefix = "http://$serverName/"; if (!beginsWith($returnUrl, $prefix)) { $returnUrl = "http://$serverName/"; } header("Location: $returnUrl"); } function beginsWith($s, $prefix) { return (substr($s, 0, strlen($prefix)) === $prefix); } function sendMail() { global $recipient; $messages = array(); $email = $_POST['email']; if (!preg_match("/^[\w\+\-\.\~]+\@[\-\w\.\!]+$/", $email)) { $messages[] = "That is not a valid email address. In format: You@something.com"; } $realName = $_POST['realname']; if (!preg_match("/^[\w\ \+\-\'\"]+$/", $realName)) { $messages[] = "The real name field must contain only alphanumeric characters, spaces and + or - signs."; } $subject = $_POST['subject']; if (preg_match('/^\s*$/', $subject)) { $messages[] = "Please specify a subject for your message. "; } $body = $_POST['body']; if (preg_match('/^\s*$/', $body)) { $messages[] = "Your message was blank. Fill out a message or Click Cancel to cancel message."; } if (count($messages)) { displayForm($messages); return; } mail($recipient, $subject, $body) or die("unable to send the mail!"); $escapedReturnUrl = htmlspecialchars($_POST['returnurl']); ?> <form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>"> <input type="submit" name="continue" value="Click Here To Continue"/> <input type="hidden" name="returnurl" value="<?php echo $escapedReturnUrl?>"/> </form> <?php } ?> so i am trying to make my api for a website, and started coding a script for it.
so far it looks like this
<?php Hey all long time no post lol so im working on improving this RosterAPI Josh Grochowski made and im adapting it for use with a nother site my issue is this i have to get data from an html file the data i wana collect in nested like this Code: [Select] <div class="talentcalc-info"> <div class="third-party"> <a href="javascript:;" data-fansite="talentcalc|paladin|000000000000000000003202322312112110022000000000000000000000" class="fansite-link "> </a> </div> <div class="export" style="display: none"><a href="#">Export</a></div> <div class="calcmode"><a href="javascript:;">Calculator mode</a></div> <div class="restore" style="display: none"><a href="javascript:;">Restore</a></div> <div class="reset" style="display: none"><a href="javascript:;">Reset</a></div> <div class="pointsspent" style="display: none"><span class="name">Points spent:</span><span class="value"><span>0</span><ins>/</ins><span>30</span><ins>/</ins><span>0</span></span></div> <div class="pointsleft" style="display: none"><span class="name">Points left:</span><span class="value">0</span></div> <div class="requiredlevel" style="display: none"><span class="name">Required level:</span><span class="value">-</span></div> </div> being that "talentcalc|paladin|000000000000000000003202322312112110022000000000000000000000" is the data i wana retrive i have tryed Code: [Select] query('.//div[@class="talentcalc-info"]/div[@class="third-party"]/a');but im getting no where fast any ideas guys? Hi, I've been tearing my hair out over this problem for hours (and I've precious little left as it is). It's hopefully just a 'wood for the trees' moment. I'm trying to parse XML search results using DOMDocument and DOMXPath, the problem is that the DOMDocument never seems to get populated. I can load the XML result set via cURL fine, and the XML validates ok. Here's my code: $xmldoc = new DOMDocument(); $xmldoc->load( 'http://searchserver/xml.cgi?collection=test&query=' ); $xpath = new DOMXPath( $xmldoc ); $results = $xpath->query( "/padre_result_packet" ); echo '<pre>'; print_r( $results ); echo '</pre>'; And here's an example of the XML I'm working with: Code: [Select] <?xml version="1.0" encoding="iso-8859-1" standalone="no" ?> <PADRE_result_packet> <details> <padre_version>Unknown</padre_version> </details> <error> <usermsg>Please specify a valid query</usermsg> <adminmsg>The query parameter is invalid or missing</adminmsg> </error> </PADRE_result_packet> The result is: Code: [Select] DOMNodeList Object ( ) Does anybody have some advice? I was getting the following error when using $xmldoc->loadXML: Code: [Select] Warning: DOMDocument::loadXML(): Start tag expected, '<' not found in Entity, line: 1 HI I am very confused right now guys. I have no idea how to evaluate my upload script. This adds CSV lines into my phpmyadmin table and it works fine, but i want to make it more user friendly so users could simply `save as` an XLS file into a CSV file without making any adjustments. And so the program would do most of the work from there. So if my CSv file looks like this: , ,, ,,,,, some word, random, ,,,, #Batch 312-313 312,John Smith, New Jersey,, //line 1 313, Ana White, California,, //line 2 #Batch 314-315 314, Greg Long, Mexico //line 3 315, Jane Snow, Texas,, //line 4 Prepared by:, Jack Brown, CPA I need help on how to add only the four lines into the fields: `number`, `name`, `address` How do i disregard any other things in the CSV except for words that should be on my database? Thank you for your time, and have a nice day. I am just wondering if there is a PHP script/command that can evaluate if all form fields from a given form are completed upon submitting. Example: If I have a form with three form fields (name, email, phone), do I have to setup a Code: [Select] if($_POST['name'] == '' || $_POST['email'] == '' || $_POST['phone'] == '') { redirect with error } else { continue } to evaluate if each was completed or is there a short cut that will automatically determine if any fields were left blank? Just curious. Thanks to any and all responses. Hi Everyone I am having a few issues with my website. I have developed in on my xampp local host and it works ok but when I upload the files and try to renew a membership using stripe I get the following messages. Warning: session_start(): Cannot start session when headers already sent in /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/inc/settings.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/procedures/payments/charge.php:1) in /customers/a/d/f/mywebsite.co.uk/httpd.www/mywebsite/procedures/payments/charge.php on line 141 I have some includes that appear on every page. This is the bootstrap.php file. This file holds the settings.php which connects to my database and other function files. In this settings page I call the session_start() php function and then connect to my database. I call the bootstrap.php file on every page to there for call the session_start() on every page. I am using sessions alot so is this the right thing to do? I have attached the renew_membership payment page which holds the form. The user fills out the payment page and the form data gets sent to a script called charge.php which uses the stripe objects to make the payment. I then want to do a redirect to the paymentSuccess.php page to output to the user that the payment was made successfully. This is where the issues arrise. I have split the charge file into 3 screen shots so it is more readable. Hope someone can help me. Thanks a lot David
Edited April 26 by Irish_Dave <?php if(isset($_POST['submit'])){ $name = $_POST['name']; } ?> <form method="POST" action="hist1.php"> <br /> <input type="hidden" name="name" value="<?php echo $name ?>" /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question1 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q1"><br /><br /> <label class="items">1st Question :</label> <br /> <center> <textarea class="textareaQ" name="question1" readonly><?php echo $question1; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad1" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad1" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad1" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q2"><label title="Proceed to 2nd Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question2 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q2"><br /><br /> <label class="items">2nd Question :</label> <br /> <center> <textarea class="textareaQ" name="q2" readonly><?php echo $question2; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad2" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad2" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad2" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q1"><label title="Proceed to 1st Question">Back</label></a> | <a class="nxt" href="#q3"><label title="Proceed to 3rd Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question3 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q3"><br /><br /> <label class="items">3rd Question :</label> <br /> <center> <textarea class="textareaQ" name="q3" readonly><?php echo $question3; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad3" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad3" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad3" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q2"><label title="Proceed to 2nd Question">Back</label></a> | <a class="nxt" href="#q4"><label title="Proceed to 4th Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question4 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q4"><br /><br /> <label class="items">4th Question :</label> <br /> <center> <textarea class="textareaQ" name="q4" readonly><?php echo $question4; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad4" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad4" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad4" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q3"><label title="Proceed to 3rd Question">Back</label></a> | <a class="nxt" href="#q5"><label title="Proceed to 5th Question">Next</label></a> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> <br /><br /> <?php $q = mysql_query("SELECT * FROM histact1 WHERE question != '$question1' AND question != '$question2' AND question != '$question3' AND question != '$question4' ORDER BY RAND() LIMIT 1"); while ($r1 = mysql_fetch_array($q)){ $id = $r1[0]; $question5 = $r1[1]; $opt1 = $r1[3]; $opt2 = $r1[4]; $opt3 = $r1[5]; ?> <div class="Qset" id="q5"><br /><br /> <label class="items">5th Question :</label> <br /> <center> <textarea class="textareaQ" name="q5" readonly><?php echo $question5; ?></textarea> </center> <br /><br /> <p class="marA"> <input type="radio" name="rad5" value="<?php echo $opt1; ?>" /> <label class="lbl"><?php echo $opt1 ?></label><br /> <input type="radio" name="rad5" value="<?php echo $opt2; ?>" /> <label class="lbl"><?php echo $opt2 ?></label><br /> <input type="radio" name="rad5" value="<?php echo $opt3; ?>" /> <label class="lbl"><?php echo $opt3 ?></label><br /> </p> </div> <div class="lr"> <center> <br /><br /><br /><br /> <a class="nxt" href="#q4"><label title="Proceed to 4th Question">Back</label></a> | <input type="submit" title="Submit Answers" name="submit" class="submit" value=" Submit " onclick="return confirm('Are you sure you want to submit your answers?\nYou can review your answer by click the Back link')" /> </center> </div> <br /><br /><br /> <center><hr width="90%" /></center><br /> <?php } ?> </form> Edited by mac_gyver, 09 October 2014 - 10:51 AM. code in code tags please |