PHP - Defining What Fields Have Actually Been Left Blank
Hello,
I'm using the below code to determine whether fields have been left blank, however, it only a standard sentence, i'd like to customise it, like: "Email has been left blank" or The email and message has been left blank. My best preference would be to bullet point each line. IE: Email has been left blank. Message has been left blank. $name = $_POST['name']; $visitor_email = $_POST['email']; $user_message = $_POST['message']; if(empty($name)|| empty($visitor_email)|| empty($user_message)) { $errors .= "\n Some of the above fields have not been filled in.<br><br> "; } Many thanks. Similar Tutorialshi, is there a way to do a check for blank fields before posting to database? dumb users keep adding blank fields. i need to check fields $_POST[company], $_POST[jobNO] and $_POST[staff]. Code: [Select] if(isset($_POST['add'])) { $cname=$_POST[company]; $compid = mysql_query("SELECT * FROM company WHERE company = '$cname'"); while($row4 = mysql_fetch_array($compid)) { $cid=$row4["ID"]; } $query = "INSERT INTO jobno VALUES ( NULL, '$_POST[jobNO]', '$cid' )"; mysql_query($query) or die('Error, insert failed'); $query1 = "INSERT INTO staff VALUES ( NULL, '$_POST[staff]', '$_POST[Y]-$_POST[M]-$_POST[D]', '$_POST[jobNO]' )"; mysql_query($query1) or die('Error, insert failed1'); echo "1 record added"; Hi. I've been doing tutorials all day on checking for blank fields and I have wrote a function to do so. For now I am only checking one field to see if it works. If I miss that field out (first name) It works great and displays the correct error message. Problem I have is if I fill in the whole form and send it I get an Inturnal server error. I will post my code to show you. can anyone see whats going wrong? I have \\ some of the code for now because I my keep it if I cant do this error check. session_start(); $validation_id = strval(time()); if(isset($_POST['submit'])) { $first_name = check_input($_POST['first_name'],"Please enter a first name"); $last_name = check_input($_POST['last_name']); $DOB = check_input($_POST['DOB']); $sex = check_input($_POST['sex']); $email = check_input($_POST['email']); $username = check_input($_POST['username']); $password = check_input($_POST['password']); $agree = check_input($_POST['agreed']); $creation_date = check_input($_POST['creation_date']); $user_type = check_input($_POST['member_type']); $access_level = check_input($_POST['access_level']); $validation = check_input($_POST['validation_id']); $club_user =check_input($_POST['user_type']); // $first_name = mysql_real_escape_string($_POST['first_name']); // $last_name = mysql_real_escape_string($_POST['last_name']); // $DOB = mysql_real_escape_string($_POST['DOB']); // $sex = mysql_real_escape_string($_POST['sex']); // $email = mysql_real_escape_string($_POST['email']); // $username = mysql_real_escape_string($_POST['username']); // $password = mysql_real_escape_string($_POST['password']); // $agree = mysql_real_escape_string($_POST['agreed']); // $creation_date = mysql_real_escape_string($_POST['creation_date']); // $user_type = mysql_real_escape_string($_POST['member_type']); // $access_level = mysql_real_escape_string($_POST['access_level']); // $validation = mysql_real_escape_string($_POST['validation_id']); // $club_user = mysql_real_escape_string($_POST['user_type']); $insert_member= "INSERT INTO Members (`first_name`,`last_name`,`DOB`,`sex`,`email`,`username`,`password`,`agree`,`creation_date`,`usertype`,`access_level`,`validationID`) VALUES ('".$first_name."','".$last_name."','".$DOB."','".$sex."','".$email."','".$username."','".$password."','".$agree."','".$creation_date."','".$user_type."','".$access_level."', '".$validation."')"; $insert_member_now= mysql_query($insert_member) or die(mysql_error()); $url = "thankyou.php?name=".$_POST['username']; header('Location: '.$url); and the form <form method="POST" name="member_accounts" id="member_accounts"> <input name="first_name" type="text" class="form_fields" value="<?php echo $_POST['first_name'];?>" size="20" /> <input name="last_name" type="text" class="form_fields" value="<?php echo $_POST['last_name'];?>" size="20" /> <input name="submit" type="submit" class="join_submit" id="submit_member" value="Create Account" /> <? function check_input($data, $problem='') { $data= trim($data); $data= stripslashes($data); $data= htmlspecialchars($data); if ($problem && strlen($data) ==0) { die($problem); } return $data; } ?> Good morning, I am a beginner at PHP, but trying to write a simple script to use at work and currently stuck on one part, looking for some advice! I have a simple form here > http://jmdostal.com/route2.php (Feel free to use it to test), that returns data on the next page, in a format such as : Jose F - Jose A - 285 Brenda L [Delivery] [Dallas] - Items Job 2 [Pickup] [Arlington] - Items [] [] - [] [] - [] [] - [] [] - [] [] - Gustavo - +1 - 284/pickup Jody W [Delivery] [Keller] - Items [] [] - [] [] - [] [] - [] [] - [] [] - [] [] - My question is how can I get it not to show the fields that are empty, so I dont have a bunch of lines with [] [] - formatting Here is my coding you can view here > http://jmdostal.com/code.txt A friend had suggested to me trying to use isset , so I tried it on a few lines, such as : if(isset($_POST['items14'])){ $items14 = "- ". Trim(stripslashes($_POST['items14'])); } But it didnt seem to change anything. Im sure this is something simply, Any suggestions are appreciated! Thanks ! I have a form with a gender control made up of two radio buttons. If the user doesn't fill out this form, nothing gets submitted (i.e name='gender') in the $_POST array. So how ae you supposed to verify that the form field was left blank, and use that information to say display an error message on the form? Edited February 16 by SaranacLakeAs expected when a die statement is triggered, my script is exited and ALL of the fields that have been filled in on my form are wiped clean. This however is proving to be annoying for users making mistakes. Is there a way to keep the data in the correctly filled in fields, and to just wipe or highlight the incorrectly filled in fields? Code: [Select] <?php function checkPostcode (&$toCheck) { $alpha1 = "[abcdefghijklmnoprstuwyz]"; $alpha2 = "[abcdefghklmnopqrstuvwxy]"; $alpha3 = "[abcdefghjkstuw]"; $alpha4 = "[abehmnprvwxy]"; $alpha5 = "[abdefghjlnpqrstuwxyz]"; $pcexp[0] = '^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$'; $pcexp[1] = '^('.$alpha1.'{1}[0-9]{1}'.$alpha3.'{1})([0-9]{1}'.$alpha5.'{2})$'; $pcexp[2] = '^('.$alpha1.'{1}'.$alpha2.'[0-9]{1}'.$alpha4.')([0-9]{1}'.$alpha5.'{2})$'; $pcexp[3] = '^(gir)(0aa)$'; $pcexp[4] = '^(bfpo)([0-9]{1,4})$'; $pcexp[5] = '^(bfpo)(c\/o[0-9]{1,3})$'; $Postcode = strtolower($toCheck); $Postcode = str_replace (' ', '', $Postcode); $valid = false; foreach ($pcexp as $regexp) { if (ereg($regexp,$Postcode, $matches)) { $toCheck = strtoupper ($matches[1] . ' ' . $matches [2]); $toCheck = ereg_replace ('C\/O', 'c/o ', $toCheck); $valid = true; break; } } if ($valid){return true;} else {return false;}; } if(isset($_POST['submit'])) { $drop = mysql_real_escape_string($_POST['drop_1']); $tier_two = mysql_real_escape_string($_POST['Subtype']); $Name = mysql_real_escape_string($_POST["Name"]); $Phone = mysql_real_escape_string($_POST["Phone"]); $Email = mysql_real_escape_string($_POST["Email"]); $Postcode = mysql_real_escape_string($_POST["Postcode"]); $Website = mysql_real_escape_string($_POST["Website"]); if($Name == '') { die ("<div class=\"form\">You did not complete the name field, please try again</div>"); } elseif ($Phone == '' or (preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Phone))) { die("<div class=\"form\"> You completed the telephone field incorrectly, please try again</div>"); } elseif ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL))) { die("<div class=\"form\"> You completed the Email field incorrectly, please try again</div>"); } elseif ($Postcode == '' or (!checkPostcode($Postcode))) { die("<div class=\"form\"> You did not complete the Postcode field correctly, please try again</div>"); } elseif ($Website == '' or (!preg_match("~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i", $Website))) { die("<div class=\"form\">You completed the website field incorrectly, please try again</div>"); } else { echo("<div id=\"formtwo\">Thankyou for submiting your details, you will be added to our directory shortly</div>"); } $query = ("INSERT INTO business (`id`, `Name`, `Type`, `Subtype`, `Phone`, `Email`, `Postcode`, `WebAddress`, `Confirmed`) VALUES ('NULL', '$Name', '$drop', '$tier_two' , '$Phone', '$Email', '$Postcode', '$Website', 'Yes')"); mysql_query($query) or die ( "<br>Query: $query<br>Error: " .mysql_error()); } ?> Hi all, I am trying to write a script that finds the blank $_POST values and add them to a $blank_array. All I get is a blank page - any ideas? Also is there some code I can put at the top of every php page to show exactly what the errors are? - I have tried a few scripts but have not found one to work universally. include("cxn.php"); $reg = "G-".strtoupper($_POST['reg']); $sql = "SELECT * FROM sales WHERE reg='$reg'"; $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query"); $num = mysqli_num_rows($result); if ($num >0) // Listing Already Found { echo "The aircraft '$reg' is already listed!"; echo $_SESSION['logname']; } foreach ($_POST as $value) { if ($value == "") { $blank_array[] = $field; } if (@sizeof($blank_array) > 0) // blank fields are found { $error = "Please fill in all the form.<br>"; include ("../sell-your-reg.php"); } } ?> Hi guys! New to the community and hope to learn a lot here! Here is some background info and what I want to do, and what I know. I have been building websites for years, and I am familiar with Actionscript 3.0. And I have successful ran a few wordpress websites. What I am trying to do right now however is modify this form script I found, to only email the data when the field isn't left blank. It's stumping me because the actual "message" that ends up being the body of the email is a variable. And form what I can tell I can't figure out how to put if statements into it. If anyone can take a look at this script and give me any pointers you would be awesome. Code: [Select] <?php //trying to store the date in a separate variable only when it's not blank if ($_POST['starttime'] == '') { //nothing; } else { $showStartTime == "Start time: " . $_POST['starttime'] . ""; } if ($_POST['finishtime'] == '') { //nothing; } else { $showFinishTime == "Finish time: " . $_POST['finishtime'] . ""; } // Read POST request params into global vars $to = $_POST['to']; $from = $_POST['from']; $name = $_POST['name']; $company = $_POST['company']; $newcustomer = $_POST['newcustomer']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $subject = ("Event Rental for " . $name . ""); $description = $_POST['description']; $phone = $_POST['phone']; $message = (" Name: " . $name . " Company or Organization: " . $company . " Phone Number: " . $phone . " Email Address: " . $from . " Street Address: " . $address1 . " " . $address2 . " New Customer: " . $newcustomer . " Customer From: " . $_POST['howyouheard'] . " Interested in: SkyLoft " . $_POST['whichspace'] . " Date: " . $_POST['date'] . " Day of Week: " . $_POST['dayofweek'] . " " . $showStartTime . " " . $showFinishTime . " Number of Guests: " . $_POST['Guests'] . " Format: " . $_POST['format'] . " Occasion: " . $_POST['Occasion'] . " Optional Needs: " . $_POST['dj'] . " " . $_POST['tables'] . " " . $_POST['chairs'] . " " . $_POST['eventbanner'] . " " . $_POST['pasoundsystem'] . " Message: " . $description . " "); // Obtain file upload vars $fileatt = $_FILES['fileatt']['tmp_name']; $fileatt_type = $_FILES['fileatt']['type']; $fileatt_name = $_FILES['fileatt']['name']; $headers = "From: $from"; if (is_uploaded_file($fileatt)) { // Read the file to be attached ('rb' = read binary) $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); // Generate a boundary string $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // Base64 encode the file data $data = chunk_split(base64_encode($data)); // Add file attachment to the message $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; } // Send the message $ok = @mail($to, $subject, $message, $headers); if ($ok) { echo "<p><b>Thank you for your interest in SkyLofts!</b> <br>You should recieve a verification in your inbox that we recieved your request. We will contact you as soon as possible and hopefully be able to answer any questions you may have! You can also contact us via phone 410-791-6699, or toll-free 1-800-344-0410.</p>"; } else { echo "<p>There was an error when processing your request. Please try again.</p>"; } ?> HI, I have a user form on a modal. The user can be updated from this modal but on the second tab is where the users password can be updated. The update button commits all changes including the password update. If the New Password field is blank i do not want it to be updated. I am using a prepared statement and am not sure how to ommit a field if it is blank. In actual fact there is a new password and a confirm password field which must be the same before the password field is updated. if ($_SERVER['REQUEST_METHOD']=='POST'){ $uid = $_POST['UM-uid']; $fname = $_POST['UM-firstName']; $lname = $_POST['UM-lastName']; $email = $_POST['UM-emailAddress']; $accountlevel = $_POST['UM-accountLevelId']; $mobile = $_POST['UM-mobileNumber']; $roleid = $_POST['UM-roleId']; $newpass = password_hash($_POST['UM-pass'], PASSWORD_DEFAULT); if(!empty($_POST['UM-firstName'])){ // prepare stmt $stmt = $conn->prepare(" UPDATE ssm_user SET user_password=?, user_email=?, user_firstname=?, user_lastname=?, user_account_level_id=?, user_mobile=?, user_role_id=? WHERE user_id = ? "); $stmt->bind_param('sssssssi', $newpass, $email, $fname, $lname, $accountlevel, $mobile, $roleid, $uid); $stmt->execute(); $_SESSION['user']=$fname." ".$lname; $_SESSION['updateUser']="has been successfully updated"; $_SESSION['actionstatus']="success"; I am sure i will be able to work out the password confirmation part, its just the omitting password from being part of the update if blank. ...added to an error log? Currently, my coding is as follows: Form to gather data: Code: [Select] <html><head><title>Car Accident Report Form</title></head> <form action="errorlog.php" method="post"> First Name: <br><input type="text" name="name"><br> Surname:<br> <input type="text" name="surname"><br> Age: <br><input type="text" name="age"><br> Weeks Since Accident: <br><input type="text" name="weeks"><br> <input type="submit" value="Submit"> </form> Coding for error log: Code: [Select] <html><head><title>Validating Car Accident Report Form Details</title></head> <?php $name=$_POST["name"]; $surname=$_POST["surname"]; $age=$_POST["age"]; $weeks=$_POST["weeks"]; $subtime = strftime('%c'); $pass = "The details uploaded are fine<br><br>"; if ((((trim($name)="" && trim($surname)="" && trim($age)="" && trim($weeks)="")))) { echo "It seems that you have not entered a value for the Name, Surname, Age or Weeks fields. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has not entered any values", 3, "C:/xampp/htdocs/errorlog.txt"); } if (($age<18)&& ($weeks<=1)) { echo "It seems that you have entered an invalid age and number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has entered an age that is below 18 and the number of weeks since the accident is equal to or under 1 week!<br>Age entered:" . $age . "<br>Number Of Weeks Since Accident entered:" . $weeks . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($age<18) { echo "It seems that you have entered an invalid age. This has been added to the error log.<br><br>"; error_log("<b><u>Age Error</b></u><br>The user has entered an age that is below 18!<br>Age entered:" . $age . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($weeks<=1) { echo "It seems that you have entered an invalid age number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Week Error</b></u><br>The user has entered a number of weeks since the accident that is equal to or under 1 week!<br>Number Of Weeks Since Accident entered:" . $weeks . "<br> Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else { echo $pass; } echo "Car Accident Report Form details have been sent<br>"; echo "<a href='readlog.php'>Read Error Log</a>" ?> </html> How can I get it so that if a user presses the space bar in a field, then the trim function sees that there's no white space and then this gets added to the error log? Any help is appreciated! Is there a recommended way to code in order to have a dual language support, especially when one is English (left to right), and the other is Hebrew (right to left)? Should I design every page twice or is there a ready made solution? Hey guys,
Thank you in advance... here is my situation, I have a form with three (3) fields in it, the 'student name' is unlimited textfield with an "add more" button to it and I have two select fields ('number of shirts' and 'trophies') that depend on the number of entries for 'student name'...
I want to create the select fields based on this math, for as many 'student name' entries:
1- i want to have the select form for 'number of shirts' to be 0 up to that number... so if there are 6 'student name' entries, the select options will be 0,1,3,4,5,6,7
2- I want to have the select form for 'trophies' to be 5 'student name' entries to 1 'trophies', for example if there are 6 'student name' entries, the select options will be 0,1... if there are 13 entries, options will be 0,1,2... So if there are less than 5 'student name' entries, the select field will not show (hidden)
of course if there are no 'student name' entries, these two fields won't show up (hidden)
let me know if that make sense and ANY help or directions will be GREATLY APPRECIATED.
Thanks guys!
Hi all I wonder if someone can help me, basically I have a HTML form with a free text area, which looks like Code: [Select] <textarea name="details"></textarea> when I submit the form, I can print what was outputted using $details = $_POST['details']; print $details; The user is able to either enter plain text, like Code: [Select] this is my website profile or they can enter some text and a URL, like Code: [Select] this is my website [http://www.google.com,2] profile My question is, when I do my print statement using print $details; how can I get it to convert what has been posted, so that it outputs the following HTML Code: [Select] this is <a href="http://www.google.com">my website</a> profile so basically it would create a link using what was entered between Code: [Select] [] and then use Code: [Select] ,2 to determine how many words before the URL should be linked, so in my example, just the words Code: [Select] my website would be linked, as I defined Code: [Select] ,2 following the URL in the code. But then further to this, if I entered 0, using Code: [Select] ,0 how can I then get it to link all the text, like Code: [Select] <a href="http://www.google.com">this is my website profile</a> i'm very new to PHP, so some guidance would be a great help Thanks very very much, been racking my brain on how to do this and have tried so many things, all with massive failure Hello Guys
I need help.
I found one PHP script for simple auto update of "system" (automatic updating of website for example)
http://maxmorgandesign.com/simple_php_auto_update_system/I want to adjust this script for my project, and In this code there is a line (on line 10): echo '<p>CURRENT VERSION: '.get_siteInfo('CMS-Version').'</p>';which variable should write in my page to define curent version of CMS? I try to googleit but unsuccessful :-/ Many thanks I need to define a query in a PHP script that will check a MySQL db - based on six variables (the six variables are statically defined within the script based on another snippet of code reading the new file that's being prepared for insertion into the db.) Objective: if the six variables, from the new records, does not produce an exact match already within the db based on ($rcheck) then insert the new record into the db. Note: I have the INSERT statement working correctly but having issues with the query ($rcheck). As for the records being checked by ($rcheck) in the MySQL db: they are all UNIQUE records based on the six fields I'm trying to build the query around to ensure no DUPLICATE entries are made with new insertions. ------------------- Issue: I can't get the query ($rcheck) to fire correctly to check the queued (new records' data) against the db - based on six fields of data. Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource. FYI: if I just do a standard "SELECT * FROM information"; the quey works as it should but I need to check the db based on the six fields as shown in below code: $rcheck = "SELECT docno,fdate,ftime,vegregno,direction,grossmass FROM information where docno = $docnoNew AND fdate = $fdateNew AND ftime = $ftimeNew AND vegregno = $vegregnoNew AND direction = $directionNew AND grossmass = $grossmassNew;"; $duplicate = mysql_query(rcheck); // Execute query to check for duplicate transaction in table while ($row = mysql_fetch_array($duplicate)) { echo $row['docno']."<br/>"; echo $row['fdate']."<br/>"; echo $row['ftime']."<br/>"; echo $row['vegregno']."<br/>"; echo $row['direction']."<br/>"; echo $row['grossmass']."<br/>"; } I know the problem rests with trying to use multiple "AND" clauses but I'm not sure how to get around this issue. Any advice on how to define this query to check based on all six fields surely appreciated to get ($rcheck) working! thanks I know that I have posted a similar question to this but I am still having some confusion that I hoped I could clear up. Thank you all for being patient with and helping me clean up this mess.
Below is the code that is spitting out the bottom error messages. So, I understand that the way to define a variable which uses += and not send it into a loop, generating a notice is this..
Using the top example
$meter_multiplier=0;
while ($row5 = sqlsrv_fetch_array($query5)){ meter_multiplier += $row5['meter_multiplier']; } versus... $meter_multiplier += $row5['meter_multiplier']; how can I implement this type of statment below. Should the php be called another name and reference sql that way, so the names are different? example $meter_multiplier=0; while ($row5 = sqlsrv_fetch_array($query5)){ meter_multiplier += $row5['meter_mult']; <?php $sql5 = "select meter_id, subaccount_number, service_name, service_address, service_address2, service_city, service_st, service_zip, service_contact, basic_charge, energy_charge, base_rate, intermediate_rate, peak_rate, meter_multiplier, raw_material_price FROM [radiogates].[dbo].[ops_invoice] where meter_id ='$comm_id' and subaccount_number='$session_id'";$query5 = sqlsrv_query($conn, $sql5);if ($query5 === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row5 = sqlsrv_fetch_array($query5)){ $meter_multiplier += $row5['meter_multiplier']; $raw_material_price += $row5['raw_material_price']; $basic_charge += $row5['basic_charge']; $peak_rate += $row5['peak_rate']; $intermediate_rate += $row5['intermediate_rate']; $energy_charge += $row5['energy_charge']; $base_rate += $row5['base_rate']; $account_number = $row5['meter_id']; $service_name = $row5['service_name']; $service_address = $row5['service_address']; $service_address2 = $row5['service_address2']; $service_city = $row5['service_city']; $service_st = $row5['service_st']; $service_zip = $row5['service_zip'];} sqlsrv_free_stmt($query5); ?>Notice: Undefined variable: meter_multiplier in C:\xampp1\htdocs\Utrack\invoice.php on line 335 Notice: Undefined variable: raw_material_price in C:\xampp1\htdocs\Utrack\invoice.php on line 335 Notice: Undefined variable: basic_charge in C:\xampp1\htdocs\Utrack\invoice.php on line 335 Notice: Undefined variable: peak_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335 Notice: Undefined variable: intermediate_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335 Notice: Undefined variable: energy_charge in C:\xampp1\htdocs\Utrack\invoice.php on line 335 Notice: Undefined variable: base_rate in C:\xampp1\htdocs\Utrack\invoice.php on line 335 Edited by Butterbean, 10 January 2015 - 06:34 PM. What the hell am i missing here?? Trying to set the $output so if there are any errors it will display a message. If no email or password is entered the $output is echoed fine But if the wrong email or password is entered the $ouptut is not echoed at all??? if (loggedin()){ header ("Location: index.php"); exit(); } if (isset ($_POST['login'])) { $email= $_POST['email']; $password= $_POST['password']; if (isset ($_POST['rememberme'])) {$rememberme= $_POST['rememberme'];} if (isset($rememberme)) {$rememberme= "on";} else {$rememberme= "off";} if (empty($email)) {$output= "<span class='error'>Please enter a username or password</span>";} if (empty($password)) {$output= "<span class='error'>Please enter a username or password</span>";} if ($email&&$password) { $login= mysql_query ("SELECT * FROM user WHERE email='$email'"); while ($row= mysql_fetch_assoc($login)) { $passwordcheck = $row['password']; if (md5($password)==$passwordcheck) $loginok = true; else $loginok = false; if ($loginok==true) { $uniquelogon = "{$row['uniqlogon1']}"; if ($rememberme=="on"){ setcookie("uniquelogon", $uniquelogon, time()+2628000);} else if ($rememberme=="off"){ session_start(); $_SESSION['uniquelogon'] = "$uniquelogon";} header ("Location: index.php"); exit(); } else echo "<span class='error'>Your Email or Password do not match our records</span>"; } } } <?php if (!empty($output)) {echo $output;} ?> <form action"login.php" method="POST"> <p>Email:<br> <input type="text" name="email"> </p> <p>Password:<br> <input id="pwd" type="password" class="required lock pad" watermark="{html:'Password',cls:'pad empty'}" name="password"> </p> <p> <input type="checkbox" name="rememberme"> Remember Me!<br> </p> <input type="submit" name="login" value="Log In"> </form> Ive used all my special powers trying to get this to work, but i am missing something... Can someone help me out, I had a guy make some great changes to a script. works perfectly - however I want to modify it further and he's unavailable till tomorrow to discuss. Hopefully someone will be able to guide me: define('TBL_PROFILE_COUNTRY_FILTER', '`country_id` = \'IE\''); This line is based on users in a database from Ireland (IE) but what I need to do is make it so that this TBL_PROFILE_COUNTRY_FILTER doesnt just filter Ireland members but also those from Northern Ireland (Ni) as well. So my question is this - can I (and if so how) - can I add Ni to this define statement. Grateful for any guidance (php isn't my thing at all but I'm trying to pick up what I need when I need it). Thanks again. // does the product exist ? $sql = "SELECT pd_id, pd_qty FROM tbl_product WHERE pd_id = $productId"; $result = dbQuery($sql); if (dbNumRows($result) != 1) { // the product doesn't exist header('Location: cart.php'); } else { // how many of this product we // have in stock $row = dbFetchAssoc($result); $currentStock = $row['pd_qty']; if ($currentStock == 0) { // we no longer have this product in stock // show the error message setError('The product you requested is no longer in stock'); header('Location: cart.php'); exit; } } // current session id $sid = session_id(); session_register("size"); $size = $_SESSION['size']; // check if the product is already // in cart table for this session $sql = "SELECT pd_id FROM tbl_cart WHERE pd_id = $productId AND ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { // put the product in cart table $sql = "INSERT INTO tbl_cart (pd_id, ct_qty, size, ct_session_id, ct_date) " . "VALUES ($productId, 1, '$size', '$sid', NOW())"; $result = dbQuery($sql); } else { // update product quantity in cart table $sql = "UPDATE tbl_cart SET ct_qty = ct_qty + 1 WHERE ct_session_id = '$sid' AND pd_id = $productId"; $result = dbQuery($sql); } This is just a piece of my cartfunctions.php (which is an include() once you add an item to the cart). I've been trouble shooting this all day and finally got it to stop giving me error messages. Im trying to allow the user to pick a size between 4 options, after that it is added to the cart and I can easily find out what size shirt the customer wants before I ship it. but now it wont update the $size variable to the DB. Am I defining this wrong or maybe my whole approach is messed up? If you would like to see the setup you can go to rbcrime.com/newshop/newshop/ . Hi, I my first problem is hashing passwords to md5. My second problem is defining session on value from db. There is my code but not working. Code: [Select] mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username=$_POST['username']; $password=$_POST['password']; $hash = md5($password); $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM $tbl_name WHERE where username = '$username' and password = '$hash'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $sql2="SELECT access FROM $tbl_name WHERE username='$username' and password='$password'"; $access=mysql_query("$sql2"); session_register("username"); session_register("password"); session_register("access"); $_SESSION["access"]=$access; header("location:success.php"); } else { echo "Invalid Username or Password";Thanks for any answers. I have a search code for my site and I want to narrow the scope of the search with a drop down that will allow users to pick a state, ( the sql table includes a state field ) or set the script so that i will only search for results for a particular state. In the sql select I have tried every way of using WHERE venue_state='NY' but it will not work. I would really rather allow the users to select a state from a dropdown and then enter the search term - city, zip or venue name. Thank you for looking Code: [Select] <?php include('config.db.php'); $find = trim($_GET['find']); $field = $_GET['field']; if($find && $field) { // we have search form submitted // check for values to prevent sql injection $valid_fields = array("venue_zip", "venue_city" , "show_name"); if(!in_array($field, $valid_fields)) die("Error: Invalid field!"); $rpp = 10; // results per page $adjacents = 4; $page = intval($_GET["page"]); if(!$page) $page = 1; $reload = $_SERVER['PHP_SELF'] . "?find=" . urlencode($find) . "&field=" . urlencode($field); echo "<h4>Search Results for $find</h4>\n"; $find = addslashes($find); $result = mysql_query("SELECT *, DATE_FORMAT(`start_date`, '%b %e, %Y') AS s_date FROM craft_shows WHERE $field LIKE '%$find%'"); if(mysql_num_rows($result) == 0) { echo "<p>0 matches found.</p>"; } else { echo "<table class='table7' cellpadding='2'>"; echo "<tr><td> </td><td><strong>Date</strong></td><td><strong>Show Name</strong></td><td><strong>City</strong></td><td><strong>Attendance</strong></td></tr>"; echo "<tr><td colspan='5'><hr class=\"hr2\"></td></tr>"; // count total number of appropriate listings: $tcount = mysql_num_rows($result); // count number of pages: $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; while(($count<$rpp) && ($i<$tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); $id = $row['id']; echo "<tr><td>"; echo "<a href=\"/show_submits/show_detail.php?id=$id\">Details</a>"; echo "</td><td>"; echo $row['s_date']; echo "</td><td>"; echo $row['show_name']; echo "</td><td>"; echo $row['venue_city']; echo "</td><td>"; echo $row['venue_state']; echo "</td></tr>"; echo "<tr><td colspan='5'><hr class=\"hr3\"></td></tr>"; $i++; $count++; } echo "</table><br>"; function paginate_one($reload, $page, $tpages) { $firstlabel = "First"; $prevlabel = "Prev"; $nextlabel = "Next"; $lastlabel = "Last"; $out = "<div class=\"pagin\">\n"; // first if($page>1) { $out.= "<a href=\"" . $reload . "\">" . $firstlabel . "</a>\n"; } else { $out.= "<span>" . $firstlabel . "</span>\n"; } // previous if($page==1) { $out.= "<span>" . $prevlabel . "</span>\n"; } elseif($page==2) { $out.= "<a href=\"" . $reload . "\">" . $prevlabel . "</a>\n"; } else { $out.= "<a href=\"" . $reload . "&page=" . ($page-1) . "\">" . $prevlabel . "</a>\n"; } // current $out.= "<span class=\"current\">Page " . $page . " of " . $tpages . "</span>\n"; // next if($page<$tpages) { $out.= "<a href=\"" . $reload . "&page=" .($page+1) . "\">" . $nextlabel . "</a>\n"; } else { $out.= "<span>" . $nextlabel . "</span>\n"; } // last if($page<$tpages) { $out.= "<a href=\"" . $reload . "&page=" . $tpages . "\">" . $lastlabel . "</a>\n"; } else { $out.= "<span>" . $lastlabel . "</span>\n"; } $out.= "</div>"; return $out; } echo paginate_one($reload, $page, $tpages, $adjacents); } } ?> |