PHP - Check If A Users Email Already Exists In The Database On Submit
Hi there everyone,
I have the below code (needs to be sanitized for SQL injection - i know ). Submitting to a MYSQL database. I wish to check on form submit if the users email address already exists, and if so display a simple error message (even just a windows error message) stating "the email address you have entered already exists". I don't really know where to start with this, or what the code should look like, so any help and direction would be massively appreciated. All i do know, is the email column is set to unique, and when i attempt to submit using an email i know exists the code appears to run successfully without spitting out any errors (i.e. the web url changes to the below php code) but the table doesn't update (which is correct). I just don't know how to then return the user to the form (preferably with all their info still entered) when this happens along with a nice error message... Kind regards, Tom. Code: [Select] <? $localhost="00.000.000.00"; $username="###"; $password="###"; $database="mfirst"; $firstname=$_POST['firstname']; $surname=$_POST['surname']; $dob="{$_POST['dobyear']}-{$_POST['dobmonth']}-{$_POST['dobday']}"; if (isset ($_POST['permissionnewsletter']) || (!empty ($_POST['permissionnewsletter']))) { $permissionnewsletter = "Yes"; } else { $permissionnewsletter = "No"; } $email=$_POST['email']; $userpassword=$_POST['userpassword']; $telephone=$_POST['telephone']; mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $insertintocustomerdetail = "INSERT INTO customerdetail VALUES (NULL,'$firstname','$surname','$dob','$permissionnewsletter','$email','$userpassword','$telephone',now())"; mysql_query($insertintocustomerdetail); $addressline1=$_POST['addressline1']; $addressline2=$_POST['addressline2']; $cityortown=$_POST['cityortown']; $county=$_POST['county']; $postcode=$_POST['postcode']=strtoupper(@$_REQUEST['postcode']); $insertintoaddresstable = "INSERT INTO addresstable VALUES (NULL,LAST_INSERT_ID(),'$addressline1','$addressline2','$cityortown','$county','$postcode',now())"; mysql_query($insertintoaddresstable); mysql_close(); ?> Similar Tutorialsi wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers All, In my registration script I am trying to check if an email address already exists (yawn I know), and I am stuck. The code highlighted in bold is where I want to check if the email exists (notice that form checking is done above that, including sorting out the email address that the user enters) and if it doesnt insert data into the table. Trouble is that on loading the page it simply states the 'already submitted' error before an email is even entered into the form: Code: [Select] if(isset($_POST['name']) && !empty($_POST['name']) AND isset($_POST['email']) && !empty($_POST['email']) AND ($_POST['password']) && !empty($_POST['password'])){ $name = mysql_escape_string($_POST['name']); // Turn our post into a local variable $email = mysql_escape_string($_POST['email']); $password = mysql_escape_string($_POST['email']);// Turn our post into a local variable } $name = mysql_escape_string($_POST['name']); $email = mysql_escape_string($_POST['email']); $password = mysql_escape_string($_POST['password']); if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ // Return Error - Invalid Email $msg = 'The email you have entered is invalid, please try again.'; }else{ // Return Success - Valid Email $msg = 'Your account has been made, <br /> please verify it by clicking the activation link that has been sent to your email.'; } $hash = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable. // Example output: f4552671f8909587cf485ea990207f3b [b]$emailCheck = mysql_query("SELECT email FROM users WHERE email = '".$email."'"); if (mysql_num_rows($emailCheck) > 0) { echo "already submitted"; } else {[/b] // We have a match, activate the account mysql_query("INSERT INTO users (username, password, email, hash) VALUES( '". mysql_escape_string($name) ."', '". mysql_escape_string(md5($password)) ."', '". mysql_escape_string($email) ."', '". mysql_escape_string($hash) ."') ") or die(mysql_error()); Thanks in advance, G Hey, so I'm trying to check the database if the user and email already exists when registering. <?php include_once('includes/config.php'); if(isset($_POST['submit'])) { $username = $_POST['username'] ? trim($_POST['username']) : null; $password = md5($_POST['password']) ? trim($_POST['password']) : null;; $email = ($_POST['email']); $message = ""; if(empty($username) || empty($password) || empty($email)) { $message = "All fields required"; } else { $sql = "SELECT COUNT(username) AS userNum FROM users WHERE username = :username"; $sql = "SELECT COUNT(email) AS emailNum FROM users WHERE email = :email"; $stmt = $db->prepare($sql); $stmt->bindValue(':username', $username); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if($row['userNum'] >0) { die("That username already exists!"); } elseif($row['emailNum'] > 0) { die("That email already exists!"); } $sql = "INSERT INTO users (username, password, email) VALUES (:username, :password, :email)"; $stmt = $db->prepare($sql); $stmt->bindValue(':username', $username); $stmt->bindValue(':password', $password); $stmt->bindValue(':email', $email); $result = $stmt->execute(); if($result) { $message = "Registration was successful"; } } } ?> If I remove this line " $sql = "SELECT COUNT(email) AS emailNum FROM users WHERE email = :email"; the code works but only checks the username. How can I check both? Hello. I want to check if an e-mail address is stored into a database. I've found this type of code: Code: [Select] function verifmail($email) { db_connect(); if (mysql_num_rows(mysql_query("SELECT email FROM users WHERE email='$email';"))) { return 1; } else { return 0; } } Is it correct ? Is there any other way? Hi there everyone. I'm really confused about this as I want to email eveyone in my DB when a new Event is created by a member. I have a test code which I used to make sure it works and it sends to 5 email addresses (which is all of them) in the test table. This works fine. All members with a 0 get the mail. So I now just took the code and changed the table name (obviously!!) and put it in my live site which has 50 members so far. It now doesn't send any emails??? Not sure why this is as the code is exactly the same (except the table name). $result = mysql_query("SELECT email FROM membership WHERE send_as_email = '0'"); while ($row = mysql_fetch_array($result)) { sendMail($row[0]); } mysql_free_result($result); function sendMail($to){ $subject = 'New Event Created; $message = "Hi there,\n Just letting you know of a new Event that has been created.\n Title: $title\n Town: $town\n Date: $date_convert\n For more details or to attend this Event, please login \n Many thanks\n The Team\n \n ****************************************************************************\n THIS EMAIL IS AUTOMATED. DO NOT REPLY.\n To turn notifications off, change the notification settings in your Profile.\n ****************************************************************************\n"; $headers = 'From: members@mysite.co.uk' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=359217.0 Hello all. I have seen a few threads that loosely deal with ways to do this, but haven't seen anything yet that speaks to this scenario. I have a page (volunteer_signup.php) that shows events to participate in and it passes some variables to a second page (volunteer.php)which is a form for individuals to enter their credentials and that appends to the event detail passed from the first page. I want to be able to check that their email isn't already associated with this particular event, but it is allowed to be in the database for another event. I wanted to do something like the code below, but don't know how to incorporate that with the form (or in volunteerDB.php) any help would be great. thank you in advance. Code: [Select] $sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'"); $email_check = mysql_num_rows($sql_email_check); if($email_check > 0) { echo "Email is already in our database. Please enter a different email !! <br />"; } exit(); } current form: Code: [Select] <html> <?php include('dbconfig.php'); $event_id = $_GET['id']; $park = $_GET['park']; $orderdate = $_GET['orderdate']; $description = $_GET['description']; $leader = $_GET['leader']; $hour = $_GET['hour']; $min = $_GET['min']; $ampm = $_GET['ampm']; echo $orderdate; echo "<BR>"; echo $park; echo "<BR>"; echo $description; echo "<BR>"; echo $hour; echo ":"; echo $min; echo $ampm; ?> <body> <form enctype="multipart/form-data" action="volunteerDB.php" method="POST" name="myform"> <table border="1"> <input type="hidden" name="event_id" value=<?php echo $event_id; ?>> <input type="hidden" name="park" value=<?php echo $park; ?>> <input type="hidden" name="orderdate" value=<?php echo $orderdate; ?>> <input type="hidden" name="description" value=<?php echo $description; ?>> <input type="hidden" name="leader" value=<?php echo $leader; ?>> <input type="hidden" name="hour" value=<?php echo $hour; ?>> <input type="hidden" name="min" value=<?php echo $min; ?>> <input type="hidden" name="ampm" value=<?php echo $ampm; ?>> <tr> <td>First Name</td> <td> <input name="firstname" /> </td> </tr> <tr> <td>Last Name</td> <td> <input name="lastname" /> </td> </tr> <tr> <td>Email</td> <td> <input name="email" /> </td> </tr> <tr> <td>Phone</td> <td> <input name="phone" /> </td> </tr> <tr> </tr> </table> <input type="submit" value="Submit" onclick="verify();"> </td> </tr> </form> </body> </html> form feeds to this php page (volunteerDB.php): Code: [Select] <?php include('dbconfig.php'); $event_id = $_POST['event_id']; $park = $_POST['park']; $orderdate = $_POST['orderdate']; $description = $_POST['description']; $leader = $_POST['leader']; $hour = $_POST['hour']; $min = $_POST['min']; $ampm = $_POST['ampm']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $phone = $_POST['phone']; $email_list = $_POST['email_list']; // Make a MySQL Connection mysql_connect("localhost", "$user", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); mysql_query("INSERT INTO volunteer (id, event_id, park, firstname, lastname, email, phone, email_list) VALUES('', '$event_id', '$park', '$firstname', '$lastname', '$email', '$phone', '$email_list') ") or die(mysql_error()); ?> <?php $to = "$email"; $subject = "Trailworker Event Signup Confirmation"; $message = "Hello $firstname! Thank you for signing up to work the $park trailworker event. A crew leader will contact you shortly. Park: $park Date: $orderdate Time: $hour:$min $ampm Description: $description Crew Leader: $leader"; $from = "info@xxxxxxxxxx.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Thank you for signing up. You will receive an email shortly letting you know event details and who your crew leader is."; ?> Hello, I have looked on the forum, but haven't found the answer to this. I have a basic [name, email, phone, event] web form and want to make sure there person is not submitting twice by doing duplicate check of the mail. I looked at other solutions that suggested setting up unique IDs for each user, but it would be possible for a user to sign up for more then one event. Any info would be helpful. Not a newbie, but not an expert. I am trying to compare an array containing required questions to an array holding survey responses. When a user submits a survey, I take the $_POST array and write the values to a new array called $surveyResponseArray. How can I determine if $surveyResponseArray exists?
Edited February 16 by SaranacLake hi, how can i check if a username exists? i tried this
$usrsql = "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password'"; $usrres = mysql_query($usrsql); $usrcount = mysql_num_rows($usrres); if($usrres && mysql_num_rows($usrcount)>0) { die("Username is already taken!"); } What is the best/proper way to check if a supplied URL goes to an actual image? My site will allow users to enter an image URL (like "http://example.com/images/monkey.jpg"). I will store the URL they enter in a MySQL database and then will call it up later and do some resizing to these images. But I don't want to try to do any resizing if the URL they supply doesn't actually go to an image, or if it's blank (i.e. the user didn't enter a URL yet). So basically, I will run a MySql query to pull back the contents of the column called "imageurl". Let's say those contents are stored in a variable called $imageurl. This is what I'm trying to accomplish.... Code: [Select] if ($theimageurl does NOT contain a URL to an image OR is blank) { // do this } else { //run my resizing code } I guess i could do this to check to see if it's blank, but not sure this is proper/most efficient way to check that part of the issue... Code: [Select] if (trim($theimageurl) == "") But greater than the "is it blank" concern is that people may enter URLs that just to a regular website so whether it's at this point in my code (or for security, I should probably do it BEFORE inserting it into my database :/ ) so curious if there are any functions that check to see if it's an image URL or not. I know of file_exists, but I'm pretty sure that's just checking to see if a file exists and doesn't check image URLs. Any info/suggestions would be appreciated as always! And if there are any recommended functions to check/clean the user-entered URL BEFORE it's entered into the database, please share Thanks! Hello, I want to check when adding a new user, that if there are 2 records that has the same recruiter id, it's should give an error, if less, than it makes him complete the registration Also check if the National ID number is not assigned to another user, so if there is a record that has it, it should give and error, if it's unavailable, it should let him complete the registration here is my code register.html Code: [Select] <html> <form action="post.php" method="post"> <table> <tr><td>First Name: <input type="text" name="fname" /></td></tr> <tr><td>Middle Name: <input type="text" name="mname" /></td></tr> <tr><td>Last Name: <input type="text" name="lname" /></td></tr> <tr><td>Mobile: <input type="text" name="mobile" /></td></tr> <tr><td>Telephone: <input type="text" name="tel" /></td></tr> <tr><td>Address: <input type="text" name="address" /></td></tr> <tr><td>Job Title: <input type="text" name="job" /></td></tr> <tr><td>Company: <input type="text" name="company" /></td></tr> <tr><td>National ID Number: <input type="text" name="nid" /></td></tr> <tr><td>Recruiter ID: <input type="text" name="recruiteris" /></td></tr> <tr><td>Email: <input type="text" name="email" /></td></tr> <tr><td>Password: <input type="password" name="password" /></td></tr> <tr><td>Type: <input type="text" name="type" /></td></tr> <tr><td><input type="submit" /></td></tr> </table> </form></html> post.php Code: [Select] <?php $sql="INSERT INTO users (id,fname, mname, lname, mobile, tel, address, job, company, nid, recruiteris, email, password, type) VALUES ('','$_POST[fname]','$_POST[mname]','$_POST[lname]','$_POST[mobile]','$_POST[tel]','$_POST[address]','$_POST[job]','$_POST[company]','$_POST[nid]','$_POST[recruiteris]','$_POST[email]','$_POST[password]','$_POST[type]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; echo "<br />"; echo "<a href='http://waw-eg.com/admin/register.html'>Add More Client? Click Here</a><br/>"; echo "<a href='http://waw-eg.com/admin/Users.php'>View Users Click Here</a>"; mysql_close($con) ?> I'm working with a registration/login system from a tutorial. It's got email validation to make sure it does not exist but I'm struggling to add the same to the username field: Working code: Code: [Select] <?php include ('database_connection.php'); if (isset($_POST['formsubmitted'])) { $error = array();//Declare An Array to store any error message if (empty($_POST['name'])) {//if no name has been supplied $error[] = 'Please Enter a name ';//add to array "error" } else { $name = $_POST['name'];//else assign it a variable } if (empty($_POST['e-mail'])) { $error[] = 'Please Enter your Email '; } else { if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) { //regular expression for email validation $Email = $_POST['e-mail']; } else { $error[] = 'Your EMail Address is invalid '; } } if (empty($_POST['Password'])) { $error[] = 'Please Enter Your Password '; } else { $Password = $_POST['Password']; } if (empty($error)) //send to Database if there's no error ' { // If everything's OK... // Make sure the email address is available: $query_verify_email = "SELECT * FROM members WHERE Email ='$Email'"; $result_verify_email = mysqli_query($dbc, $query_verify_email); if (!$result_verify_email) {//if the Query Failed ,similar to if($result_verify_email==false) echo ' Database Error Occured '; } if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email . // Create a unique activation code: $activation = md5(uniqid(rand(), true)); $query_insert_user = "INSERT INTO `members` ( `Username`, `Email`, `Password`, `Activation`) VALUES ( '$name', '$Email', '$Password', '$activation')"; $result_insert_user = mysqli_query($dbc, $query_insert_user); if (!$result_insert_user) { echo 'Query Failed '; } if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull. // Send the email: $message = " To activate your account, please click on this link:\n\n"; $message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation"; mail($Email, 'Registration Confirmation', $message, 'From: Admin@TheGameCo.Com'); // Flush the buffered output. // Finish the page: echo '<div class="success">Thank you for registering! A confirmation email has been sent to '.$Email.' Please click on the Activation Link to Activate your account </div>'; } else { // If it did not run OK. echo '<div class="errormsgbox">You could not be registered due to a system error. We apologize for any inconvenience.</div>'; } } else { // The email address is not available. echo '<div class="errormsgbox" >That email address has already been registered. </div>'; } } else {//If the "error" array contains error msg , display them echo '<div class="errormsgbox"> <ol>'; foreach ($error as $key => $values) { echo ' <li>'.$values.'</li>'; } echo '</ol></div>'; } mysqli_close($dbc);//Close the DB Connection } // End of the main Submit conditional. ?> <!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>Game Name - Home</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="container"> <div id="header"> <?php include("includes/header.php"); ?> </div> <div id="nav"> <?php include("includes/nav.php"); ?> </div> <div id="content"> <form action="index.php" method="post" class="registration_form"> <fieldset> <legend>Registration Form</legend> <p>Create A new Account<br />Already a member? <a href="login.php">Log in</a></p> <div class="elements"> <label for="name">Username:</label> <input type="text" id="name" name="name" size="25" /> </div> <div class="elements"> <label for="e-mail">E-mail:</label> <input type="text" id="e-mail" name="e-mail" size="25" /> </div> <div class="elements"> <label for="Password">Password:</label> <input type="password" id="Password" name="Password" size="25" /> </div> <div class="submit"> <input type="hidden" name="formsubmitted" value="TRUE" /> <input type="submit" value="Register" /> </div> </fieldset> </form> </div> <div id="footer"> <?php include("includes/footer.php"); ?> </div> </div> </body> </html> I've tried adding this after the email verification: Code: [Select] // Make sure the user is available: $query_verify_user = "SELECT * FROM members WHERE Username ='$name'"; $result_verify_user = mysqli_query($dbc, $query_verify_user); if (!$result_verify_user) { echo ' Database Error Occured '; } } if (mysqli_num_rows($result_verify_user) == 0) { // IF no previous user is using this user . But that just returns me with: It works to stop username/email duplication but now returns: Query Failed You could not be registered due to a system error. We apologize for any inconvenience. Not sure where I'm going wrong tbh. Hi, I am creating a temporary table. I need to check if the table already exists or not. If exists, I have to use the existing data else have to create a new temporary table. I can use 'Create If Not Exists'. How practical is this query? any issues with the performance? If the table exists it will be a huge data, I don't want to loose that data because recreating is an un-necessary load on the database. Hello , Im trying to make a very simple link trade script , which checks in a page exists and after searches to that page to find a link (in this case my link). But i got stuck in the lalst step of finding my link on a given page. Hope you can help me with that Code: [Select] <?php require_once('Connections/my_conn.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $myurl= 'http://mywebsite.com'; //check if the remote site url exists function url_exists($url) { $ch = @curl_init($url); @curl_setopt($ch, CURLOPT_HEADER, TRUE); @curl_setopt($ch, CURLOPT_NOBODY, TRUE); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $status = array(); preg_match('/HTTP\/.* ([0-9]+) .*/', @curl_exec($ch) , $status); } //check if my link exists in the remote site if(($status[1] == 200) && ($myurl== )); { //Insert into database code here } ?> I would like a little help on how to check if my link exist in the trader's url. Thanks in advance Please help before this script drives me insane. It tries to download a skin from Minecraft. It works fine, except, if it returns an error code, (301, 302, 404), don't download, and using my image (char.png) as a replacement. I can get the error code, except, no matter how I compare it, it will a) still say it's 302 or b) not work at all. Here's my code: userskin.inc.php > <?php require('class.mineuser.php'); if(!isset($_GET['width']) || strlen(trim($_GET['width'])) == 0 || !isset($_GET['height']) || strlen(trim($_GET['height'])) == 0) { $x = 16; $y = 16; } else { $x = $_GET['width']; $y = $_GET['height']; } if(isset($_GET['refresh'])) $refresh = true; else $refresh = false; if(isset($_GET['debug'])) $debug = true; else $debug = false; $http = curl_init("http://www.minecraft.net/skin/{$_GET['user']}.png"); curl_setopt($http, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($http); $http_status = curl_getinfo($http, CURLINFO_HTTP_CODE); $resp = preg_match("/302/", $http_status, $match); $code = $match[0]; if($code == 302) { mineuser::downloadSkin($_GET['user'], $_GET['path'], $code, $refresh); mineuser::getFace($_GET['user'].".png", $x, $y, $_GET['path'], $code, $debug); } else { mineuser::getFace("char.png", $x, $y, $_GET['path'], $code, $debug); } class.mineuser.php > <?php class mineuser { public static function downloadSkin($user, $path = "", $resp, $new = false) { if($resp !== 302) { //Checks if $new is true, if it is, then delete $user.png and download a new one. if($new == true) unlink("$path/$user.png"); //Checks if the users skin already exists (faster loading time) if(!file_exists("$path/$user.png")) { $fh = fopen("$path/$user.png", "w"); $file = file("http://www.minecraft.net/skin/$user.png"); foreach($file as $char) //Since it's an array, we use a foreach loop and write each character individually fwrite($fh, $char); fclose($fh); //Close our file handler. } } else { } } //End of function downloadSkin() public static function getFace($user, $width, $height, $path, $resp, $debug = true) { $im = imagecreatetruecolor($width, $height); if($debug == false) { header("Content-type: image/png"); } if($resp === 302) { $image = imagecreatefrompng("$path/char.png"); } else { $image = imagecreatefrompng("$path/$user"); } imagecopyresampled($im, $image, 0, 0, 8, 8, $width, $height, 8, 8); imagepng($im); imagedestroy($im); } //End of function getFace() } ?> please help before i go insane Thanks in advance Pehaps this is kidstuff but i'm a kid at heart. I have only 1 form field on a form User enters a special code in the form. Once submitted the form is queried against a mysql database to see if the code exists. If code does not exist it must be reentered. If code exists then redirected. basically its like "get to the next page if you have the code" thanks Hey guys im automatically generating a folder location to place some image files the user has uploaded into. If this folder doesnt exist how can i make it? $target_path_thumbnails = "http://www.worldwidelighthouses.com/Images/".$folderlocation."/".$foldername."/Mini/"; Thats the path style. Danny What is the best/proper way to run an image URL from an external site through a check to see if the image actually exists? I am trying to use file_exists() but it's not recognizing image URLs from external sites as existing, so there must be some other way to deal with external URLs. In other words, the image does exist but file_exists() says it doesn't. Can anyone help? Hello all, I am working on an upload script for a client. The script generates a random 32 bit string (to use as an ID). I want it to check if that folder exists and, if not, create it and put the files in it. Here is the script I have so far: <?php /******************************************* /* contact_us_process.php /* Author: Brandon Pence (brandonpence@gmail.com) /* /* Desc: This page process and checks the submitted form. /* /* variable meaning /* -------- ------- /* $FieldCheck Instance of the FieldCheck class. /* /******************************************/ session_start(); require ("./inc/include.inc.php"); //include Field Check Class include("classes/FieldCheck.php"); $FieldCheck = new FieldCheck; if(file_exists("uploads/$id")){ echo 'Folder Exists!'; }else{ echo 'Folder does not exist. Create folder.'; } //mkdir("uploads/$id",0777,true); $target_path = "uploads/$id/"; $i = 0; while($i < 3){ $target_path = $target_path . basename( $_FILES['uploadedfile']['name'][$i]); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$i], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name'][$i]). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } $i++; } if (!$FieldCheck->checkName($your_name)){ $errors['your_name'] = "Your name is not valid.";} if (!$FieldCheck->isEmpty($your_date)){ $errors['your_date'] = "Your date is not valid.";} if (!$FieldCheck->isEmpty($your_message)){ $errors['your_message'] = "Your message is not valid.";} foreach($_POST as $key=>$value){ $fields[$key] = $value; } //print_r($_POST); //check for error messages if (isset($errors)) { $_SESSION['errors'] = $errors; $_SESSION['fields'] = $fields; $_SESSION['error_msg'] = "Errors found! Please review your entries."; $url = "./testimonials.php?action=errors"; header ("Location: $url"); exit; }else{ // multiple recipients $to = 'email@email.com'; // note the comma // subject $subject = '[Domain Name.com] Testimonials Form Submission'; // message $message = ' Name: '.$your_name.' Date: '.$your_date.' Message: '.$your_message.' '; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Example <email@example.com>' . "\r\n"; $headers .= 'From: Example <email@example.com.com>' . "\r\n"; $headers .= 'X-MAILER: PHP'.phpversion(); $headers .= 'Reply-To:email@example.com'; // Mail it $mail = mail($to, $subject, $message); //mail("$to", "$subject", "this is a test message, if you are reading this the email was sent successfully."); //savvy $_SESSION['error_msg'] = "Your email has been sent. Thank you for contacting us."; header( "Location: testimonials.php?action=success" ); } ?> It always outputs folder exists, even though it doesn't. My form is this: function random_string($p_length) { $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $char_list .= "abcdefghijklmnopqrstuvwxyz"; $char_list .= "1234567890"; $random = ""; srand((double) microtime() * 1000000); for($i = 0; $i < $p_length; $i++) { $random .= substr($char_list, (rand() % (strlen($char_list))), 1); } return $random; } <form method="POST" action="contact_us_process.php" class="cmxform" enctype="multipart/form-data"> <?php if ($_GET['action'] == 'success' && isset($_SESSION['error_msg'])){ echo '<div class="success">'.$_SESSION['error_msg'].'</div>'; unset($_SESSION['error_msg']); }else{ if(isset($_SESSION['error_msg'])){ echo '<div class="error">'.$_SESSION['error_msg'].'</div>'; unset($_SESSION['error_msg']); } } ?> <fieldset style="margin:20px;width:350px;height:450px;background-color:none;"> <legend>Contact Us</legend> <ol> <li> <label for="your_name">Your Name</label> <input type="text" name="your_name" size="50" class="textbox" <?php if (isset($errors['your_name'])){echo 'class="input_red"';}?> <?php if (isset($fields['your_name'])){echo 'value="'.$fields['your_name'].'"';}?>/> <?php if (isset($errors['your_name'])){ echo '<span class="error_box"> '.$errors['your_name'].'<span class="error-pointer"> </span></span>';}else{?> <span class="hint">Tell us your name! It's nice to meet you!<span class="hint-pointer"> </span></span> <?php } ?> </li> <div class="clear"></div> <li> <label for="your_date">Your Date</label> <input type="text" name="your_date" size="50" class="textbox" <?php if (isset($errors['your_date'])){echo 'class="input_red"';}?> <?php if (isset($fields['your_date'])){echo 'value="'.$fields['your_date'].'"';}?>/> <?php if (isset($errors['your_date'])){ echo '<span class="error_box"> '.$errors['your_date'].'<span class="error-pointer"> </span></span>';}else{?> <span class="hint">Let's keep in touch!<span class="hint-pointer"> </span></span> <?php } ?> </li> <div class="clear"></div> <li> <label for="your_message">Your Message</label> <textarea rows="3" cols="40" name="your_message" class="textarea"<?php if (isset($errors['your_message'])){echo 'class="input_red"';}?>><?php if (isset($fields['your_message'])){echo $fields['your_message'].'</textarea>';}else{echo '</textarea>';}?> <?php if (isset($errors['your_message'])){ echo '<span class="error_box"> '.$errors['your_message'].'<span class="error-pointer"> </span></span>';}else{?> <span class="hint">What's on your mind?<span class="hint-pointer"> </span></span> <?php } ?> </li> <li> <input name="uploadedfile[]" type="file" /> </li> <li> <input name="uploadedfile[]" type="file" /> </li> <li> <input name="uploadedfile[]" type="file" /> </li> <?php $random_string = random_string(32); //This will return a random 10 character string?> <input type="hidden" value="<?php echo $random_string;?>" name="id"/> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> <div class="submit_box"> <input type="submit" value="Get in touch with us!" name="submit" class="submit"> </div> </ol> </fieldset> </form> Can anyone help me with the "if it exists, move on, if it doesnt, create folder" part? |