PHP - Check If Email Already In Mysql Db
I am trying to check if email already in DB. This is what I have so far and does not work.
Code: [Select] if($email){ // checking user input $check_email=mysql_query("SELECT * FROM userlist WHERE email ='".$email."' "); $get_email=mysql_fetch_array($check_email); $existsmail=$get_email['email']; if($email == $existsmail){ $resultado = "Email address already exists!"; } if($email != $existsmail){ $resultado = "Your Account was created successfully! You may now login."; $date=getdate(); $insert=mysql_query("INSERT INTO userlist VALUES ('', '$name', '$phone', '$fax', '$company_name', '$billing_address', '$billing_city', '$billing_state', '$billing_zip_code', '$email', AES_ENCRYPT('$mysecretkey''password') ,now())"); }else{ $resultado = ""; } echo $resultado; } Thanks in advance. 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 I am working on a web form in PHP which accepts a Paypal Email address from the user. I need to authenticate (validate or check) if the Paypal email address entered is a valid Paypal email account. Please reply. All comments and feedback are welcomed. Thank you! does anyone have code for checking to make sure an email address is typed in correct 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 Hi all, I was just thinking that it might be possible to find out if someone read an email. If someone might want to share his thoughts on the following I would be really happy The idea i had is that instead of requiring a receipt to sign, which most free email providers don't provide. Instead send an html email with an external image with a unique name for the receiver. Ones the receiver opens the email it requests the image. This probbably isn not fool proof since someone can view in plain text, but it might be a nice thought. Is there maybe a way to track how often an image is requested and perhaps from where (IP or so). Which might not be usefull since it will come from a general email provider. This idea just popped up for me and i thought it could be nice to chat about it. If someone knows a better tracker way which is still customer friendly I would love to know : ) The idea is that in some cases it might me nice to remind someone if they didn't opn an email. Cheers! I cannot figure out why my checkbox values are not being included in my emails I am posting my html and my php.
<form method="post" action="../leaf.php"> <input type="hidden" name="subject" value="Cleanup"> <div> <table width="425" border="0" cellspacing="0" cellpadding="0"> <tr> <td><label><span class="ie7bugfix01">Name:<span class="colour">*<br /> </span></span> <input type="text" name="contact-name" class="text" value="" /></label></td> <td><label><span class="ie7bugfix01">Email:<span class="colour">*</span></span><br /> <input type="text" name="contact-email" class="text" value="" /></label></td> </tr> <tr> <td> <label><span class="ie7bugfix01">Phone No:</span> <br /> <input type="text" name="contact-mobile" class="text" value="" /></label> </td> </tr> <tr> <td><label><span class="ie7bugfix01">Address:<br /> </span> <input type="text" name="contact-street" class="text" value="" /></label></td> <td><label><span class="ie7bugfix01">City:</span><br /> <input type="text" name="contact-city" class="text" value="" /></label></td> </tr> <tr> <td><label><span class="ie7bugfix01">Property Size:<br /> </span> <input type="text" name="property-size" class="text" value="" /></label></td> </tr> <tr> <td><label><span class="ie7bugfix01">Service request:</span><br /></label> <input type="checkbox" name="projects[]" value="Lawn Maintenance"> <label for="type1">Lawn Maintenance</label> <br> <input type="checkbox" name="projects[]" value="Mulching"> <label for="type2">Mulching</label> <br> <input type="checkbox" name="projects[]" value="Gutter Cleaning/Repair"> <label for="type3">Gutter Cleaning/Repair</label> <br> <input type="checkbox" name="projects[]" value="Revitalization"> <label for="type1">Revitalization</label> <br> <input type="checkbox" name="projects[]" value="Power Washing"> <label for="type2">Power Washing</label> <br> </td><td> <br> <input type="checkbox" name="projects[]" value="Hardscapes"> <label for="type3">Hardscape</label> <br> <input type="checkbox" name="projects[]" value="Deck Work"> <label for="type3">Deck Treatments/Repair/Construction</label> <br> <input type="checkbox" name="projects[]" value="Snow Removal"> <label for="type3">Snow Removal</label> <br><input type="checkbox" name="projects[]" value="Tree Trimming"> <label for="type3">Tree Trimming/Removal</label> <br> <input type="checkbox" name="projects[]" value="Privacy Barriers"> <label for="type3">Privacy Barriers</label> </td></tr> <tr> </tr> </table> <label><span class="ie7bugfix01">Describe your project:<span class="colour">*</span></span><br /> <textarea name="contact-comments" class="text" cols="68" rows="5"></textarea></label> <p class="submit"> <input type="submit" class="submit" value="submit" /> <input type="button" class="reset" value="reset" /> </p> </div></form> <?php $from = $_REQUEST['contact-email'] ; $name = $_REQUEST['contact-name'] ; $subject = $_REQUEST['subject'] ; $headers = "From: $from"; $headers = "Subject: $subject"; $fields = array(); $fields{"subject"} = "Subject"; $fields{"contact-name"} = "Name"; $fields{"contact-email"} = "E-mail"; $fields{"contact-mobile"} = "Phone"; $fields{"contact-street"} = "Address"; $fields{"contact-city"} = "City"; $fields{"property-size"} = "Size"; $selectedProjects = 'None'; if(isset($_POST['projects']) && is_array($_POST['projects']) && count($_POST['projects']) > 0){ $selectedProjects = implode(', ', $_POST['projects']); } $body .= 'Selected Projects: ' . $selectedProjects; $fields{"contact-comments"} = "Message"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: t***@toma***.com"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. By choosing TOMA you will be able to enjoy your time off with the peace of mind that your lawn is always professionally serviced. Never worry about finding time to work in the lawn again and gain back at least 35 hours of summer this season! TOMA provides weekly as needed lawn maintenance for your home or business. We are dedicated to every detail of your unique lawn. We always arrive with sharp blades, we police your property and we make sure everything is left freshly groomed and clean. Easy to sign up, easy billing, invest in your home and time today! FREE ESTIMATES WHEN YOU CALL ________. If you have any more questions, please consult our website at www.t**.com or call _________ to get started."; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { $send = mail("t***@t**.com", $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.**t.com/thank-you.html" );} else {print "We encountered an error sending your mail, please try again"; } } } ?> 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? Hi, I need to check is the mail is sent and successfully deliver to the recipient email. here is the code : if(mail($to, $subject, $message, $headers, '-f ' . $return_path)) {echo "Sent"; }else {echo "Not Sent";} Please help me, its urgent. Thanks in advance. 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. Hello, I'm currently using this code to check for blank fields: if(isset($_POST['submit'])) { $emailconfirm = $_POST['emailconfirm']; $user_message = $_POST['message']; $name = $_POST['name']; $visitor_email = $_POST['email']; if(empty($name)|| empty($visitor_email)|| empty($user_message)) { $errors .= "<div id='contact_form_errorloc' class='err1'>Some of the above fields have not been filled in.</div><br>"; } This however, does not check for valid emails, I've found this code: function is_valid_email($email) { $result = TRUE; if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) { $result = FALSE; } return $result; } My question was if the above is possible aswell as incorporating the blank field checks. Many thanks! 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."; ?> I have made a form that asks a user for email, first name, last name, and password. I am using Spry validation tools in Dreamweaver. When I used those only, I did not have a problem. The problem began once I tried to actually check to see if the email was already registered. I have tried changing so many things like what $_POST variable to look for at the beginning, to different db connection arrangements. I am stumped. The only other thing I can think of is that I have the order wrong somehow in the logic. Thanks for the help. First, here is the form: Code: [Select] Enter Email<?php if($error_email_taken) echo ": $error_email_taken."; ?> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="email" type="text" id="email" value="<?php if($_POST["email"]) echo $_POST["email"]; ?>"> <input name="first" type="text" id="first" value="<?php if($_POST["first"]) echo $_POST["first"]; ?>"> <input name="last" type="text" id="last" value="<?php if($_POST["last"]) echo $_POST["last"]; ?>"> <input name="pass" type="password" class="formText1" id="pass" value="<?php if($_POST["pass"]) echo $_POST["pass"]; ?>"> <input type="submit" name="Submit" value="Submit"></td> </form> And the email verification and insert, which is placed before the opening html tag. Code: [Select] <?php if($_POST['Submit']) { //Check to see if email is registered. $email = $_POST['email']; $dbc=mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $q_1 = "SELECT users_email FROM table WHERE users_email = $email"; $r_1 = mysqli_query($dbc, $q_1); $rows_1 = mysqli_num_rows($r_1); if ($rows_1 == 0) { //If 0, email is not already registered. $new_email = $_POST['email']; } else { $error_email_taken = "This email is already registered."; } //If everything is good, insert the information. if(isset($new_email)) { $first_name = $_POST['first']; $last_name = $_POST['last']; $password = $_POST['pass']; //Insert User information. $q_2 = "INSERT INTO table (users_email, users_first, users_last, users_pass) VALUES ('$new_email', '$first_name', '$last_name', '$password')"; $r_2 = mysqli_query($dbc, $q_2); //Go to new page if form was submitted and information properly inserted. header('Location: new_page.php'); }//End: if($new_email) } //End: if $_POST['submit'] ?> I've simplified it as much as I could. I totally eliminated stuff like a password hash, etc. because I wanted to get it down to the most simple form, so once this gets working, I'll add that other stuff later. Thanks so much again. 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(); ?> I tried adding a group field to my user table so I can show different content to different users but when I do the check and then if/else the required info it doesn't seem to do it. I think I've got a mistake in my query: <?php include ('header.php'); ?> </center> <?php $username = mysql_real_escape_string($_POST['username']); $checkadmin = mysql_query("SELECT Group FROM users WHERE Username = '".$username."'"); if('$checkadmin' == GroupA) { ?> Welcome Admin! <?php } else { ?> You are not authorised. <?php } include ('footer.php') ?> Whats wrong with it? Cheers. Hi guys, I'm recent working on my php to add the row in mysql database. I need a bit of your help as I would like to know how to check the data in mysql database if it have added in mysql and then print it out without adding another same row? here's the current code: Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $pass = clean($_GET['pass']); $login = clean($_GET['login']); $all = clean($_GET['all']); if($username == '' && $pass == ''){ // both are empty $errmsg_arr[] = 'Username and password are missing. You must enter both or the other one.'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['user'])) { $insert[] = 'username = \'' . clean($_GET['user']) .'\''; } if(isset($_GET['pass'])) { $insert[] = 'pass = \'' . clean($_GET['pass']) . '\''; } if(isset($_GET['login'])) { $insert[] = 'LoggedUser = \'' . clean($_GET['login']) . '\''; } if(isset($_GET['all'])) { $insert[] = 'all = \'' . clean($_GET['all']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if($username) { $qrytable1="SELECT username, LoggedUser FROM Online_Users WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='LoggedUser'>"; echo $row['LoggedUser'] . "</p>"; } } if($username && $login == '1') { $sql="INSERT INTO Online_Users (username, LoggedUser) VALUES ('$_GET[user]','$_GET[login]')"; $result = mysql_query($sql); if($result) { $qrytable1="SELECT username, LoggedUser FROM Online_Users WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='LoggedUser'>"; echo $row['LoggedUser'] . "</p>"; } } } elseif($username == 'all') { $names = implode(',',$insert); $result = mysql_query("SELECT * FROM Online_Users") or die('Error: ' . mysql_error()); $num_rows = mysql_num_rows($result); echo "There are $num_rows Users Online right now"; } } } ?> Hello All, I am new to PHP and I am trying to modify a already written script since I want to add a checkbox to my site. In the front end I have Code: [Select] <input type="checkbox" name="privateurlcheck" id="privateurlcheck" value="0"> in the php I have var privateurlcheck = document.getElementById( "privateurlcheck" ).value Then in the mysql data insert php page, $records[channel_protected] = $postData[privateurlcheck] ; In MySQL "channel_protected" field is "ENUM" with Values '0','1' When I run the code I see 0 in the MySQL channel_protected field even when I check the checkbox. All other values that are passed on to mysql such as name, age are posted correctly without any issues. Can you please let me know how can I get 0 or 1 in the mysql depening on the checkbox status? It is 5AM and I am trying to figure this for 2nd consecutive day! Greatly appreciate if any one can help me out. I have this script running: <?php $query = mysql_query("SELECT * FROM jobs WHERE event = 'Yes' ORDER BY title"); while ($row = mysql_fetch_array($query)) { ?> How do I check if a field is empty and NOT display it...? For instance it has a 'applied' field, if that is empty I dont want it to display, however I still need the event = 'Yes' part. Hi guys, I need your help. I am checking on a database as I want to see if I have the same value in the url and in the database. Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $test = clean($_GET['test']); $public = clean($_GET['public']); if (isset($_GET['user']) && (isset($_GET['pass']))) { if($username == '' || $password == '') { $errmsg_arr[] = 'username or password are missing'; $errflag = true; } } elseif (isset($_GET['user']) || (isset($_GET['test'])) || (isset($_GET['public']))) { if($username == '' || $test == '' || $public == '') { $errmsg_arr[] = 'user or others are missing'; $errflag = true; } } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if ($username && $password) { if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, test, links, Public FROM user_list WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='test'>"; echo $row['test'] . "</p>"; echo '<p id="images"> <a href="images.php?test=test&id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?test=test&id='.$row['id'].'">Delete</a> </td> | <span id="test">'.$row['Public'].'</td>'; } } else { echo "user not found"; } } elseif($username && $test && $public) { $qry="SELECT * FROM members WHERE username='$username'"; $result1=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result1) > 0) { $qrytable1="SELECT Public FROM user_list WHERE username='$username' && test='$test'"; $result2=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result2) > 0) { $row = mysql_fetch_row($result2); mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'"); echo "update!"; } else { echo "already updated!"; } } else { echo "user not found"; } } } ?> This is the function I use to check the value in the database: Code: [Select] if (mysql_affected_rows($result2) > 0) { mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'"); echo "you have update it!"; } else if (mysql_affected_rows($result2) < 0) { echo "it is not on the database"; } else { echo "you have already updated!"; } When i input the different value in a url bar while the records are not the same as the value in the url and in the database, i can't get passed and I am keep getting "you have already updated!!" when the value in a database are different than I have input in a url. Do you know how i can get pass it when I have input the different value in the url while it is not the same in the database? Any advice would be much appreicated. Thanks, Mark This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=347295.0 im developing a voting system where you can vote for multiple choices using checkboxes.. upon submitting the vote form, votecounts must automatically be updated.. values for votecount will come from the checkbox value 1. ive been having a hard time trying to figure out hot to update multiple rows with checkbox values..any help would be appreciated..thanks in advance! here's the code: Code: [Select] $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form_vote")) $i=1;{ while ($i<= $totalRows_rs_candi) { $updateSQL = "UPDATE tbl_candidates SET votecount={$_POST['votecount']} WHERE user_id={$_POST['candi']}"; mysql_select_db($database_organizazone_db, $organizazone_db); $Result1 = mysql_query($updateSQL, $organizazone_db) or die(mysql_error()); $i++; } if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo = "vote_success.php"; } header(sprintf("Location: %s", $updateGoTo)); } Code: [Select] <form id="form_vote" name="form_vote" method="POST" action="<?php echo $editFormAction; ?>"> <table border="1"> <tr> <td> </td> <td>user_id</td> <td>l_name</td> <td>course_id</td> <td>yearlevel</td> <td>about</td> </tr> <?php $i=1; do { ?> <tr> <td><span id="sprycheckbox1"> <input name="votecount[<?php echo $i ?>]" type="checkbox" id="votecount" value="1" /> <span class="checkboxMinSelectionsMsg">Minimum number of selections not met.</span></span> <label for="votecount[]"></label></td> <td><label for="candi"></label> <input name="candi" type="text" disabled="disabled" id="candi" value="<?php echo $row_rs_candi['user_id']; ?>" readonly="readonly" /></td> <td><?php echo $row_rs_candi['l_name'].' ,'.$row_rs_candi['f_name'].' '.$row_rs_candi['m_name']; ?></td> <td><?php echo $row_rs_candi['course_id']; ?></td> <td><?php echo $row_rs_candi['yearlevel']; ?></td> <td><?php echo $row_rs_candi['about_me']; ?></td> </tr> <?php $i++; ?> <?php } while ($row_rs_candi = mysql_fetch_assoc($rs_candi)); ?> </table> |