Search the Community
Showing results for tags 'errors'.
-
Hello,recently, the company needed an PHP script to capture error,i try to use “set_error_handler”,but it can’t capture fatal error,like redeclare a function,then I try to change a way that use “register_shutdown_function”,but I found it that also unable to capture above mentioned errors at the end of the script. my php version is 7.0.1
-
Hi All, I have touched upon exceptions earlier. However I am still not sure if I am handling them correctly. try { ... ... ... }catch(Exception $e){ if($prod === true) // In production mode { header("Location: exceptions/errors.php") exit(); } if($dev === true) // In development mode { echo $e->getMessage(); // & if needed log the errors / exceptions into a file. exit(); } } I would like to ask if using the function header() to load the errors.php page is a good and safe practice. Or is there a better way to load the errors.php. If I load the errors page as in the snippet, do I also have to log the errors myself in some files or is php going to do that in any case. Any improvements or suggestions are welcome. Thanks all ! P.S. Googling exceptions gives loads of information but seldom does it touch the issue of loading an errors page when an exception occurs.
- 19 replies
-
- exceptions
- errors
-
(and 1 more)
Tagged with:
-
[Linux] PHP Notice: Undefined variable: connection in /var/www/html/popreport/functions.php on line 23 PHP Fatal error: Call to a member function query() on a non-object in /var/www/html/popreport/functions.php on line 23 The fuction output in the following program is called from another file called records records-board.php If you look at the program below you'll see that I did define $connection above line 23 in the file functions.php And for the second error I'm really not getting it because that same foreach loop was working fine with the exact same argument list when it was in the file records-board.php, but now that I've copied most of the code from records-board.php and placed it in functions.php all the sudden my program can't see the variable $connection and has a problem with my foreach loop on line 23. Again, both of those lines worked fine when they were in another file. functions.php <?php //session_start(); // open a DB connectiong $dbn = 'mysql:dbname=popcount;host=127.0.0.1'; $user = 'user'; $password = 'password'; try { $connection = new PDO($dbn, $user, $password); } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $sql = "SELECT full_name, tdoc_number, race, facility FROM inmate_board WHERE type = 'COURT'"; function output() { foreach($connection->query($sql) as $row) { echo "<tr><td>$row[full_name]</td></tr>"; } } ?> records-board.php <? include 'functions.php'; php output(); ?> Any ideas?
-
Hi all ! Here is a small piece of code that I wrote to Select from a DB:- $query = "SELECT Id, User, Pass, FROM $table WHERE User = ?"; $stmt = $con->prepare($query); $stmt->bind_param('s',$user); $stmt->execute(); $stmt->bind_result($db_id,$db_user,$db_pw); $stmt->fetch(); ... Each of these statements warrant that they be checked for failure and for possible exceptions since each of these can fail. However such similar blocks of code may be present at 100's of places in a large application and so checking for failure after each line of code would be make it a very lengthy & cumbersome procedure. I was wondering if there is a simpler, elegant way to handle these kind of failures or exceptions. And that's what I wish to ask. Thanks loads everyone.
-
Hi I just finished this tutorial('http://www.startutorial.com/articles/view/php-crud-tutorial-part-3/) and everything was working fine until I decided to add last names to the application. I got everything working on all the other pages except the Update page. This is my php code. d = $_REQUEST['id']; } if ( null==$id ) { header("Location: index.php"); } if ( !empty($_POST)) { // keep track validation errors $nameError = null; $lastError = null; $emailError = null; $mobileError = null; // keep track post values $name = $_POST['name']; $last = $_POST['last']; $email = $_POST['email']; $mobile = $_POST['mobile']; // validate input $valid = true; if (empty($name)) { $nameError = 'Please enter Name'; $valid = false; } $valid = true; if (empty($last)) { $lastError = 'Please enter last name'; $valid = false; } if (empty($email)) { $emailError = 'Please enter Email Address'; $valid = false; } else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) { $emailError = 'Please enter a valid Email Address'; $valid = false; } if (empty($mobile)) { $mobileError = 'Please enter Mobile Number'; $valid = false; } // update data if ($valid) { $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "UPDATE customers set name = ?, last = ?, email = ?, mobile =? WHERE id = ?"; $q = $pdo->prepare($sql); $q->execute(array($name, $last,$email,$mobile,$id)); Database::disconnect(); header("Location: index.php"); } } else { $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM customers where id = ?"; $q = $pdo->prepare($sql); $q->execute(array($id)); $data = $q->fetch(PDO::FETCH_ASSOC); $name = $data['name']; $last = $data['last']; $email = $data['email']; $mobile = $data['mobile']; Database::disconnect(); } ?> When I hit Update it is directing me to a white screen instead of the index.php page.
-
I have purchased a ad manager type script and have put so much work in to the site but i cannot get the cron file to execute properly due to errors. The makers of the script arent answering my emails so I am left to find the answer myself im hoping some experts can shine a light on this for me I have the cron running once daily as required the error messages are as follows: /home2/net2you/public_html/2xx.co.uk/include/CronStats.php: line 1: ?php: No such file or directory /home2/net2you/public_html/2xx.co.uk/include/CronStats.php: line 2: syntax error near unexpected token `;' /home2/net2you/public_html/2xx.co.uk/include/CronStats.php: line 2: `ob_start();' I have installed the script on two different hosts and get the exact same errors. any help would be much appriciated the contents of the cron file are below ______________________________________________ <?php ob_start(); ini_set("max_execution_time", 0); error_reporting(0); require_once("db_connection.php"); // hits table fix $ws = mysql_query("select pid from publishersinfo"); while($row = mysql_fetch_assoc($ws)){ $max = mysql_fetch_assoc(mysql_query("SELECT count(distinct ip) as distinct_hits, count(ip) as hits, date from hits where pub_id='$row[pid]' group by date order by hits desc, distinct_hits desc limit 1")); mysql_query("update publishersinfo set hits = '$max[hits]', distinct_hits = '$max[distinct_hits]' where pid = '$row[pid]' "); $country_clicks = mysql_query("select count(country) as clicks, country from hits where is_click = 1 and pub_id = '$row[pid]' GROUP BY country order by clicks desc"); mysql_query("delete from country_clicks where pid = '$row[pid]' "); while($rc = mysql_fetch_assoc($country_clicks)){ mysql_query("insert into country_clicks set clicks = '$rc[clicks]' , country = '$rc[country]', pid = '$row[pid]', updated = CURDATE() "); } } mysql_free_result($ws); // adv info $advertisement_ids = mysql_query("select adv_id from advertisersinfo"); while($ro = mysql_fetch_assoc($advertisement_ids)){ $clicksToday = mysql_result(mysql_query("select count(hit_id) from hits where adv_id = '$ro[adv_id]' and is_click='1' and is_sale='0' and `date` = CURDATE()"),0,0); $impressionsToday = mysql_result(mysql_query("select count(hit_id) from hits where adv_id = '$ro[adv_id]' and is_click='0' and is_sale='0' and `date` = CURDATE()"),0,0); $conversionsToday = mysql_result(mysql_query("select count(hit_id) from hits where adv_id = '$ro[adv_id]' and is_sale='1' and `date` = CURDATE()"),0,0); mysql_query("update advertisersinfo set clicksToday = $clicksToday, clicksTotal = (clicksTotal + $clicksToday), impressionsToday = $impressionsToday, impressionsTotal = (impressionsTotal + $impressionsToday), conversionsTotal = (conversionsTotal + $conversionsToday) where adv_id = '$ro[adv_id]' "); } mysql_free_result($advertisement_ids); // targeted_ads $cmp_ids = mysql_query("select cmp_id from adv_campaign"); while($ro = mysql_fetch_assoc($cmp_ids)){ $clicksToday = mysql_result(mysql_query("select count(hit_id) from hits where cmp_id = '$ro[cmp_id]' and is_click='1' and `date` = CURDATE()"),0,0); mysql_query("update adv_campaign set clicksToday = $clicksToday, clicksTotal = (clicksTotal + $clicksToday), remaining_budget = (remaining_budget - expense_today) where cmp_id = '$ro[cmp_id]' "); //camp_appeared $camp_appeared = mysql_query("select distinct publishersinfo.url, publishersinfo.pid from publishersinfo, hits where hits.cmp_id= '$ro[cmp_id]' and hits.pub_id=publishersinfo.pid order by hits.hit_id, hits.pub_id"); mysql_query("delete from camp_appeared where cmp_id= '$ro[cmp_id]' "); while($cmp = mysql_fetch_assoc($camp_appeared)){ mysql_query(" insert into camp_appeared set url = '$cmp', pid = '$cmp[pid]', cmp_id = '$ro[cmp_id]', updated = curdate() "); } } mysql_free_result($cmp_ids); /* $as = mysql_query("select ad_id from publishers_adspaces"); while($row = @mysql_fetch_assoc($as)){ $max_one_day_clicks = mysql_result(mysql_query("SELECT count(hit_id) as total from hits where is_click=1 and ad_id='$row[ad_id]' group by date order by total desc limit 1"),0,0); mysql_query("update publishers_adspaces set hits = $max_one_day_clicks "); } mysql_free_result($as); */ $users = mysql_query(" select uid from users where utype = 'pub+adv' "); while($r = mysql_fetch_assoc($users)){ $price = mysql_result(mysql_query("select sum(h.click_price) as price from publishersinfo pi inner join hits h on pi.pid = h.pub_id where pi.uid = '$r[uid]' and h.cmp_id <> 0 and h.date=curdate() and h.is_click=1 "),0,0); mysql_query("delete from pub_earningstoday where uid = '$r[uid]' "); mysql_query("insert into pub_earningstoday set updated = CURDATE(), uid = '$r[uid]', price = '$price' "); } ?>
-
I make my share of programming design blunders, as many of you know from helping me debug a few, so I am hesitant to point fingers, but I just had an experience so horrible, with so many errors on a website owned by Snapfish (which should have some programming resources) that I had to write it up.
-
- user interface
- errors
-
(and 1 more)
Tagged with:
-
Ok so I have been working on a simple Bean. My code is: <?php if(!empty($_SESSION['identification'])){ $id = $_SESSION['identification']; $sql = 'SELECT * FROM `accounts` WHERE `id` = $id'; $rows = R::getAll($sql); $accounts = R::convertToBeans('accounts',$rows); if (!isset($accounts->id)) { die("<font color='white'>Bean Cannot be Found!</font>"); } else{ ?> <li><font color="white"><a href="/account">Welcome <?php echo $accounts->username;?></a></font></li> <li><a href="signout.php">Sign out -></a></li> <?php } }?> It dies out the Beans cannot be found. It should have the rows converted to beans however It does not. Any help would be Great. Thank you, The Red Head.
-
Dear Professional PHP Coders, I really need your help here. I am designing a form for registration (Please find the codes below). There are two errors I want corrected on this form. 1. PostBack data on controls. If a user submits a form, and there are errors on the submitted data, php should postback the user's submitted data on the controls. Instead of clearing them (i.e., setting the value to empty). 2. Display an array of all errors during form submission. Here, if a user has failed to provide necessary data on a selected controls, php should create an array of all controls wherein there are incorrect data, and php should echo the array of such incorrect errors below the form. (pls find the code below). I have tried something, but php is not echoing the assumed errors. No reporting at all. Please kindly help me. <?php //Connect to the database through our include include_once "/dat/connString_local.php"; //include the php file that checks whether a user is logged in or not include_once("toplinks_for_join_form.php"); //load the captcha code from the database $sql = mysql_query("SELECT id, captchacode, status FROM captcha"); while ($result = mysql_fetch_array($sql)) { $id = $result['id']; $captchacode_from_dbase = $result['captchacode']; } // echo $captchacode_from_dbase; // Set error message as blank upon arrival to page $errorMsg = array(); // First we check to see if the form has been submitted if (isset($_POST['username'])){ // Filter the posted variables // GET USER IP ADDRESS AND LOCATION DATA $ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR')); $address1 = str_replace("[^A-Z a-z0-9]", "", $_POST['address1']); $address2 = str_replace("[^A-Z a-z0-9]", "", $_POST['address2']); $address = $address1 .", ". $address2 ." "; //CONCATENATE ADDRESS FIELDS INTO ONE VARIABLE $country = str_replace("[^A-Z a-z0-9]", "", $_POST['country']); // filter everything but spaces, numbers, and letters $state = str_replace("[^A-Z a-z0-9]", "", $_POST['state']); // filter everything but spaces, numbers, and letters $city = str_replace("[^A-Z a-z0-9]", "", $_POST['city']); // filter everything but spaces, numbers, and letters $address .=$city. ", " .$state. ", " .$country; //account info if($_POST['accounttype']=="atm"){ $accounttype = "ATM";}else {$accounttype = "eCurrency";} //$accounttype = str_replace("[^a-z]", "", $_POST['accounttype']); // filter everything but lowercase letters $user_captcha = str_replace("[^0-9]", "", $_POST['captchacode']);//filter everything except numbers only //login data $username = str_replace("[^A-Za-z0-9]", "", $_POST['username']); // filter everything but numbers and letters $email = stripslashes($_POST['email']); $email = strip_tags($email); $email = mysql_real_escape_string($email); $password = str_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters $password2 = str_replace("[^A-Za-z0-9]", "", $_POST['password2']); // filter everything but numbers and letters //bio data $fullname = str_replace("[^A-Za-z]", "", $_POST['fullname']); // filter everything but upper and lowercase letters //find the gender if(($_POST['gender'])=="male"){ $gender = "m";} else {$gender = "f"; } //concatenate the date of birth fields $day = str_replace("[^0-9]", "", $_POST['day']);//filter everything except numbers only $month = str_replace("[^0-9]", "", $_POST['month']);//filter everything except numbers only $year = str_replace("[^0-9]", "", $_POST['year']);//filter everything except numbers only $dob = $year."/".$month."/".$day; //mysql accepts date string starting from year, month then day. $bio = str_replace("[^A-Z a-z0-9]", "", $_POST['bio']); // Check to see if the user filled all fields with // the "Required"(*) symbol next to them in the join form // and print out to them what they have forgotten to put in if(isset($_POST['btn_register'])){ if(!$fullname){$errorMsg[] .= "---Full Name must be characters only and not spaces.<br />";}//die($errorMsg.); else if(!isset($_POST['gender'])){$errorMsg = "---Please select gender.<br />";}//die($errorMsg.= else if(!$day){$errorMsg[] .= "---You must enter your valid date of birth.<br />";}//die($errorMsg. else if(!$month){$errorMsg[] .= "---You must enter your valid date of birth.<br />";}//die($errorMsg.= else if(!$year){$errorMsg[] .= "---You must enter your valid date of birth.<br />";}//die($errorMsg.= else if(!$bio){$errorMsg[] .= "---Please tell us about yourself.";}//die($errorMsg.= else if(strlen($bio) < 100){$errorMsg[] = "---Please tell us about yourself. Minimum of 100 xters.<br />";}//die( else if(!$address1){$errorMsg[] .= "---Address is compulsory please.<br />";}//die($errorMsg.= else if(!$city){$errorMsg[] .= "---Please enter your city location.<br />";}//die($errorMsg.= else if(!$state){$errorMsg[] .= "---Please enter or select a state where you come from.<br />";}//die($errorMsg.= else if(!$country){$errorMsg[] .= "---Please select your country from the list.<br />";}//die($errorMsg.= else if(!$email){$errorMsg[] .= "---You must enter a valid email address.<br />";}//die($errorMsg.= else if(!$username){$errorMsg[] .= "---Your username is required please.<br />";}//die($errorMsg.= else if(!$password){$errorMsg[] .= "---Password is required.<br />";}//die($errorMsg.= else if(strlen($password) < {$errorMsg[] = "---Invalid password. Min of 8 characters are required, max is 20.<br />";}//die( else if(!$password2){$errorMsg[] .= "---Please repeat password.<br />";}//die($errorMsg.= else if($user_captcha!=$captchacode_from_dbase){$errorMsg[] .= "---Please enter the correct CAPTCHA code.<br />";}//die($errorMsg.= else if(!$accounttype){$errorMsg[] .= "---Please select account type or mode of transaction.<br />";}//die($errorMsg.= else if(!$ip){$errorMsg[] .= "---Your location cannot be determined. You will not be allowed to continue the registration.<br />";}//die( elseif($country=="Select your country"){$errorMsg[] .= "Invalid Country selection.<br />";} else if($accounttype=="Select account type"){$errorMsg[] .= "Invalid Account Type selection.<br />";} //die($errorMsg); else if($password!=$password2){$errorMsg[] .= "---Passwords did not match. Repeat correct passwords please.<br />";}//die( else if($month > 12){$errorMsg[] .= "---Invalid month in date of birth.<br />";}//die( else if($day > 31 || $day =="00"){$errorMsg[] .= "---Invalid day of birth.<br />";}//die( else if($year < 1960 || $year > 1995 ){$errorMsg[] .= "---You are not qualified for this registration.<br />";}//die( else { //update the captcha table with a new generated captcha code // this file regenerates the captcha code if it is less than 50. require("update_captcha.php"); // Database duplicate Fields Check $sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1"); $sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1"); $username_check = mysql_num_rows($sql_username_check); $email_check = mysql_num_rows($sql_email_check); if($username_check > 0){ $errorMsg = "<u>ERROR:</u><br />Sorry, our system does not accept the username that you are using. Please try another."; die($errorMsg); } else if($email_check > 0){ $errorMsg = "<u>ERROR:</u><br />Sorry, our system does not accept the email that you are using. Please try another."; die($errorMsg);} } }//close the blocked if(isset)else { // Add MD5 Hash to the password variable $hashedPass = md5($password); // Add user info into the database table, claim your fields then values $sql = mysql_query("INSERT INTO members (fullname,gender,dob,bio,ip,username,address,country,state,city,accounttype,email, password, signup_date) VALUES('$fullname', '$gender','$dob','$bio','$ip','$username','$address','$country','$state','$city','$accounttype','$email','$hashedPass', now()) ") or die (mysql_error()); // Get the inserted ID here to use in the activation email $id = mysql_insert_id(); // Create a directory(folder) to hold each user files(pics, MP3s, etc.) mkdir("memberFiles/$id", 0755); //echo "Yes, " .$_POST['btn_register']. "<br />Username: ".$_POST['username']. "<br />Gender: ". $gender. "<br />Captcha: ". $user_captcha. //"<br />Account Type: ".$accounttype. "<br />Address: ".$address; //send the maill first before adding to the database //compose email function here $to = "$email"; $subject = "Complete your registration - Authentication Needed!"; //Begin HTML Email Message where you need to change the activation URL inside $message = '<html> <body bgcolor="#FFFFFF"> Hi ' . $fullname . ', <br /><br /> You have successfully created an account with us.<br /><br /> Your Login information is as follows: <br /><br /> Your E-mail Address: ' . $email . ' <br /> Your Password: ' . $password . ' <br /><br /> Your Account / Payment / Transaction information: '.$accounttype. '. <br /><br /> In order to be able to use your account, you must complete this step to activate your account by clicking on the Account Activation Link below. <br /><br /> Please click the link to activate now >> <a href="http://localhost/easytimecorporation.com/lotto/activation.php?id=' . $id . '"> ACTIVATE NOW</a><br /> Thanks! <br /><br /> Eyo Honesty, <br /> Easytime Corporation. </body> </html>'; // end of message //import the email settings file here. include_once('emailSettings.php'); //check whether the mail is sent or not if($mail->Send()) { //echo "Message has been sent"; // Then print a message to the browser for the joiner $message2 = '<br /> Hi ' . $fullname . ', <br /><br /> You have successfully created an account with us. A mail has been sent to you at ' .$email. '.<br /><br /> In order to be able to use your account, please check your email and click on the Account Activation Link to activate your account. <br /><br /> Thank you'; //echo $message2; //update the captcha table with a new generated captcha code // this file regenerates the captcha code if it is less than 50. require("update_captcha.php"); //redirect user to success.php $_SESSION['msg'] = $message2; //echo $_SESSION['msg']; //header("location: register_success.php?id=".$_SESSION['msg']); } else { //delete the user from database and delete the created user directory require("delete_user.php"); rmdir("memberFiles/$id");//removes a created directory. //update the captcha table with a new generated captcha code // this file regenerates the captcha code if it is less than 50. require("update_captcha.php"); die("Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo); exit(); } // Exit so the form and page does not display, just this success message }//close the $_POST[''] check line ?> <!DOCTYPE html> <HTML> <HEAD> <META CHARSET="UTF-8"> <LINK rel="icon" href="images/blueweb.ico" type="image/x-icon"> <LINK rel="stylesheet" href="style/style.css"> <TITLE>Users Registration Form.</TITLE> <STYLE type="text/css"> <!-- .style1 {color: #FF0000} .style3 {color: #FF0000; font-weight: bold; } --> </STYLE> </HEAD> <BODY> <?php include_once("template_pageTop.php");?> <DIV id="pageMiddle"> <FORM name="joinForm" id="joinForm" action="join_form.php" method="post" enctype="multipart/form-data"> <DIV align="center"> <H1>Users Registration Form</H1> <HR style="width:80%; outline-style:groove; outline-color:#CCCCCC;"> <DIV align="justify"> <LEGEND style="margin-left:20px; "><STRONG><u>Basic Data</u></STRONG> Please all starred <SPAN class="style1">*</SPAN> fields in red colour are required.</LEGEND> <BR /> <TABLE width="800" border="0" align="center" cellpadding="2" cellspacing="5" style="border-radius:10px; background-color:#006699; color:#FFFFFF;"> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> Full Name:</STRONG></TD> <TD width="520" align="left" valign="middle"><INPUT type="text" name="fullname" value="<?php if (isset($_POST['fullname'])) {echo "$fullname";} ?>" size="80" maxlength="40"></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> Gender:</STRONG></TD> <TD width="520" align="left" valign="middle"> <LABEL> <INPUT type="radio" name="gender" value="male"> Male</LABEL> <INPUT type="radio" name="gender" value="female"> Female</LABEL></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> Date of Birth:</STRONG></TD> <TD width="520" align="left" valign="middle"> Day <INPUT type="text" name="day" value="<?php if (isset($_POST['day'])) {echo "$day";} ?>" size="5" maxlength="2"> Month <INPUT type="text" name="month" value="<?php if (isset($_POST['month'])) {echo "$month";} ?>" size="5" maxlength="2"> Year <INPUT type="text" name="year" value="<?php if (isset($_POST['year'])) {echo "$year";} ?>" size="10" maxlength="4"> format --> DD / MM / YYYY </TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><STRONG><SPAN class="style1">*</SPAN> Tell us about yourself: </STRONG><EM>(min = 100 characters).</EM> </TD> <TD width="520" align="left" valign="middle"><TEXTAREA name="bio" cols="50" rows="4"><?php if (isset($_POST['bio'])) {echo "$bio";} ?></TEXTAREA></TD> </TR> </TABLE> </DIV> <HR style="width:80%; outline-style:groove; outline-color:#CCCCCC;"> <DIV align="justify"> <LEGEND style="margin-left:20px; "><STRONG><u>Location Data</u></STRONG> Please all starred <SPAN class="style1">*</SPAN> fields in red colour are required.<BR> </STRONG></u></LEGEND><BR /> <TABLE width="800" border="0" align="center" cellpadding="2" cellspacing="5" style="border-radius:10px; background-color:#006699; color:#FFFFFF;"> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> Address 1 :</STRONG></TD> <TD><INPUT name="address1" type="text" size="80" maxlength="70" value="<?php if (isset($_POST['address1'])) {echo "$address1";} ?>" /></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><STRONG>Address 2 (<EM>optional</EM>) :</STRONG></TD> <TD><INPUT name="address2" type="text" size="80" maxlength="70" value="<?php if (isset($_POST['address2'])) {echo "$address2";} ?>" /></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> City:</STRONG></TD> <TD><INPUT name="city" type="text" size="50" maxlength="30" value="<?php if (isset($_POST['city'])) {echo "$city";} ?>" /></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> State:</STRONG></TD> <TD><INPUT name="state" type="text" size="50" maxlength="25" value="<?php if (isset($_POST['state'])) {echo "$state";} ?>" /></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> Country :</STRONG></TD> <TD><SELECT name="country"> <OPTION value="Select your country" selected="selected">Select your country</OPTION> <OPTION value="Australia">Australia</OPTION> <OPTION value="Canada">Canada</OPTION> <OPTION value="Mexico">Mexico</OPTION> <OPTION value="United Kingdom">United Kingdom</OPTION> <OPTION value="United States">United States</OPTION> <OPTION value="Zimbabwe">Zimbabwe</OPTION> <OPTION value="Cameroon">Cameroon</OPTION> <OPTION value="Nigeria">Nigeria</OPTION> <OPTION value="South Africa">South Africa</OPTION> <OPTION value="Uganda">Uganda</OPTION> <OPTION value="Thailand">Thailand</OPTION> <OPTION value="Brazil">Brazil</OPTION> <OPTION value="China">China</OPTION> <OPTION value="Japan">Japan</OPTION> <OPTION value="Korea">Korea</OPTION> <OPTION value="DR Congo">DR Congo</OPTION> <OPTION value="Egypt">Egypt</OPTION> <OPTION value="Germany">Germany</OPTION> <OPTION value="Bene Republic">Bene Republic</OPTION> <OPTION value="Niger">Niger</OPTION> <OPTION value="Saudi Arabia">Saudi Arabia</OPTION> <OPTION value="Italy">Italy</OPTION> <OPTION value="France">France</OPTION> <OPTION value="India">India</OPTION> <OPTION value="Malaysia">Malaysia</OPTION> <OPTION value="Spain">Spain</OPTION> <OPTION value="Portugal">Portugal</OPTION> <OPTION value="Port De Spain">Port De Spain</OPTION> <OPTION value="Trinidad and Tobago">Trinidad and Tobago</OPTION> <OPTION value="Chile">Chile</OPTION> </SELECT></TD> </TR> </TABLE> </DIV> <HR style="width:80%; outline-style:groove; outline-color:#CCCCCC;"> <DIV align="justify"> <LEGEND style="margin-left:20px; "><U><STRONG>Login Information</STRONG></U> Please all starred <SPAN class="style1">*</SPAN> fields in red colour are required.</LEGEND> <BR /> <TABLE width="800" border="0" align="center" cellpadding="2" cellspacing="5" style="border-radius:10px; background-color:#006699; color:#FFFFFF;"> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> Username:</STRONG></TD> <TD><DIV align="left"> <INPUT name="username" type="text" size="50" maxlength="25" value="<?php if (isset($_POST['username'])) { echo "$username";} ?>" /> </DIV></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><P><SPAN class="style3">*</SPAN><STRONG> Password: </STRONG></P> <P><EM>(8 characters minimum, 20 max.) </EM></P></TD> <TD><DIV align="left"> <INPUT name="password" type="password" value="<?php if (isset($_POST['password'])) {echo "$password";} ?>" size="40" maxlength="20"> No spaces or special charactes. </DIV></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><P><SPAN class="style3">*</SPAN><STRONG> Repeat Password</STRONG></P> <P><EM>(8 characters minimum, 20 max.) </EM></P></TD> <TD><DIV align="left"> <INPUT name="password2" type="password" value="<?php if (isset($_POST['password2'])) {echo "$password2";} ?>" size="40" maxlength="25"> No spaces or special charactes. </DIV></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> E-mail Address</STRONG></TD> <TD><DIV align="left"> <INPUT name="email" type="text" value="<?php if (isset($_POST['email'])) {echo "$email";} ?>" size="80" maxlength="45" /> </DIV></TD> </TR> </TABLE> </DIV> <HR style="width:80%; outline-style:groove; outline-color:#CCCCCC;"> <DIV align="justify"> <LEGEND style="margin-left:20px; "><U><STRONG>Account / Payment Information</STRONG></U> Please all starred <SPAN class="style1">*</SPAN> fields in red colour are required.</LEGEND> <BR /> <TABLE width="800" border="0" align="center" cellpadding="2" cellspacing="5" style="border-radius:10px; background-color:#006699; color:#FFFFFF;"> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> Account Type:</STRONG></TD> <TD><SELECT name="accounttype" size="3"> <OPTION value="Select account type">Select Account Type</OPTION> <OPTION value="atm">ATM</OPTION> <OPTION value="ecurrency" selected>e-Currency</OPTION> </SELECT></TD> </TR> <TR> <TD align="right" valign="middle" style="width:260px; height:40px; padding:15px;"><SPAN class="style3">*</SPAN><STRONG> CAPTCHA:</STRONG></TD> <TD> <INPUT name="captchacode" type="text" value="<?php if (isset($_POST['captchacode'])) {echo "$user_captcha";}?>" maxlength="12"> <?php echo "<font style ='color:#ffff00; font-size:20px; font-weight:bolder; font:Broadway;'> $captchacode_from_dbase</FONT> <font style='color:#ffffff;'-->Enter the code shown.</FONT>";?> </TD> </TR> </TABLE> </DIV> <HR style="width:80%; outline-style:groove; outline-color:#CCCCCC;"> <DIV align="left" style="margin-left:0px;"> <DIV align="center"> <INPUT name="btn_register" type="submit" value="R E G I S T E R"> <INPUT name="reset" type="reset" value="R E S E T" style="font:Georgia, 'Times New Roman', Times, serif; font-size:14px;"> <BR /><BR /> </DIV> </DIV> <?php if (empty($errorMsg)=== false) { echo '<ul>'; foreach($errorMsg as $error) { echo '<li>', $error, '</li>'; } echo '</ul>'; } ?> </FORM> </DIV> <?php include_once("template_pageBottom.php");?> </BODY> </HTML> join_form.php
-
ive got 3 errors which i have no clue what the problems are all 3 of them are related to near enough the same thing 1 of them is CompanyNameerr variable and the other to is CompanyName its confusing the hell out of me cause im pretty sure ive declared these variable. ( ! ) Notice: Undefined index: CompanyName in C:\wamp\www\AddLeads\addleads2.php on line 37 ( ! ) Notice: Undefined variable: CompanyNameErr in C:\wamp\www\AddLeads\addleads2.php on line 45 ( ! ) Notice: Undefined variable: CompanyName in C:\wamp\www\AddLeads\addleads2.php on line 68 and heres the code i used <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <? $con = mysqli_connect("localhost","root","","nib"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"INSERT INTO tbl_club_contacts (CompanyName, FirstName, Address1, Address2, Area, City); VALUES ('nelsons', 'luke', '', 'IT', '5 HIGHFIELD ROAD', 'LITTLEOVER', 'DERBY')"); mysqli_close($con); // define variables and set to empty values $companynameErr = $FirstNameErr = $Address1Err = $Address2Err = $AreaErr = $CityErr = ""; $companyname = $FirstName = $Address1 = $Address2 = $Area = $City = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") $allValid = true; { $allValid = false; } if($allValid) { // connect to db, create query, execute query } if($_POST['CompanyName']==null || $_POST['CompanyName']=="") { $allValid = false; } ?> <form action="insertaddleads.php" method="post"> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> CompanyName: <input type="text" name="companyname"> <span class="error">* <?php echo $CompanyNameErr;?></span> <br><br> FirstName: <input type="text" name="firstname"> <span class="error">* <?php echo $FirstNameErr;?></span> <br><br> Address 1: <input type="text" name="address1"> <span class="error">* <?php echo $Address1Err;?></span> <br><br> Address 2: <input type="text" name="address2"> <span class="error">* <?php echo $Address2Err;?></span> <br><br> Area: <input type="text" name="area"> <span class="error">* <?php echo $AreaErr;?></span> <br><br> City: <input type="text" name="city"> <span class="error">* <?php echo $CityErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> </form> <? echo $CompanyName; echo "<br>"; echo $FirstName; echo "<br>"; echo $Address1; echo "<br>"; echo $Address2; echo "<br>"; echo $Area; echo "<br>"; echo $City; echo "<br>"; ?> <?php foreach($_POST as $fieldName=>$fieldValue) { if($fieldValue == '') { print "<div>$fieldName is blank</div>"; } } ?> </body> </html>
-
I have created a main class where all my main member activation deactivation functions are and all the other things related to them are also done this main class(along with some main functions) is called from various places including through curl Now lets take my activaton function(One of the main functions) in the class activationFunction($data) { //use data to generate total, discount etc $this->giveAffiliates($total); if($this->_error){ return $this->_error;} $this->activateOrder($total,$discount,id); if($this->_error){ return $this->_error;} $this->activatePlan($total,$discount,id); if($this->_error){ return $this->_error;} //similarily calling various functions which themselves call other functions } activatePlan() { try{ //call other functions and do necessary stuff for plan A } catch(Exception $e) { $this->_error.="Error occurred while activating plan A"; } //for plan B try{ //call other functions and do necessary stuff for plan B } catch(Exception $e) { $this->_error.="Error occurred while activating plan B"; } //for other plans similarily } } Now the issue is having if($this->_error){ return $this->_error;} after each sub function call.(Total I am having around 35 such similar lines) I require this as I need to send the error to the user and stop my code from running further. But it is making my code long and not efficient. How can I reduce all these returns but show the user an error when one of the sub functions fails and try to keep my code structure as is. I have to call the various subfunctions from each main function(This I cannot change, there will be only one class and various functions in it) and the errors will mostly have to be caught at each level and returned(very few simple errors are not returned and the code is allowed to continue running) . I have to also keep in mind that there can be various other functions be added to it later and it should be flexible enough to handle all that later
-
I have a contact form that uses send-mail.php. I got it to work on one site and literally copied it to another site but it doesn't work. The error shows and the success message shows and it certainly doesn't send emails. ----------------------------------------------------------------- PHP Code ----------------------------------------------------------------- <?php //vars $subject = $_POST['subject']; $to = explode(',', $_POST['to'] ); $from = $_POST['email']; //data $msg = "NAME: " .$_POST['name'] ."<br>\n"; $msg .= "EMAIL: " .$_POST['email'] ."<br>\n"; $msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n"; //Headers $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=UTF-8\r\n"; $headers .= "From: <".$from. ">" ; //send for each mail foreach($to as $mail){ mail($mail, $subject, $msg, $headers); } ?> ----------------------------------------------------------------- Form Code ----------------------------------------------------------------- <!-- form --> <script type="text/javascript" src="_/js/form-validation.js"></script> <form id="contactForm" action="#" method="post"> <fieldset> <p><input name="name" id="name" type="text" class="text" placeholder="Full Name" title="Enter your full name" /></p> <p><input name="email" id="email" type="text" class="text" placeholder="Email Address" title="Enter your email address" /></p> <p><textarea name="comments" id="comments" rows="5" cols="38" placeholder="Message" title="Enter your comments"></textarea></p> <!-- send mail configuration --> <input type="hidden" value="joshua.ward@me.com" name="to" id="to" /> <input type="hidden" value="Sioux Signs Inquiry" name="subject" id="subject" /> <input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" /> <!-- ENDS send mail configuration --> <p><input type="button" value="Submit" name="submit" id="submit" class="submit" /> <span id="error" class="warning">Something went wrong. Please refresh your page and try again.</span></p> </fieldset> </form> <p id="sent-form-msg" class="success">Your message has been sent. We'll be in touch soon.</p> </div> <!-- ENDS form --> ----------------------------------------------------------------- This same form works on another site. I'm not sure why. Any suggestions?
-
View is not displaying error messages.Validation done at model level My view is add.ctp <?php echo $this->Session->Flash(); foreach($this->form->validationerrors as $errors) { echo $errors['Publishers']; } if(isset($updates)) { $id=$updates['Agreement']['id']; $pubname=$updates['Agreement']['publisherid']; } echo $this->Form->create('Agreement', array('action' => 'add', 'type' => 'file')); //echo $this->Form->file('File'); echo "<table><tr><td>Publisher Name</td><td>".$this->Form->input('Publishers',array('label'=>false,'default'=>@$pubname))."</td></tr>"; echo "<tr><td>Agreement File</td><td>".$this->Form->file('File',array('label'=>false))."</td></tr>"; echo "<tr><td colspan='2'>".$this->Form->input('id',array('label'=>false,'default'=>@$id,'type'=>'hidden'))."</td></tr>"; echo "<tr><td colspan='2'>".$this->Form->submit('Upload',array('label'=>false,'after' => $this->Html->link('Cancel', array('action' => 'view'))))."</td></tr></table>"; echo $this->Form->end(); ?> Model is <?php //License Agreements //Created By Dharmender On 8-2-2013 class Agreement extends AppModel { var $name = 'Agreement'; var $validate=array( 'Publishers' => array( 'rule' => 'notEmpty', 'message' => 'Please enter publisher name.' )); } ?> Controller is <?php class AgreementsController extends AppController { var $name = 'Agreements'; var $components = array('Session'); function add($id=null) { if($id!=null) { $updates=$this->Agreement->findById($id); $this->set('updates',$updates); } if(@$this->request->data['Agreement']['id']==NULL) { $this->Agreement->create(); if (!empty($this->request->data) && is_uploaded_file($this->request->data['Agreement']['File']['tmp_name'])) { $fileData = fread(fopen($this->request->data['Agreement']['File']['tmp_name'], "r"), $this->request->data['Agreement']['File']['size']); $this->request->data['Agreement']['name'] = $this->request->data['Agreement']['File']['name']; $this->request->data['Agreement']['type'] = $this->request->data['Agreement']['File']['type']; $this->request->data['Agreement']['size'] = $this->request->data['Agreement']['File']['size']; $this->request->data['Agreement']['data'] = $fileData; if($this->request->data['Agreement']['Publishers']=='ram') { $id2=1; } else { $id2=2; } $this->request->data['Agreement']['publisherid']=$id2; $this->request->data['Agreement']['createdon'] = date ('Y-m-d H:i:s'); if($this->Agreement->save($this->data)) { $this->Session->setFlash('File Uploaded Successfully!'); $this->Redirect('view'); } else { $this->Session->setFlash('Error in File Uploading!'); } } } else { $this->Agreement->id=$this->request->data['Agreement']['id']; if (!empty($this->request->data) && is_uploaded_file($this->request->data['Agreement']['File']['tmp_name'])) { $fileData = fread(fopen($this->request->data['Agreement']['File']['tmp_name'], "r"), $this->request->data['Agreement']['File']['size']); $this->request->data['Agreement']['name'] = $this->request->data['Agreement']['File']['name']; $this->request->data['Agreement']['type'] = $this->request->data['Agreement']['File']['type']; $this->request->data['Agreement']['size'] = $this->request->data['Agreement']['File']['size']; $this->request->data['Agreement']['data'] = $fileData; if($this->request->data['Agreement']['Publishers']=='ram') { $id2=1; } else { $id2=2; } $this->request->data['Agreement']['publisherid']=$id2; $this->request->data['Agreement']['createdon'] = date ('Y-m-d H:i:s'); if($this->Agreement->save($this->data)) { $this->Session->setFlash('Record Updated Successfully!'); $this->Redirect('view'); } else { $this->Session->setFlash('Error in File Updating!'); } } } }
-
I keep getting error: PHP Error Message Warning: mysql_query() [function.mysql-query]: Access denied for user 'a6743732'@'localhost' (using password: NO) in /home/a6743732/public_html/chat.php on line 25 PHP Error Message Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a6743732/public_html/chat.php on line 25 Access denied for user 'a6743732'@'localhost' (using password: NO) <?php session_start(); //CREDITS TO MODERNSONIC FROM 3DSPLAZA-3DSPAINT-SOMELUIGI.COM-3DSMEGUSTA-DSISTARZ for this chat script! //CREDITS TO MARIOERMANDO FOR THE TABLE CREATOR //CREDITS TO JUNAID FOR THE AUTO REFRESH...THAT WILL ONLY WORKS IF YOU SEPARATE THE MESSAGE FILE. ?> <? //AUTO TABLE CREATOR BY MARIOERMANDO //http://3DSFun.heliohost.org/ //http://marioermando.tumblr.com $sql = "CREATE TABLE chat( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), user TEXT(30), message TEXT(40))"; $result = mysql_query($sql) or die(mysql_error()); ?> <script type='text/javascript'> function updateChat() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET",".php?error=",true); xmlhttp.send(); } </script> <body onload="setInterval('updateChat()',2000);"> <div id="chat" style="witdth:320px height:200px; overflow:auto;"> <?php $user = $_SESSION['username']; //database infos $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb","***********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a6743732_pokeb", $con); if ($_POST['submit']) { $_POST['message'] = mysql_real_escape_string(htmlentities($_POST['message'])); $sql = "INSERT INTO chat (user, message) VALUES ('$user', '$_POST[message]')"; $result = mysql_query($sql) or die(); } session_start(); if (!empty($_SESSION['username'])) // he got it. { echo ""; } else // bad info. { header('Location: connexion.php'); } //db connect $user = $_SESSION['username']; $con = mysql_connect("mysql10.000webhost.com","a6743732_pokeb","***********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a6743732_pokeb", $con); //max messages $result = mysql_query("SELECT * FROM chat ORDER BY id DESC LIMIT 0, 15"); while($row = mysql_fetch_array($result)) { //smilies $smIn=array("R:"); $smOut=array("EPIC FACE URL"); $o_user = $row['user']; $message = $row['message']; $message = str_replace($smIn, $smOut, $message); echo '<u>'. $o_user . '</u>: '. $message . '</font>'. '</font>'. '</b>' ; echo "<br>"; } ?> </div> <style> #chat { background-color:green; width:320px; height:200px; overflow:auto; } </style> <form action="chat.php" method="POST"> <input type="text" name="message"><input type="submit" value="Chat" name="submit"> </form> <meta name="viewport" content="width=320"> <br> <a href="index.php"><img src="[url="http://png-2.findicons.com/files/icons/1572/minicons/48/refresh.png%22></a>refresh"]http://png-2.findico...ng"></a>refresh[/url] <br> Chat! </body>