PHP - Couple Field Validation Questions
Having trouble figuring this out.
1) How can I check whether the user's input for a field is an integer with a value greater than 0? Was thinking of using regular expressions using 1-9 but then 10 might result in an error and that's not wanted. 2) For a field that's a drop-down, how can I have an error show if they choose the default option (value of "none") Thanks for the help. Similar TutorialsOk, so I'm trying to develop/remake a web based browser game that I used to play back in 2006. I've got a fair amount set up, considering I knew nothing about php/mysql about a week ago. However, I've made a registration process, login system, and the game pages (member only). However, I was talking to some people the other day, and I'm using MD5 to encrypt the passwords. The suggestion given to me was to use SHA2 with Salt. The problem that I'm facing is that no matter what I try, I can't seem to get the system working.. I've followed the advice originally recieved: no success. I've followed a tutorial online: no success. SO, I was wondering if someone from here could help me. My database has the extra 'salt' field setup.. and here's my uneddited working MD5 code: Code: [Select] <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $email = clean($_POST['email']); $login = clean($_POST['login']); $password = clean($_POST['password']); $cpassword = clean($_POST['cpassword']); $empire_name = clean($_POST['empire_name']); $race = clean($_POST['race']); $referrer = clean($_POST['referrer']); //Input Validations if($email == '') { $errmsg_arr[] = 'Email missing'; $errflag = true; } if($login == '') { $errmsg_arr[] = 'Username missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } if($cpassword == '') { $errmsg_arr[] = 'Confirm password missing'; $errflag = true; } if( strcmp($password, $cpassword) != 0 ) { $errmsg_arr[] = 'Passwords do not match'; $errflag = true; } if($empire_name == '') { $errmsg_arr[] = 'Empire Name missing'; $errflag = true; } if($race == '') { $errmsg_arr[] = 'Race not selected'; $errflag = true; } if(strlen($login) > 20) { $errmsg_arr[] = 'Username exceeds allowed charachter limit'; $errflag = true; } if(strlen($empire_name) > 20) { $errmsg_arr[] = 'Empire Name exceeds allowed charachter limit'; $errflag = true; } //Check for duplicate login ID if($login != '') { $qry = "SELECT * FROM members WHERE login='$login'"; $result = mysql_query($qry); } if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Username already in use'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } //Check for duplicate Empire Name if($empire_name != '') { $qry = "SELECT * FROM members WHERE empire_name='$empire_name'"; $result = mysql_query($qry); } if($result) { if(mysql_num_rows($result) > 0) { $errmsg_arr[] = 'Empire Name already in use'; $errflag = true; } @mysql_free_result($result); } else { die("Query failed"); } //If there are input validations, redirect back to the registration form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location:register-form.php"); exit(); } //Create INSERT query $qry = "INSERT INTO members(email, login, passwd, empire_name, race, referrer) VALUES('$email','$login','".md5($_POST['password'])."','$empire_name','$race','$referrer')"; $result = @mysql_query($qry); //Check whether the query was successful or not if($result) { header("location: register-success.php"); exit(); }else { die("Query failed"); } ?> My second question is: I've got a set of permissions in my members database.. These are guest, player, mod and admin. I'm currently running my updates page by calling the updates from the database... How would i go about adding a link to the first page you come to (after logging in) that can only be seen by members who are in the admin permission? Because I'd like to make an admincp with a page to submit a form to the database that updates the updates page.. However, I'd rather the link to it only showed up for me and was invisible to other members.. Again, I'm only asking because I cant seem to find any information online at any tutorials or worksheets that I've come across.. And believe me, I've been searching quite a bit.. :/ Any help would be very much appreciated.. Cheers, /zythion/ This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330539.0 I am trying to store website address in a variable but when I do so the dots in the address are missing. I guess it takes it as string concatenation, for example: $address='www.lottocomplete.com'; will actually give me: wwwlottocompletecom How can I make sure these dots will be preserved? I am also trying to store email address in a variable but I get error, something about @ symbol being in wrong spot, wonder how this can be resolved as well. One more questions relates to the new line issue that I have when I concatenate string, for example if I do the following: $string = "1\n"; $string .= "2\n"; $string .= "3\n"; I would think that each number would be printed on new line but instead it shows up as: 123 What am I doing wrong? Question 1. Say I have a register form where a member registers with their full name but many people can have the same full name. What would be the best way to make the full name appear unique in the url(eg. website.com/member/johnsmith) for each member?
Question 2. I am not sure about other CMS but Shopify has this feature where you can change the colors of certain things on the website, in the backend. How is that achieved? I am a little lost on how you should connect css with php.
Hello all! I want to use PHP to valididate html fields. I'm using a form in index.php and using process.php to process the data, here is my current base: <?php if (isset($_REQUEST['email'])) { $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $from = $_REQUEST['from'] ; $amount = $_REQUEST['amount'] ; $message = $_REQUEST['message'] ; $from = $from; $length = $amount; for ($p = 0; $p < $length; $p++) { mail("$email", "$subject", $message, "From:" . $from); } $headers = "From:" . $from; header('Location: success.php'); } ?> If I wanted to only allow a certain figure in the 'amount' field, would something like this work: <?php $options = array( 'options' => array( 'min_range' => 1, 'max_range' => 99, ) ); $options['options']['default'] = 1; if (($int_c = filter_var($int_c, FILTER_VALIDATE_INT, $options)) !== FALSE) { echo "That number entered is between 1-99."; } ?> However, I'm not sure how I'd apply it to process.php to stop the 'mail' from occurring if the quantity is not between 1-99. Also that above code doesn't echo' That number you have entered is not valid' Many thanks Hi, I have this form to create a new user: Code: [Select] <form action="<?php htmlentities($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" on> <table width="850" border="0" align="center" cellpadding="8" cellspacing="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td><span class="CP_blueTXT">Nombre de la persona autorizada</span></td> </tr> <tr> <td> <input name="usuario_nombre" type="text" class="CP_loginFormFields" id="usuario_nombre" size="32" /></td> </tr> </table></td> </tr> </table> <table width="100%" border="0" cellpadding="10" cellspacing="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td><span class="CP_blueTXT">Nombre de usuario</span></td> </tr> <tr> <td> <input name="usuario" type="text" class="CP_loginFormFields" id="usuario" size="32" /> <span class="CP_SiNoText"><?php echo isset($errorMsg) ? $errorMsg : '';?></span></td> </tr> </table></td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td><span class="CP_blueTXT">Contraseña</span></td> </tr> <tr> <td> <input name="password" type="text" class="CP_loginFormFields" id="password" size="32" /></td> </tr> </table></td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="2%"> </td> <td width="98%"><input name="upload" type="submit" class="box" id="upload" value=" crear usuario" /></td> </tr> </table></td> </tr> </table></td> </tr> </table> </form> ...and I use this query to cretae a new user record: Code: [Select] $colname_checkdup_RS = "-1"; // this checks that if the user entered is already in database if (isset($_POST['usuario'])) { $colname_checkdup_RS = $_POST['usuario']; } mysql_select_db($database_MySQLconnect, $MySQLconnect); $query_checkdup_RS = sprintf("SELECT * FROM t_usuario WHERE usuario = %s", GetSQLValueString($colname_checkdup_RS, "text")); $checkdup_RS = mysql_query($query_checkdup_RS, $MySQLconnect) or die(mysql_error()); $row_checkdup_RS = mysql_fetch_assoc($checkdup_RS); $totalRows_checkdup_RS = mysql_num_rows($checkdup_RS); if($totalRows_checkdup_RS==1) { $errorMsg = "el usuario introducido ya existe en la base de datos"; // duplicate entry found message } else{ $query = "INSERT INTO eu45antinew.t_usuario (usuario_nombre,usuario,password) ". "VALUES ('$usuario_nombre','$usuario','$password')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); //echo "<br>Files uploaded<br>"; header("Location: PC_users_display.php"); } } ?> The query includes a function to check if the value entered in "user" already exists. This works fine, but I want the field "user" to be an email address...so I would like to validate that field...how can I do that? Thanks I have been toying around with form validation and have got to a sticking point in four areas that I am pretty sure are easier to do than I am finding! What I have so far works fine - once you start typing in a field, if it is invalid, then there is a message and some extra styling that is removed once it is valid. These are the functions for the four fields so far (there will be more, some required, some not). $('#username').on('keyup', function(){ var valid = /^[a-zA-Z0-9_-]{3,16}$/.test(this.value) && this.value.length; $('#regUsername .regAlert').html((valid?'':'Not Valid')); if(!valid){ $("#regUsername").addClass('bg-danger'); }else{ $("#regUsername").removeClass('bg-danger'); } }); $('#email').on('keyup', function(){ var valid = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/.test(this.value) && this.value.length; $('#regEmail .regAlert').html((valid?'':'Not Valid')); if(!valid){ $("#regEmail").addClass('bg-danger'); }else{ $("#regEmail").removeClass('bg-danger'); } }); $('#password').on('keyup', function(){ var valid = (/^(?=.*\d)(?=.*[a-zA-Z])[0-9a-zA-Z]{6,}$/).test(this.value) && this.value.length; $('#regPassword .regAlert').html((valid?'':'Not Valid')); if(!valid){ $("#regPassword").addClass('bg-danger'); }else{ $("#regPassword").removeClass('bg-danger'); } }); $('#password_confirm').on('keyup', function(){ var valid = (/^(?=.*\d)(?=.*[a-zA-Z])[0-9a-zA-Z]{6,}$/).test(this.value) && this.value.length; $('#regPassword2 .regAlert').html((valid?'':'Not Valid')); if(!valid){ $("#regPassword2").addClass('bg-danger'); }else{ $("#regPassword2").removeClass('bg-danger'); } }); What I am trying to do next is, if any of these fields are not valid, for the submit button to be disabled I can do by including if(!valid){ $('#registerSubmit').prop('disabled', true); }else{ $('#registerSubmit').prop('disabled', false); }in each function BUT if one is invalid, but the next is valid, then this overrides it and the button is clickable again. I have also tried setting a variable to true/false and the same happens. Plus, if all are valid, once the button is clicked, it needs to check for empty (required) fields and only submit if all fields have data. I am also guessing that they is a better way of writing this using a single keyup function and then placing each fields rules within that, but I have tried to wrap it all in a single function but got more in a mess. So, what I am looking for help with (bearing in mind there will be more fields, radio's, checkboxes and selects in the full form) is How can I streamline all of the functions into one to save on repeated code and to make it simple to add more fields in future How can I disable the submit button if ANY of the validations have failed How can I check for any empty required fields on submit button click and not process the form if any are found How can I check that #password and #password_confirm match on keyup from #password_confirm Thanks in advance for any advice Steve I'm having some trouble validating a file upload. I have it set to display a message if the file upload name already exists, but it is also displaying the same message when the field is left blank. I tried adding in a message to display when the field was blank, but it always displays the previous message, plus the new message, and on top of that, the error message about the file field being blank displays even if the user has uploaded a file. can anyone help?? Code: [Select] <?php $firstname = ""; $lastname = ""; $address = ""; $city = ""; $state = ""; $zip = ""; $phone = ""; $position = ""; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>KulaE_WDP4451_U2IP</title> </head> <body> <form action="process_U2IP.php" method="post" enctype="multipart/form-data"> <h3>Please fill out the form below and upload your resume to apply for a position within our company:</h3> <table> <tr> <td><label for="firstname"><b>First Name*</b></label></td> <td><input name="firstname" type="text" size="20" id="firstname" value="<?php echo $lastname; ?>" /></td> </tr> <tr> <td><label for="lastname"><b>Last Name*</b></label></td> <td><input name="lastname" type="text" size="20" id="lastname" value="<?php echo $lastname; ?>" /></td> </tr> <tr> <td><label for="address"><b>Address*</b></label></td> <td><input name="address" type="text" size="20" id="address" value="<?php echo $address; ?>" /></td> </tr> <tr> <td><label for="city"><b>City*</b></label></td> <td><input name="city" type="text" size="20" id="city" value="<?php echo $city; ?>" /></td> </tr> <tr> <td><label for="state"><b>State*</b></label></td> <td><input name="state" type="text" size="20" id="state" value="<?php echo $state; ?>" /></td> </tr> <tr> <td><label for="zip"><b>Zip*</b></label></td> <td><input name="zip" type="text" size="20" id="zip" value="<?php echo $zip; ?>" /></td> </tr> <tr> <td><label for="phone"><b>Phone*</b></label></td> <td><input name="phone" type="text" size="20" id="phone" value="<?php echo $phone; ?>" /></td> </tr> <tr> <td><label for="position"><b>Position*</b></label></td> <td><input name="position" type="text" size="20" id="position" value="<?php echo $position; ?>" /></td> </tr> <tr> <td><b>Upload Resume*</b></td> <td><input type="file" name="file" id="file" /> </td> </tr> <tr> <td colspan="2"><p><i>Your information will not be sold or shared with others.</i></p></td> </tr> <tr> <td colspan="2"><p style="color: red;">* denotes required field</p></td> </tr> <tr> <td colspan="2" align="center"><input type="hidden" name="submitted" value="1" /> <input type="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td> </tr> </table> </form> </body> </html> Code: [Select] <?php if (@$_POST['submitted']){ $firstname = (@$_POST['firstname']); $lastname = (@$_POST['lastname']); $address = (@$_POST['address']); $city = (@$_POST['city']); $state = (@$_POST['state']); $zip = (@$_POST['zip']); $phone = (@$_POST['phone']); $position = (@$_POST['position']); $file = (@$_POST['file']); if (get_magic_quotes_gpc()){ $firstname = stripslashes($firstname); $lastname = stripslashes($lastname); $address = stripslashes($address); $city = stripslashes($city); $state = stripslashes($state); $zip = stripslashes($zip); $phone = stripslashes($phone); $position = stripslashes($position); } $error_msg=array(); if ($firstname==""){ $error_msg[]="Please enter your first name"; } if(!preg_match("/^\b[a-zA-Z]+\b$/", $firstname)){ $error_msg[]="First Name can only contain letters"; } if ($lastname==""){ $error_msg[]="Please enter your last name"; } if(!preg_match("/^\b[a-zA-Z]+\b$/", $lastname)){ $error_msg[]="Last Name can only contain letters"; } if ($address==""){ $error_msg[]="Please enter your address"; } if(!preg_match('/^[a-z0-9 ]*$/i', $address)){ $error_msg[]="Address can only contain numbers, letters and spaces"; } if ($city==""){ $error_msg[]="Please enter your city"; } if (!preg_match("/^\b[a-zA-Z]+\b$/", $city)){ $error_msg[]="City can only contain letters"; } if ($state==""){ $error_msg[]="Please enter your state"; } if (strlen($state)<>2){ $error_msg[]="State can only contain 2 letters; use state abbreviation"; } if (!preg_match("/^\b[a-zA-Z]+\b$/", $state)){ $error_msg[]="State can only contain letters"; } if ($zip==""){ $error_msg[]="Please enter your zip code"; } if (strlen($zip)<>5){ $error_msg[]="Zip code can only contain 5 digits"; } if(!is_numeric($zip)){ $error_msg[]="Zip code must contain only numbers"; } if ($phone==""){ $error_msg[]="Please enter your phone number"; } if (strlen($phone)<>10){ $error_msg[]="Phone number can only contain 10 digits"; } if(!is_numeric($phone)){ $error_msg[]="Phone number must contain only numbers"; } if ($position==""){ $error_msg[]="Please enter your desired position"; } if(!preg_match('/^[a-z0-9 ]*$/i', $position)){ $error_msg[]="Position can only contain numbers, letters and spaces"; } if (file_exists("upload/" . $_FILES["file"]["name"])) { $error_msg[]= $_FILES["file"]["name"] . " already exists"; } if ((($_FILES["file"]["type"] != "document/msword") || ($_FILES["file"]["type"] != "document/pdf")) && ($_FILES["file"]["size"] > 50000)) { $error_msg[]= "Uploaded file can only be in MSWord or PDF format and can only be under 50KB in size"; } } if ($error_msg){ $display_errors = "<h3>There were errors in your submission.</h3> <p>Please review the following errors, press the Back button on your browser, and make corrections before re-submitting.</p> <ul style=color:red>\n"; foreach ($error_msg as $err){ $display_errors .= "<li>".$err."</li>\n"; } $display_errors .= "</ul>\n"; } if (!$error_msg){ echo " <h3>Thank you for applying! Applicants we are interested in interviewing will be contacted within 48 hours.</h3> <p>You have submitted the following information:</p> <table> <tr> <td><b>First Name:</b></td> <td>$firstname</td> </tr> <tr> <td><b>Last Name:</b></td> <td>$lastname</td> </tr> <tr> <td><b>Address:</b></td> <td>$address</td> </tr> <tr> <td><b>City:</b></td> <td>$city</td> </tr> <tr> <td><b>State:</b></td> <td>$state</td> </tr> <tr> <td><b>Zip Code:</b></td> <td>$zip</td> </tr> <tr> <td><b>Phone Number:</b></td> <td>$phone</td> </tr> <tr> <td><b>Position Desired:</b></td> <td>$position</td> </tr>"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "<tr> <td><b>Uploaded File:</b></td> <td><a href=upload/" . $_FILES["file"]["name"] . ">" . $_FILES["file"]["name"] . "</a></td> </tr> </table>"; exit(); } echo $display_errors; ?> I am trying to validate username and password fields. I want to use preg match, but have little knowledge of this function. I want the password to only contain A-z 0-9 and with at least one letter and one number. Username needs to only include "A-z 0-9 _ -" no spaces in any of these. Here is what I have so far: $username= $_POST['username']; $password = $_POST['password']; $password2 = $_POST['password2']; if($password==$password2){ if( preg_match("[A-z0-9]", $password) || strlen($password)>6 // at least 7 chars || strlen($password)<26 // at most 20 chars ){$errors[] = 'Password must contain at least one number and letter plus be between 7-25 characters. May only contain alphanumeric characters, _ and .';} }else{$errors[] = 'Your Passwords did not Match';} if( preg_match("[A-z0-9_-]", $username) || strlen($username)>5 // at least 6 chars || strlen($username)<26 // at most 25 chars ){ $errors[] = 'Username must be 6-25 characters and contain only alphanumeric characters, _ and .'; } <input type="text" maxlength="5" name="zip" value="Zip Code" pattern="(\d{5})?" />So, if the zip code is filled, it should be a five digit number. If it's not filled it's optional. The above RegEx is forcing everyone to enter a zip code. Can HTML do this, or am I going to have to script it? Ok If anyone read my recent topics they will know I am making a forum system This system for users is currently about 1/3 complete and I now have a couple of issues. Firstly: When a user logs in I am using $_SESSION['RAYTH_MEMBER_ID'] to save their member ID for when they return. However every time the browser/page is closed it doesn't save and then they are logged out. How would I set it so it keeps them logged in until they personally logout? Secondly: Since It's a forum you expect there to be new lines and stuff when you Read posts in threads (like we do here). How would I set it when a user posts it replaces every return character from the input (enter/newline etc) and replace it with <br> in the mysql database? Thanks for your help I'm working with a payment module for a zencart template. The files are in PHP and I know some HMTL over the years, but never touched PHP coding.
Here are three lines of text in my PHP....
define('MODULE_PAYMENT_DOLLARS_TEXT_TITLE', 'Pay with dollars!'); define('MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT', 'Checkout with PayPal.'); define('MODULE_PAYMENT_PAYPALEC_MARK_BUTTON_IMG', 'https://www.paypalobjects.com/en_US/i/logo/PayPal_mark_37x23.gif'); Hi, I have a search form which pulls info from a MySQL table and there are a few enhancements I would like to make. 1) I would like the search terms in my results table hilited in red. I made a class in my stylesheet for this, but it isn't working so I am missing a step or two 2) I would like a display for the number of results returned. Example. "There were 3 results found in your search". 3) This isn't php related, but if anyone has any ideas why my JQuery slideup doesn't work with my results let me know. I have posted in the JavaScript section, but haven't gotten a response. My code. Code: [Select] <html> <head> <link href="default.css" rel="stylesheet" type="text/css" media="screen" /> <script src="js/jquery.js"></script> <script src="js/jquery-fonteffect-1.0.0.js"></script> <script type="text/javascript"> $("#mirror").FontEffect({ outline:true }) </script> <script type='text/javascript'> var $ = jQuery.noConflict(); $(document).ready(function(){ $("#search_results").slideUp(); $("#search_button").click(function(e){ e.preventDefault(); ajax_search(); }); // $("#search_term").keyup(function(e){ // e.preventDefault(); // ajax_search(); // }); }); function ajax_search(){ $("#search_results").show(); var search_val=$("#search_term").val(); $.post("./find.php", {search_term : search_val}, function(data){ if (data.length>0){ $("#search_results").html(data); $(document).ready(function(){ $(".stripeMe tr").mouseover(function(){$(this).addClass("over");}).mouseout(function(){$(this).removeClass("over");}); $(".stripeMe tr:even").addClass("alt"); }); } }) } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso- 8859-1" /> <title>Novo RPC Results Search Engine</title> <link href="default.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="mirror">Search RPC participants</div> <form id="searchform" method="post" action="find.php"> <div> <label for="search_term">Search RPC information</label> <input type="text" name="search_term" id="search_term" /> <input type="submit" value="search" id="search_button" /> </div> </form> <div id="search_results"></div> </body> </html> <?php define(HOST, "localhost"); define(USER, "username"); define(PW, "pw"); define(DB, "DBName"); $connect = mysql_connect(HOST,USER,PW) or die('Could not connect to mysql server.' ); mysql_select_db(DB, $connect) or die('Could not select database.'); $term = strip_tags(substr($_POST['search_term'],0, 100)); $term = mysql_escape_string($term); $sql = "SELECT * FROM Phase1A_1B_TotalScores_2011 WHERE CONCAT(last_name,first_name,employee_id,title,territory,district,Phase1A_Score,Phase1B_HS_Exam, Phase1A_HS_Exam_RT,Phase1B_HS_Exam ,Phase1B_HS_Exam_RT,Class_Date) LIKE '%$term%' order by last_name asc"; $string = ''; $string = "<table class='stripeMe' id='Results'><tr><th>Last Name</th><th>First Name</th><th>Employee ID</th><th>Title</th><th>Territory</th><th>District</th><th>Phase 1A Score</th><th>Phase 1B Score</th><th>Phase 1 Average</th><th>Phase 1A HS Exam</th><th>Phase 1A HS Exam Retake</th><th>Phase 1B HS Exam</th><th>Phase 1B HS Exam Retake</th><th>Class Dates</th><th>Awards</th></tr>"; $result = mysql_query($sql); /// This is the execution if (mysql_num_rows($result) > 0){ while($row = mysql_fetch_object($result)){ $string .= "<tr>"; $string .= "<td>".$row->last_name."</td> "; $string .= "<td>".$row->first_name."</td>"; $string .= "<td>".$row->employee_id."</td>"; $string .= "<td>".$row->title."</b>"; $string .= "<td>".$row->territory."</td>"; $string .= "<td>".$row->district."</td>"; $string .= "<td>".$row->Phase1A_Score."</td>"; $string .= "<td>".$row->Phase1B_Score."</td>"; $string .= "<td>".$row->Phase1_Average."</td>"; $string .= "<td>".$row->Phase1A_HS_Exam."</td>"; $string .= "<td>".$row->Phase1A_HS_Exam_RT."</td>"; $string .= "<td>".$row->Phase1B_HS_Exam."</td>"; $string .= "<td>".$row->Phase1B_HS_Exam_RT."</td>"; $string .= "<td>".$row->Class_Date."</td>"; $string .= "<td>".$row->Awards."</td>"; $string .= "<br/>\n"; $string .= "</tr>"; //print_r($row); } $string .= "</table>"; }else{ $string = "<span class='NMF'>No matches found!</span>"; // echo $sql; } echo $string; ?> and lastly my CSS Code: [Select] /*search term styling*/ #search_term{ font-weight:bold; color:#f00; } This is my first real jump into PHP, I created a small script a few years ago but have not touched it since (or any other programming for that matter), so I'm not sure how to start this. I need a script that I can run once a day through cron and take the date from one table/filed and insert it into a different table/field, converting the human readable date to a Unix date. Table Name: Ads Field: endtime_value (human readable date) to Table Name: Node Field: auto_expire (Converted to Unix time) Both use a field named "nid" as the key field, so the fields should match each nid field from one table to the next. Following a tutorial I have been able to insert into a field certain data, but I don't know how to do it so the nid's match and how to convert the human readable date to Unix time. Thanks in advance!. Hi: I'm going crazy trying to do the following: I'm making a job registration process where the user registers on one php page to the website, must acknowlege and email receipt using an activate php page, then is directed to upload their C.V. (resume) based on the email address they enter in the active page output. I then run an upload page to store the resume in teh MySQL db based on the users email address in the same record. If I isolate the process of the user registering to the db, it works perfectly. If I isolate the file upload process into the db, it works perfect. I simply cannot upload teh file to the existing record based on teh email form field matching the user_email field in the db. With the processes together, teh user is activated, but teh file is not uploaded. Maybe I've simply been at this too long today, but am compeled to get through it by end day. If anyone can help sugest a better way or help me fix this, I will soo greatly appreciate it. My code is as follows for the 2 pages. ---------activate.php------- <?php session_start(); include ('reg_dbc.php'); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } $rsCode = mysql_query("SELECT activation_code from subscribers where user_email='$_GET[usr]'") or die(mysql_error()); list($acode) = mysql_fetch_array($rsCode); if ($_GET['code'] == $acode) { mysql_query("update subscribers set user_activated=1 where user_email='$_GET[usr]'") or die(mysql_error()); echo "<h3><center>Thank You! This is step 2 of 3. </h3>Your email is confirmed. Please upload your C.V. now to complete step 3.</center>"; } else { echo "ERROR: Incorrect activation code... not valid"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Job application activation</title> </head> <body> <center> <br/><br/><br/> <p align="center"> <form name="form1" method="post" action="upload.php" style="padding:5px;"> <p>Re-enter you Email : <input name="email" type="text" id="email"/></p></form> <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="4000000"> Upload your C.V.: <input name="userfile" type="file" id="userfile"> <input name="upload" type="submit" id="upload" value="Upload your C.V."/></form> </p> </center> </body> </html> --------upload.php---------- <?php session_start(); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $email = $_POST['email']['user_email']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include 'reg_dbc.php'; $query = "UPDATE subscribers WHERE $email = user_email (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); mysql_close($dbname); } ?> <center> <br/> <br/> <br/> <br/> Thank you for uploading your <?php echo "$fileName"; ?> file, completing your registration, and providing us your C.V. for this position. <br/> <br/> <br/> We will contact you if your canditature qualifies. </center> Code: [Select] $new_array2=array_diff($my_array,$itemIds); $updatedb = mysql_query("UPDATE content_type_ads SET field_expire_value = '666' WHERE $new_array2 = field_item_id_value"); "$new_array2" has only 12 digit numbers for each item in the array, and I want to match them to the "field_item_id_value" field in the table, updating the "field_expire_value" field for the record where they match. I know I am close because the UPDATE code works before I add the WHERE statement (it of course adds '666' to EVERY field, but for a noobie it's a start!). (Another quite newbie...) I have already an online booking form. The Form works fine now and I would like to add on one more issue, but the code ignores what I want to check. I have 4 fields: arrival, departure, no. of persons and comments to check. Scenario 1: All field mentioned above are emtpty: Workes fine and message appears: "You have not provided any booking details". Scenario 2: If arrival (date_start) and departure (date_end) is entered, there should be at least an entry either in the field "comment", or in the field "pax". If not, there should be a message: "You have not provided sufficient booking details". INSTEAD: The booking request is sent, which should not be the case. The code is currently: # all fields empty : arrival, departure, pax and comments - error if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){ exit("You have not specified any booking details to submit to us. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } #If arrival and departure date is entered, there should be at least an entry either in the field "comment", or in the field "pax". if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){ exit("You have not provided sufficient booking details. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } The form can be tested at http://www.phuket-beachvillas.com/contact-own/contact-it.php Can someone please check and tell me what's wrong with the code ? Thanks to anyone for any hint. I just installed this new script here http://webhost.pro/domain-check.php it's a basic domain availability tool. I am trying to make a form that can be used on any page forward to this page with the content. The page loads with this in the url webhost.pro/domain-check.php?domain=dwhs.net and will run the page. So I can make a form that just submits to that page and sends the details. I made this page for testing http://webhost.pro/test.html But no go, here is the code: <form id="search" action="/domain-check.php" method="GET"> <input type="text" name="s"> <a onClick="document.getElementById('search').submit()" class="button1">Search</a> <div class="clear"></div> </form> Thanks! Hi, I'm developing an app using flash AS2 as the front end via PHP and a mySQL database at the backend on my server. what i'm looking to do is update/insert into a table called 'cards' and at the same time update/insert into another table called 'jingle'. There is a field called 'cardID' in jingle that should be the same as the ID number created in 'cards' thus creating a link between entries in the different tables that can be called up as i choose. hope i've been clear i just wouldn't know where to start any help would be appreciated. MySQL client version: 5.0.91 PHPmyAdmin Version information: 3.2.4 thanks in advance |