PHP - Pear Xml Serializer Multiple Same Name Elements
hi guys
im using the pear xml serializer but i am running into a problem, i have a framework for an API which i use to create an array and then output as xml with xml serializer. The issue i have run into: i define a default tag before i create an array so my array is for example array( "a" "b" ) both of these will get labeled video in there xml thats fine <video>a</video> <video>b</video> ok so i have a whole bunch of "videos" with there _attributes set. inside each video i need multiple media elements <media x=2>x</media> <media x=4>x</media> <media x=5>x</media> my problem is that you cant add multiple items to an array with the same Key. array( "media" => x, "media" => x, "media" => x ) and if i let it default then the default tag is video plus i cant set the _attributes of the tag unless i make the value of the key into an array eg. array( "media" => array("_aributes" => array("x" => 1), "mediaValue" => "x"), "media" => array("_aributes" => array("x" => 2), "mediaValue" => "x"), "media" => array("_aributes" => array("x" => 2), "mediaValue" => "x") ) this will give me <media x=2><mediaValue>x</mediaValue></media> <media x=4><mediaValue>x</mediaValue></media> <media x=5><mediaValue>x</mediaValue></media> at the moment i get <video> <media x=2><mediaValue>x</mediaValue></media> </video> <video> <media x=4><mediaValue>x</mediaValue></media> </video> <video> <media x=5><mediaValue>x</mediaValue></media> </video> i want to get <media x=2>x</media> <media x=4>x</media> <media x=5>x</media> any help ? thanks im relay stuck on this one plus my API framework has constraints because it initializes the serializer at the end and inserts the array and parses outputs it even an injection work around would be good but the serializer seems to convert all tags into html char codes regards Similar TutorialsIn my code I call PEAR::isError to see if there was an error in the SQL Query so I can log it but its always returning this error. Does anyone know a fix? I have tried to search google it and found http://pear.php.net/bugs/bug.php?id=9950 but it does not say how to fix it. Does anyone have any ideas? Error Non-static method PEAR::isError() should not be called statically $query = "SELECT Column FROM TableName"; $res = $db['database']->query($query); if (PEAR::isError($res)) { $logger->err("Error pulling results from DB. Query:" . $query); } I am trying to work out how to correctly format an SQL query string from user data taken from multiple HTML text boxes/dropdowns. As an example assuming i have a searach page on which the user can enter search criteria into the following fields: name - text box site_location - drop down box (default set to 'search all') job_title - drop down box (default set to 'search all') manager - drop down box (default set to 'search all') email - textbox Its easy when all fields have user data set or one has user data set but when the user has entered data into only a couple of the fields I have problems constructing the SQL query, namely when it comes to adding the 'AND' keyword into the SQL query. No matter how i try to set out the logic in the PHP code i seem to end up with at least one combination of the search critea leading to back to back AND statements. I construct the SQL query by appending a string variable $query with the relevant search criteria, for example: $query = "select * from employees where "; if ($_POST['name'] != null) { $query=$query."name='".$_POST['name']."' "; } if ($_POST['site_location'] != 'all') { $query=$query."AND site_location='".$_POST['site_loaction']."' "; } //etc This does not work out though when fields are empty, I have tried adding additional if statements to check ahead to see if fields further down in the query are required and if so append an 'and' but I cannot seem to get the logic correct. Is this something anyone else has come accross, if so is there a better solution than the route i am going down? Thanks for reading. Long time lurker, first time poster here. I am having a problem with a multiple file uploader form I am trying to build. I am using the CodeIgniter framework, but I believe my problem is with the form itself. Here is the form: Code: [Select] <form action="http://localhost/show/submit" id="sendfiles" method="post" name="sendfiles" enctype="multipart/form-data"> <input type="hidden" name="doup" value="1" /> <input type="file" name="userfile1" value="" id="userfile1" size="20" /> <br /> <input type="file" name="userfile2" value="" id="userfile2" size="20" /> <br /> <input type="file" name="userfile3" value="" id="userfile3" size="20" /> <br /> <input type="submit" name="submit_btn" value="Upload" /> </form> The form is being passed to this function: if(empty($_POST['doup'])){ foreach($_REQUEST as $k => $v) print ">>> $k : $v <br />"; $data['form_open'] = form_open_multipart(uri_string(), array( 'id' => 'sendfiles', 'method' => 'post', 'name' => 'sendfiles' )); $data['form_flag'] = form_hidden('doup', '1'); $data['file1'] = form_input(array( 'id' => 'userfile1', 'name' => 'userfile1', 'size' => '20', 'type' => 'file', )); $data['file2'] = form_input(array( 'id' => 'userfile2', 'name' => 'userfile2', 'size' => '20', 'type' => 'file', )); $data['file3'] = form_input(array( 'id' => 'userfile3', 'name' => 'userfile3', 'size' => '20', 'type' => 'file', )); $data['form_submit'] = form_submit('submit_btn', 'Upload'); $data['form_close'] = form_close(); $this->load->view('show/submit', $data); } else { $config['allowed_types'] = 'mp3'; $config['max_size'] = '10240'; $config['upload_path'] = $this->config->item('file_upload_path'); $uploaded_files = array(); for($nona=1; $nona<4; $nona++){ if (strlen($_FILES['userfile'.$nona]['tmp_name']) <=0){ echo "tempname$nona failed"; continue; } //print "------ USERFILE $nona ------ <br />"; //print sizeof($_FILES['userfile'.$nona])."<br />"; //foreach ($_FILES['userfile'.$nona] as $k => $v){ // print "$k : $v <br />"; //} $this->upload->initialize($config); $upload = $this->upload->do_upload('userfile'.$nona); if (!$upload){ $form_errors = array('form_errors' => $this->upload->display_errors()); $this->load->view('show/submit', $form_errors); break; } else { $data = array('upload_data' => $this->upload->data()); $data = $data['upload_data']; $fp = $data['full_path']; $filename = strtolower(random_string('numeric', 16) . $data['file_ext']); $rel_path = 'show/submissons/uploaded/'; $path = $this->config->item('media_root_path') . $rel_path; exec('mkdir -p ' . $path , $a1, $r1); exec('mv ' . $fp . ' ' . $path . $filename, $a2, $r2); array_push($uploaded_files, $path . $filename); } } $this->session->set_flashdata('img_data',implode("||", $uploaded_files)); // redirect("show/submit_info"); } The problem is this: When I choose only one file to upload, it works. I can choose any of the 3 inputs and it works great. But as soon as I try to choose 2 or more files, the form fails to post. When I press submit, the page simply reloads and none of the form variables get posted. I have checked settings in php.ini and tried building and rebuilding this form. I'm hoping someone here can provide some insight into what I'm doing wrong? When I put all my code in one file, everything runs smooth, as soon as I try to put a chunk of code in a separte PHP file and use an include or require_once I get the error Assigning the return value of new by reference is deprecated in...PEAR\config.php yadda yadda I've done some research and I understand that passing an object by reference (&obj) is no longer acceptable in PHP 5, that's fine, but no where in my code do I have an ampersand, and again, it all works fine if it's all in the same .php file. So i figure i might be doing something wrong with my includes or something. The errors that I am getting are Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 80 Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166 Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config\Container.php on line 111 Code: [Select] include('config.php'); connect(); while ($row = mysql_fetch_assoc($ran_result)) { $ran_image = $row['image']; $category = $row['category']; $last = $row['l_name']; $first = $row['f_name']; $return = $row['item_return']; } echo "<div id='random'>\n"; echo "<h1>Random Signatures</h1>\n"; echo "<img src='../auto_images/$ran_image' /><br />\n"; echo "<p><a href='../auto_pages/signatures.php?c=$category&l=$last&f=$first'>$first $last</a></p>\n"; echo "<p>$return</p>\n"; echo "<br>"; echo "</div>"; ?> Am I doing something wrong with the include? I am trying to send an email to my gmail account using Mail SMTP. With the following code: <?php include 'incl/php/Mail.php'; $recipients = 'xxxxxxxx@gmail.com'; $headers['From'] = 'no-reply@newzstand.us'; $headers['To'] = $recipients; $headers['Subject'] = 'Test message'; $headers['Date'] = date('r', time()); $headers['Message-Id'] = '<'. microtime(true).'@newzstand.us>'; $body = 'Test message'; $domain = preg_replace("/.*@([^@]*)/", '\1', $recipients); $mxrr = getmxrr($domain, $mxhosts); $params['host'] = $mxhosts[0]; $params['localhost'] = 'mail.newzstand.us'; $params['username'] = 'no-reply'; $params['password'] = 'xxxxxxx'; // Create the mail object using the Mail::factory method $mail_object =& Mail::factory('smtp', $params); $send = $mail_object->send($recipients, $headers, $body); if (PEAR::isError($send)){ echo $send->getMessage(); }else{ echo 'No error'; } ?> I get the following message: Failed to connect to alt2.gmail-smtp-in.l.google.com:25 [SMTP: Failed to connect socket: Connection refused (code: -1, response: )] Why is Gmail refusing me? This topic has been moved to PHPFreaks.com Questions, Comments, & Suggestions. http://www.phpfreaks.com/forums/index.php?topic=359084.0 Hi all, Will reading on php.net about the famous mail() function somewhere in the notes, the author mentions to use Pear:: for sending larger amounts of email. Since I have never done anything with pear, I was wondering if it weren't better to start out with Pear, since it's more a long term thinking solution or shoudl i first start with mail(). I have read the Pear pagess, and all I saw were delayed mail sending and sending in larger quantities. If someone could maybe advise me on would could be a best practise i would love to hear Hello, I have been trying to get my script to draw a barcode but it always outputs a message saying "the image cannot be displayed because it contains errors". I have googled the problem and it seems to be about the headers, I also made sure the "extension=php_gd2.dll" is not commented in php.ini. Could anyone please let me know why this script from pear.php.net can't draw a barcode on my xampp 1.7.7 with php 5.3.8 Code: [Select] <?php require_once("Image/Barcode.php"); header("Content-type: image/png"); Image_Barcode::draw('1234', 'Code39', 'png'); ?> I am trying to use PEAR VALIDATION for a registration form an am not able to get it to work. require 'Validate/US.php'; $email = $_REQUEST['email']; $validate = new Validate(); if (!$validate->email("$email")) { echo "Invalid email"; } is what I am using. and I $email is defined earlier in the code as the user input for email. here is the rest of the code. <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "studentofstone@gmail.com"; $email_subject = "$first_name"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['address']) || !isset($_POST['city']) || !isset($_POST['state']) || !isset($_POST['zip']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $address = $_POST['address']; // required $city = $_POST['city']; // required $state = $_POST['state']; // required $state = $_POST['zip']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } require 'Validate/US.php'; $email = $_REQUEST['email']; $validate = new Validate(); if (!$validate->email("$email")) { echo "Invalid email"; } // $phoneNumber = '$telephone'; $result = Validate_US::phoneNumber($phoneNumber); echo 'Test ' . $phoneNumber .' : <br />'; var_export($result); echo '<br />'; if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" ); header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); header( "Cache-Control: no-cache, must-revalidate" ); header( "Pragma: no-cache" ); $email_message = "Form details below.\n\n"; $email_message = date("m/d/Y") . "\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "address: ".clean_string($address)."\n"; $email_message .= "city: ".clean_string($city)."\n"; $email_message .= "state: ".clean_string($state)."\n"; $email_message .= "zip: ".clean_string($zip)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); header("Location: https://www.paypal.com/"); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <? } ?> Hi everybody, I am working with SOAP-PEAR and run on a nasty problem I don't know answer to. First I explain what I know how to do. I am trying to construct a soap request and I know how to do this if XML has this structu Case 1 Code: [Select] <parent> <child1>string</child1> <child2>string</child2> <child3>string</child3> </parent> In this case, I construct an Array("root" => new Soap_Value("child1", "string", "value")).... Now my problem is that I don't know how to create an array() or some other data if XML structure is like this: Case 2 Code: [Select] <parent child1="value1" child2="value2" child3="value3" /> Could somebody please tell me how I can construct a SOAP request with SOAP-PEAR for that structure in Case 2? I just can't find a way to formulate it using arrays or some other data type Your help will greatly be appreciated. Thank you, Victor. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=349480.0 The script below works but it goes straight to the junk folder only since i added the parts below to the form. (the form is in another file) How do i stop it from going to the junk folder. Quote $error = $_GET['error']; $httpagent = getenv ('HTTP_USER_AGENT'); $url = $_SERVER['HTTP_REFERER']; Code: [Select] <?php require_once "Mail.php"; $optional = $_POST['optional']; $error = $_POST['error']; $url = $_POST['url']; $httpagent = $_POST['browser']; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $from = "Web server <removed>"; $to = "Admin <removed>"; $subject = "Someone has submitted an error."; $body = "Someone has submitted an error.\n". "Error: $error\n". "URL: $url\n". "Web browser: $httpagent\n". "Anything else you want to add?: $optional\n". "IP: $ip\n"; $host = "removed"; $username = "removed"; $password = "removed"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { header('Location: thank-you.html'); } ?> Quote Hello, Am a newbie using PEAR packages in my coding. I installed smarty on XAMPP recently and followed the configuration process in the 'php.ini' file, labelling the path to the '\libs\' directory. Before installation of smarty, my pear packages were working fine, never received any errors. However, after installing smarty and including my template file 'config.php' with 'Auth/HTTP.php' within the same file, i gor these errors; Warning: require_once(Auth/HTTP.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\OReilly\pear\blog\login.php on line 10 Fatal error: require_once() [function.require]: Failed opening required 'Auth/HTTP.php' (include_path='.;C:\xampp\smarty\libs') in C:\xampp\htdocs\OReilly\pear\blog\login.php on line 10 Warning: Cannot modify header information. Headers already sent by C:\xampp\htdocs\OReilly\pear\blog\login.php on line 10 Anybody got ideas what i can do to correct this issue, thanks. I have attached my templates file 'config.php' and my login script, the one that allows users to login be fore they access results to the database called 'login.php' This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=346325.0 This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=320893.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=322457.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=351896.0 Okay so I am using PEAR's Validate package to validate a few values in my form, it validates the username just fine, but is for some reason returning false on the password field, even if the credentials are correct. Here is the link to the package (http://pear.php.net/package/Validate/) Here is the code: Code: [Select] <?php require("Validate.php");?> <?php require("styles/top.php");?> <?php $validate = new Validate(); ?> <div id="head_reg"> <div id="head_cen_reg"> <div id="head_sup_reg" class="head_height_reg"> <?php require("scripts/newsfeed.php"); ?> <?php require("scripts/links.php"); ?> </div> </div> </div> <div id="content"> <br /> <?php if(isset($_POST['reg-btn'])){ $username = strip_tags ($_POST['username']); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['pass']); $repassword = strip_tags($_POST['repass']); if ($username && $password && $repassword && $email){ if($validate->string($username,$options = array( 'format' => VALIDATE_ALPHA, 'min_length' => 6, 'max_length' => 50))){ if($validate->string($password,$options = array( 'format' => VALIDATE_ALPHA, 'min_length' => 6, 'max_length' => 32))){ if ($password == $repassword){ if ($validate->email($email,$options = array( 'check_domain' => 'true', 'fullTLDValidation' => 'true', 'use_rfc822' => 'true', 'VALIDATE_GTLD_EMAILS' => 'true', 'VALIDATE_CCTLD_EMAILS' => 'true', 'VALIDATE_ITLD_EMAILS' => 'true', ))){ $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM users WHERE email='$email'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $pass = md5(md5($password)); $ip = $_SERVER['REMOTE_ADDR']; $date = date("F, d, Y g:i:s A"); mysql_query("INSERT INTO users VALUES ('', '$username', '$pass', '$email','Member', '$date','','0','$ip', '0')"); echo"<center>Thanks, $username! You have completed the registration process and may now login <a href=\"login.php\"><b>here!</b></center>"; } else echo"<center><font color=\"#FF0000\">That email is already in use!</font></center>"; } else echo"<center><font color=\"#FF0000\">That username is already taken!</font></center>"; } else echo"<center><font color=\"#FF0000\">That email is invalid!</font></center>"; } else echo"<center><font color=\"#FF0000\">Those passwords do not match!</font></center>"; } else echo"<center><font color=\"#FF0000\">Your password must be betweed 6 and 25 characters long!</font></center>"; } else echo"<center><font color=\"#FF0000\">Your username must be between 6 and 50 characters long!</font></center>"; } else echo"<center><font color=\"#FF0000\">You did not fill out the entire form!</font></center>"; } ?> <div id="register_form"> <form action="register.php" method="post" enctype="multipart/form-data"> <center> <table> <tr> <td>Desired Username </td> <td><input type="text" name="username" class="textbox" value="<?php $_POST['username'];?>"/></td> </tr> <tr> <td>E-Mail </td> <td><input type="text" name="email" class="textbox" value="<?php $_POST['email'];?>" /></td> </tr> <tr> <td>Password </td> <td><input type="password" name="pass" class="textbox" /></td> </tr> <tr> <td>Confirm Password </td> <td><input type="password" name="repass" class="textbox" /></td> </tr> <tr> <td><p class="register"> <input name="reg-btn" type="submit" class="btn" value="REGISTER" /> </p></td> </tr> </table> </center> </form> </div> <center><a href="#" id="showreg">Why register? Click here</a></center> <div id="content_cen"> <div id="content_sup"> <div id="welcom_pan"> <h3><span>Why</span> Register?</h3> <p>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla vitae diam magna, eget fringilla tellus. Curabitur est velit, suscipit eu faucibus eget, aliquam ac enim. per inceptos himenaeos. Nulla vitae diam magna, eget fringilla tellus.</p> </div> </div> </div> </div> <div id="foot_reg"> <div id="foot_cen_reg"> <ul> </ul> <p></p> </div> </div> </body> </html> This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=307948.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=314260.0 |