PHP - Returning Error Codes
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! Similar Tutorialshey guys. Right now upon form submission, I do an error check that puts all the errors into an array, then will display them at the top of the form. What I want to do though is break up the array, and be able to give each error msg in its indivdual table row in the html. Right now, my coding is if($lname == '') { $errmsg_arr[] = 'You must enter your last name'; $errflag = true; } if($email == '') { $errmsg_arr[] = 'You must enter your email address'; $errflag = true; } if($city == '') { $errmsg_arr[] = 'You must enter your city'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: signup_artist.php"); exit(); } thats in form2.php form 1.php has the following snipet of code <?php if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) { echo '<ul class="err">'; foreach($_SESSION['ERRMSG_ARR'] as $msg) { echo '<li>',$msg,'</li>'; } echo '</ul>'; unset($_SESSION['ERRMSG_ARR']); } ?> so basically would I would like to be able to do is identify each error as for instane $fname_error $lname_error etc and then load them into my html appropriately, as opposed to just an array listing them 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 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 ; ?> 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'); } Hi I am new to php, I am trying to capture the url and place into a variable but I only get the 1st digit to show, I just cant see what I am doing wrong. Sorry to ask such a basic question but I just can't work it out, I have attached a screen shot of all me code, your help would be very very much appreciated. Hello, I have been trying to come up with bar codes in php to represent integers for example 7432973853. How do I get a bar code for a particular string of numbers? hello freinds, iam new to this forum and new to php. i have just finished a course on html and css. but now i have realised that its become comulsory for me to learn php. but iam confused as to what ellements of php i should learn. since this is a programming language i find its gonna be real tuff for me, can u please advise as to which parts i should learn first to get going. i wont be developing custom websites for customers, just for my own hobbies. my main ambition is to utilise API's in my websites. Thanx Well my forum code is almost complete and one feature it is lacking is BB Codes. How would I go about making BB Codes for the following: Code: [Select] [URL=Url]Title[/URL] [IMG]Img Url[/IMG] [b]bold[/b] [i]Italics[/i] [u]Underline[/u] [s]Strike-through[/s] These are the only ones I want atm so any help would be appreciated. I am not sure what is going wrong but I have not changed any of my codes and now I am getting this error message on a simple form that I am testing. Any idea what has happened. I have had several successful tries that have updated to the db. Quote Warning: mysql_query() [function.mysql-query]: Access denied for user 'ebermy5'@'localhost' (using password: NO) in /home/ebermy5/public_html/form.php on line 20 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/ebermy5/public_html/form.php on line 20 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ebermy5/public_html/form.php on line 21 Warning: mysql_query() [function.mysql-query]: Access denied for user 'ebermy5'@'localhost' (using password: NO) in /home/ebermy5/public_html/form.php on line 29 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/ebermy5/public_html/form.php on line 29 This is the form Code: [Select] <?php @include_once ("Connections/connect_to_mysql.php") or die('could not connect to database'); $err=''; if($_POST["submit"]){ // Validate form data if($_POST["firstname"]=='') $err.='Please enter First Name<br>'; if($_POST["email"]=='') $err.='Please enter Email<br>'; if($err==''){ // Check if there are duplicate entries in the 'contacts' table $results = mysql_query("SELECT id FROM `Members` WHERE firstname='".addslashes($_POST["firstname"])."' and Email='".addslashes($_POST["email"])."'"); if($row = mysql_fetch_array($results)){ $err.='Can not add duplicate entry<br>'; } else{ // adding new record to 'contacts' table mysql_query("INSERT INTO Members (firstname,lastname,country,Email) values ('".addslashes($_POST["firstname"])."','".addslashes($_POST["lastname"])."','".addslashes($_POST["country"])."','".addslashes($_POST["email"])."')"); // redirecting to success screen exit; } } } ?>The HTML below.. Code: [Select] <html> <head> <title>Add New Contact</title> </head> <body> <h2>Register with us</h2> <?php echo $err==''?'':('<p style="color:red;">'.$err.'</p>') ?> <form method="post" action="form.php"> <table border="0"> <tr> <td valign="middle">First Name:</td> <td><input type="text" name="firstname" size="30" value="<?php echo htmlspecialchars($firstname) ?>"></td> </tr> <tr> <td valign="middle">Last Name:</td> <td><input type="text" name="lastname" size="30" value="<?php echo htmlspecialchars($lastname) ?>"></td> </tr> <tr> <td valign="middle">Country:</td> <td><input type="text" name="country" size="30" value="<?php echo htmlspecialchars($country) ?>"></td> </tr> <tr> <td valign="middle">Email:</td> <td><input type="text" name="email" size="30" value="<?php echo htmlspecialchars($email) ?>"></td> </tr> </table><br> <input type="submit" name="submit" value=" Submit! "> </form> </body> </html> Hello everyone, Can somebody help me? I am a novice in PHP programming. I do not understand a line of code below: $action = isset($_GET['action']) ? $_GET['action'] : ''; The variables $action saves the values obtained by the GET method, but what does this piece of code ? $_GET['action'] : ''; Thanks in advance! Hi, below is the output from FMS streams in XML format. and there is no way i can change the format of XML file, how do it just get just codes( like 20p5tc0bqm25an2, 42fem6h84kq3nmb, etc) Thank you <?xml version="1.0" encoding="utf-8" ?> - <result> <level>status</level> <code>NetConnection.Call.Success</code> <timestamp>8/25/2010 2:51:34 AM</timestamp> <name>_defaultRoot_:_defaultVHost_:::_1</name> - <data> <_0>20p5tc0bqm25an2</_0> <_1>42fem6h84kq3nmb</_1> <_2>b2zudqmrfqa05a6</_2> <_3>bsbzrnde1z4qmdv</_3> <_4>cgpm8wlvzyrp6b7</_4> <_5>hqy95ympgq1t5ui</_5> <_6>qa8ultkr5pv2vas</_6> <_7>qr94iqvdqag26ee</_7> <_8>wjesw80adgv4usu</_8> <_9>zcdua1yok7kw5l4</_9> </data> </result> Hey eveyone, I have this great idea I would love to do but I have some questions and whenever I have questions I come here and they always get answered :-) Anyway what do you guys know about SMS short codes (you know those commercials on TV that are like text ringtone1 to 555)? I did some quick reading and it seems they are super expensive?!? Is there anyway to get them free or cheaper if you can write your own code? Has anyone had any experience with sms short codes? Also is there anyway for a site to receive a SMS and then charge that persons service provider with php? Thanks Hellow every one; i need little help to change code in my script version as i have older version codes and em using new version script so i need to change codes on my version script. iam using latest script which codes are these Quote if ($CURUSER['control_panel'] == 'yes' && $privacylevel == 'strong') print('<td class="f-border comment-details" align="left" width="15%"><center><strong>'.$postername.'</strong><br /><i>'.$title.'</i><br /><img width="80" height="80" src="'.$avatar.'"><br /><br />Uploaded: ---<br />Downloaded: ---<br />Ratio: ---<br /><br /><a href="account-details.php?id='.$row["user"].'"><img src="themes/'.$THEME.'/forums/icon_profile.gif"></a> <a href="mailbox.php?compose&id='.$row["user"].'"><img src="themes/'.$THEME.'/forums/icon_pm.gif" ></a></center></td>'); and Quote else print('<td class="f-border comment-details" align="left" width="15%"><center><strong>'.$postername.'</strong><br /><i>'.$title.'</i><br /><img width="80" height="80" src="'.$avatar.'"><br /><br />Uploaded: '.$useruploaded.'<br />Downloaded: '.$userdownloaded.'<br />Ratio: '.$userratio.'<br /><br /><a href="account-details.php?id='.$row["user"].'"><img src="themes/'.$THEME.'/forums/icon_profile.gif"></a> <a href="mailbox.php?compose&id='.$row["user"].'"><img src="themes/'.$THEME.'/forums/icon_pm.gif" ></a></center></td>'); and i want to change them under Quote if ($row["class"] == 3 || $row["donated"] > 0) { if ($site_config["donatedstar"] || $site_config["vipstar"]) { $star = "<img src=images/star.gif border=0>"; } else { $star = ""; } } if ($privacylevel != "strong" || ($CURUSER["control_panel"] == "yes")) { print("<tr><td valign=top width=150 align=left class=table_col2><center><b>$postername $star</b><br><i>$title</i></center><br>Uploaded: $useruploaded<br>Downloaded: $userdownloaded<br>Ratio: $userratio<br><br><center><img width=80 height=80 src=$avatar></center><br></td>"); and Quote }else{ print("<tr><td valign=top width=150 align=left class=table_col2><center><b>$postername $star</b><br><i>$title</i></center><br>Uploaded: ---<br>Downloaded: ---<br>Ratio: ---<br><br><center><img width=80 height=80 src=$avatar></center><br></td>"); } and one more thing i have two different images for both classes as in older codes version only one image specify for both class but em using two images for "Donated" = start.gif and for "VIP" = vip.gif so i want both images for both class so pls help me how to do them. Thanks, Regards. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=317279.0 I'm trying to create a part of a script where by the system will generate a sku code and loop through out to see if this exists in the database, if the sku does the script adds one too the code so 001 will turn to 002 then it will keep looping until it finds a SKU that isn't in the database.
However I can get the script to keep generating the new SKU codes but it will only test the first SKU code so the loop will keep going if it exists.
$number=001; if(isset($_POST['submit'])){ $product = $_POST['product']; $brand = $_POST['brand']; $description = $_POST['description']; $contruct=strtoupper($product."-".$brand."-".$description); $number=sprintf("%03s",$number); $check_for=$contruct."-".$number; $query=$cc_db->query("SELECT `sku` FROM `product` WHERE `sku`='".$check_for."'"); $fetch=$cc_db->fetch_object($query); $checking=$cc_db->num_rows($query); while($checking > 0){ echo"$check_for is there : $checking rows : $fetch->sku<br>"; $number=$number+1; $number=sprintf("%03s",$number); $check_for=$contruct."-".$number; } echo $checking; echo $check_for; } Hello. i have created a template in dreamweaver, however when i added php code to a page the position of my bottom div got messed up... it works 100% with just text. I have a container div with other divs in it. inside the container div i have a div named content, and this div is the only div which is editable. in the bottom (outside of the container div) i have a bottom div which is centered with margin:0 auto; this divs position gets totally messed up once i add php code in the content div. http://elevweb.skit.no/0111nema/action_adventure.php here is the link to the page with php with it, as u can see the div with facebook etc in it got a messed up position. Hi, I have a question. Currently, when I retrieve the records in my zone 'North', there is no misalignment. However when I tried to copy the same coding to make up zone 'West', the alignment went off? May I know what is the reason? Any advice to align it properly. Attached is the picture of my example <div id ="location"> <input name="zone[]" type="checkbox" id="1" value="1"> <label for="1">North</label><br /> <?php $dbc = mysqli_connect('localhost', 'aliendatabase', '1234567', 'aliendatabase') or die(mysqli_error()); $query = ("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC"); $sql = mysqli_query($dbc, $query) or die(mysqli_error()); echo'<table><tr>'; // Start your table outside the loop... and your first row $count = 0; // Start your counter while($data = mysqli_fetch_array($sql)) { /* Check to see whether or not this is a *new* row If it is, then end the previous and start the next and restart the counter. */ if ($count % 3 == 0) { echo "</tr><tr>"; $count = 0; } echo '<td><input name="district[]" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].'">'; echo '<label for="'.$data['district_id'].'">'.$data['district_name'].'</label></td>'; $count++; //Increment the count } echo '</tr></table><br />'; //Close your last row and your table, outside the loop ?> <input name="zone[]" type="checkbox" id="2" value="2"> <label for="2">West</label><br /> <?php $dbc = mysqli_connect('localhost', 'aliendatabase', '1234567', 'aliendatabase') or die(mysqli_error()); $query = ("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC"); $sql = mysqli_query($dbc, $query) or die(mysqli_error()); echo'<table><tr>'; // Start your table outside the loop... and your first row $count = 0; // Start your counter while($data = mysqli_fetch_array($sql)) { /* Check to see whether or not this is a *new* row If it is, then end the previous and start the next and restart the counter. */ if ($count % 3 == 0) { echo "</tr><tr>"; $count = 0; } echo '<td><input name="district[]" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].'">'; echo '<label for="'.$data['district_id'].'">'.$data['district_name'].'</label></td>'; $count++; //Increment the count } echo '</tr></table>'; //Close your last row and your table, outside the loop ?> </div> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=333293.0 hello, please can anyone help me out with the codes I want to pivot it Item ID Year Type Item Value 68 2012 Assets Cash 343.556 69 2012 Assets Treasury bills 343.556 70 2012 Assets Cash and Short Term funds 687.111 71 2012 Assets Collateral by Third Parties 343.556 72 2012 Assets Operating account with Central Banks 343.556 73 2012 Assets Cash reserves with Central Banks 343.556 74 2012 Assets Overnight placements 343.556 75 2012 Assets Eskrow with Central Banks 343.556 76 2012 Assets Banks within Nigeria 343.556 77 2012 Assets Banks outside Nigeria 343.556 78 2012 Assets Inter-bank placements 343.556 79 2012 Assets Provision for doubtful balances 343.556 80 2012 Assets Federal Government of Nigeria bonds 343.556 81 2012 Assets Due from banks 2748.44 82 2012 Assets Listed equity securities 343.556 83 2012 Assets Other liquid assets 343.556 84 2012 Assets Dealing securities 687.111 85 2012 Assets Overdrafts 343.556 86 2012 Assets Term loans 0 87 2012 Assets Mortgage loans 0 88 2012 Assets Commercial paper 0 89 2012 Assets Originated by the bank 343.556 90 2012 Assets Other 0 91 2012 Assets Loan loss provision 0 92 2012 Assets Loans and advances 0 93 2012 Assets Interest in suspence 0 94 2012 Assets Advances under finance lease 0 95 2012 Assets Other assets 0 96 2012 Assets Investment securities 0 97 2012 Assets Investment in subsidiary 0 98 2012 Assets Insurance assets 0 99 2012 Assets Other facilities 0 100 2012 Assets Goodwill 0 101 2012 Assets Defferes tax assets 0 102 2012 Assets Property and equipment 0 103 2012 Assets total Assets 4809.78 to Item 2012 2011 2010 2009 2008 2007 2006 ... Cash 0 0 0 0 0 0 0 Treasury bills 0 0 0 0 0 0 0 . . . I need to do pivot it and display using PHP as all possible ways to do the using Mysql was unsuccessful |