PHP - Code E-mails Me Twice
I'm using this code to create and populate a database.
It gets a bit involved as it is creating a series of times for every day in the year. The database gets created and populated just fine, however I have 2 quirks I can't figure out. First, I am creating a separate file to store connection creds to the database. The file gets created and holds the correct information, but as I am using the program, somehow the file is getting overwritten with blank spaces, making it impossible to connect to the database. 2nd, the program sends me an e-mail when the database is created. Problem is I'm getting 2 e-mails about 20 minutes apart. 1 with all the correct information and 1 blank. I'm thinking maybe these problems are related??? Like the program is trying to run itself twice or is getting called twice. Once the program runs, it never gets called again in any other part of the program code. Any ideas? Thanks. Code: [Select] <?php $coursename = $_POST["coursename"]; $websiteurl = $_POST["websiteurl"]; $email = $_POST["email"]; $otime = $_POST["opentime"]; $ctime = $_POST["closetime"]; $interval = $_POST["interval"]; $year = $_POST["year"]; $server = $_POST["server"]; $username = $_POST["username"]; $password = $_POST["password"]; $userpassword = $_POST["userpassword"]; //--Creates a file to store Login Information--\\ $data = <<<DATA <?php \$server = "$server"; \$username = "$username"; \$password = "$password"; ?> DATA; file_put_contents("databasedata.php", $data); //--Connect to the Server--\\ mysql_connect("$server", "$username", "$password"); //--Create the Database--\\ mysql_query("CREATE DATABASE IF NOT EXISTS TeeTimes"); mysql_select_db("TeeTimes"); //--Create the Tables--\\ mysql_query("CREATE TABLE IF NOT EXISTS CourseInfo ( Course_ID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(Course_ID), CourseName varchar(40) NOT NULL default '', HomePage varchar(50)NOT NULL default '', Email varchar(50) NOT NULL default '', Password varchar(20) NOT NULL default '' )"); mysql_query("CREATE TABLE IF NOT EXISTS Daysheets$year ( Sheet_ID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(Sheet_ID), Date date NOT NULL, Time time NOT NULL, Player1 varchar(30) NOT NULL default '', Cart1 varchar(3) NOT NULL default '', Player2 varchar(30) NOT NULL default '', Cart2 varchar(3) NOT NULL default '', Player3 varchar(30) NOT NULL default '', Cart3 varchar(3) NOT NULL default '', Player4 varchar(30) NOT NULL default '', Cart4 varchar(3) NOT NULL default '', Player5 varchar(30) NOT NULL default '', Cart5 varchar(3) NOT NULL default '', Men smallint(4) NOT NULL default 0, Women smallint(4) NOT NULL default 0, Guest smallint(4) NOT NULL default 0, Event varchar(3) NOT NULL default '', EventName varchar(30) NOT NULL default '' )"); //***To Populate the Database with Dates and Times***\\ mysql_query(" INSERT INTO CourseInfo (CourseName,HomePage,Email,Password) VALUES('$coursename','$websiteurl','$email','$userpassword')"); $rows = mysql_query("SELECT * FROM Daysheets$year"); if ($rows[Date]=="") { $firstday = "$year:01:01 $otime:00:00"; $firstdate = strtotime($firstday); $firsttime = "$year:01:01 $otime:00:00"; $opentime = strtotime($firsttime); $lasttime = "$year:01:01 $ctime:00:00"; $closetime = strtotime($lasttime); $time = date("g:i",$opentime); $i=1; //***To Account For Leap Years***\\ if ($year == 2012 || $year == 2016 || $year == 2020 || $year == 2024) {$n=366;} else {$n=365;} while ($i <= $n) { $newday = date("Y-m-d",$opentime); mysql_query(" INSERT INTO Daysheets$year (Date,Time) VALUES('$newday','$time')"); while ($opentime < $closetime) { $newtime = strtotime("+$interval minute", $opentime); $nexttime = date("Y-m-d g:i a",$newtime); $nextd = date("Y-m-d",$newtime); $nextt = date("g:i",$newtime); mysql_query(" INSERT INTO Daysheets$year (Date,Time) VALUES('$nextd','$nextt')"); $opentime = strtotime($nexttime); } $opentime = strtotime($firsttime); $newday = strtotime("+$i day", $opentime); $nextday = date("Y-m-d g:i a",$newday); $opentime = strtotime($nextday); $closetime = strtotime($lasttime); $newday = strtotime("+$i day", $closetime); $nextday = date("Y-m-d g:i a",$newday); $closetime = strtotime($nextday); $i++; } } mysql_close(); //--Send Information for Safekeeping--\\ $to = "someone@somewhere.org"; $subject = "Tee Time Maker User Info"; $message = "Course Name:' '$coursename \n Website: ' '$websiteurl \n E-Mail: ' '$email \n Password: ' '$userpassword"; mail($to, $subject, $message, "From: $coursename <$email>"); //--Redirect user to the newly created site--\\ header("Location: /teetimes/adminteetimes.php"); ?> Similar TutorialsI 'm having some problem while sending mails . i am sending bulk mails using php script, der is no problem in the script. i hope some guys have faced similar issue. while i am sending bulk emails, i figured out that - few mails are going to spam not into their INBOX. can you guys pls give some hint to resolve this issue. .. A form is filled and the information is emailed to my address. The problem is it goes to the spam folder. Is it a problem with the email filter? I suppose I could whitelist the email address the server uses to email the info, but then spam would get through as well. Any ideas? I've been using something like this to send email messages to users on a site: $to = $email; $subject = "Message From Microsoft.com\r\n"; $headers = "From: support@Microsoft.com\r\n"; $headers .= "Return-Path: support@Microsoft.com\r\n"; $headers .= "Reply-To: support@Microsoft.com\r\n"; $message = "<html><body><img src='http://www.Microsoft.com/images/logo.png' /><br /><br />You have a message from Bill:<br /><br />"; $message .= '<img src="' . $image . '" /><br /><br />'; $message .= 'Isn't it pretty?.<br /><br />'; $message .= '<a href="http://www.Microsoft.com">Microsoft.com</a></body></html>'; mail($to,$subject,$message,$headers); This sends, literally, text like this: <html><body><img src='http://www.Microsoft.com/images/logo.png' /><br /><br />You have a message from Bill:<br /><br /><img src="http://www.Microsoft.com/images/billiam.jpg" /><br /><br />Isn't it pretty?.<br /><br /><a href="http://www.Microsoft.com">Microsoft.com</a></body></html> Obviously, I would like the email to hide the HTML, but use it to format the output. Also, I'd obviously like the image to show up, not a link to the image, and I would like the link to show up as a link, not as HTML. How do I do this? Cheers. Hi, I'm developing a php newsletter software but I'm in trouble with bounce mails! I set a return path directing them into a specific email box then I read that email box with php and I process bounce mails to get the kind of problem. Well, I need to get some informations about those bounce emails: The name of the user that should recive that mail, the date when the mail has been sent, the kind of error encountered; It could be so easy if I could read the body of the mail I sent into the back bounce one but every server sends a different kind of bounce...for example mailer-daemon won't let me get the body of the sent message...how can I handle this? Andrea. Hello I am working on php website. Now here im working on sending orders. So once it is ordered the confirmation e-mail goes to one who ordered(he enters his e-mail id manually) and the head of the department(e-mail ids written in code). But now I have put a checkbox that if the person is head of the department he checks the checkbox and e-mail should be sent to him. So how to verify this by checkbox.Can anyone please help me with this. The person should not get 2 e-mails. I hope I was clear in explaining my doubt. If not please do ask me for more explanation. Thank you. I have this script that sends an E-mail to my custoemr when an account is created and does a Bcc to me. Every email gets sent once, then about 2 min later another one is sent. So both the customer and myself get 2 emails. I did a test and just after the mail() function i write to a text file. What is odd is that it logs the sent mail 2 times. So somehow it is going through it a second time. The time difference between the first and the second seem to usually be about 2-3 min. For exampel this was only sent one time. My guess is there has to be something wrong with my headers, but i have been over them many times and tried different configurations. To: ben@....com Time 05/12/2011 12:18:30 am To: ben@...com Time 05/12/2011 12:21:09 am Code: [Select] <?php $db_con = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($database, $db_con); if((isset($_POST['password'])) && ($_POST['password'] == 'mandb108' )) { $install_date = date("Y-m-d"); $end = mktime(0, 0, 0, date("m"), date("d"), date("y")+1); $end_date = date("Y-m-d", $end); $folder = $_POST['folder']; $school_db = $_POST['school_db']; $school_name = $_POST['school_name']; // Check to see if school, db or folder exists if (mysql_num_rows(mysql_query("Select * FROM $select_table WHERE `school_name` = '$school_name'"))) { $message = 'School Name Already Exists in Database'; } elseif (mysql_num_rows(mysql_query("Select * FROM $select_table WHERE `school_db` = '$school_db'"))) { $message = 'Database Already Exists'; } elseif (mysql_num_rows(mysql_query("Select * FROM $select_table WHERE `school_folder` = '$folder'"))) { $message = 'School Folder Already Exists'; } else { ////////////////////id, school, db, folder, install, renew, end, contact, email, job, notes $insertSQL = sprintf("INSERT INTO $select_table VALUES (null, %s, %s, %s, %s, '$install_date', null, '$end_date', %s, %s, null, null)", GetSQLValueString($_POST['school_state'], "text"), GetSQLValueString($_POST['school_name'], "text"), GetSQLValueString($_POST['school_db'], "text"), GetSQLValueString($_POST['folder'], "text"), GetSQLValueString($_POST['contact'], "text"), GetSQLValueString($_POST['email'], "text")); mysql_select_db($database, $db_con); if($Result1 = mysql_query($insertSQL, $db_con) or die(mysql_error())) { $message = 'Added to Database - Successful<br>'; } else { $message = 'Added to Database - Failed<br>'; } // Funcatiobn to copy sampel folder to new directory for school full_copy("01_sample","$folder"); // Echo results $message .= 'Install Date - '.$install_date; $message .= '<br>'; $message .= 'Expire Date - '.$end_date.'<br>'; $message .= 'Copy of Folder - Successful<br>'; $message .= '<br><br>School - '; $message .= $_POST['school_name']; $message .= '<br>Database - '; $message .= $_POST['school_db']; $message .= '<br>Folder - '; $message .= $_POST['folder']; $message .= '<br>Contact - '; $message .= $_POST['contact']; $message .= '<br>Email - '; $message .= $_POST['email']; // Write to school_info file $open = fopen ("$folder/school_info.php", "at"); fwrite($open, "<?php\n$".$old); fwrite($open, "school_folder = '$folder';\n$".$old); fwrite($open, "school_db = '$school_db';\n$".$old); fwrite($open, "database = $".$old); fwrite($open, "school_db;\n?>".$old); fclose($open); // Link to create a database on voting site $message .= '<br><a href="http://www.anaheimartscouncil.com:2082/frontend/x3/sql/index.html" target="_blank">Cpanel</a><br>'; // link to setup Database tables on new site $message .= '<br><a href="'.$folder.'/index.php?install=yes&school='.$school_name.'" target="_blank">Database Setup</a><br>'; // link to send email to client $message .= '<br><a href="web_install.php?email=yes&school_db='.$school_db.'">Send E-mail</a><br><br>'; }// end if school name, databae or folder already exists } elseif ((isset($_GET['email'])) && ($_GET['email'] == 'yes')) { $school_db = $_GET['school_db']; $results = mysql_query("select * from tbl_schools_vote WHERE school_db = '$school_db' LIMIT 1"); // removed the while loop to get rid of duplicate emails. //while($row = mysql_fetch_array($results)){ $row = mysql_fetch_array($results); $school_contact = $row['school_contact']; $school_folder = $row['school_folder']; $school_contact_email = $row['school_contact_email']; //} // end while loop $email_message = 'Dear '; $email_message .= $school_contact; $email_message .= ',<br>'; $subject = "Voting 4 Schools - Account Activated"; $email_message .= 'Your Voting 4 Schools account has been setup. Below is all the information that you should need to get started.<br><br> Here is a link to your voting site. <a href="http://www.voting4schools.com/'.$school_folder.'">www.voting4schools.com/'.$school_folder.'</a><br><br>At the bottom of the page you will find an admin link. The user name and password are as follows<br><br>User Name: admin<br>Password: vote<br><br>When you log in please go to the control panel and create a new admin user and delete the default one that we have assigned you. At the top of the page you will find a link that says video tutorial. If you are unsure how to use the software, this is a great place to start. If you have any questions, or need help setting it up, please let us know.<br><br>Thank You,<br>Ben Star<br><br>Software 4 Schools<br>(866)757-7226<br><a href="http://www.software4schools.com">www.software4schools.com</a>'; // website link here //$to = $school_contact_email.', support@software4schools.com'; $to = $school_contact_email; //$email = 'support@software4schools.com'; //$headers = "To: ".$school_contact_email."\r\n"; //$headers .= "From: Software 4 Schools <support@software4schools.com>" . "\r\n"; //$headers .= "Bcc: Software 4 Schools <support@software4schools.com>" . "\r\n"; //$headers .= "MIME-Version: 1.0" . "\r\n"; //$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; $headers = 'From: michael@anaheimartscouncil.com' . "\r\n" . 'Reply-To: anaheimartscouncil.com' . "\r\n" . 'Bcc: ben@software4schools.com' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1'; //. "\r\n"; //. 'X-Mailer: PHP/' . phpversion(); if (mail($to, $subject, $email_message, $headers)) { $date = date('m/d/Y h:i:s a', time()); $myFile = "mail.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); $stringData = "To: ". $to."\n"; fwrite($fh, $stringData); $stringData = "Time ". $date."\n\n"; fwrite($fh, $stringData); fclose($fh); $message = 'E-mail was sent once'; }else { $message = 'Problem sending message'; } } elseif ((isset($_POST['password'])) && ($_POST['password'] != 'mandb108' )) { $message = 'Password is incorrect'; $folder = $_POST['folder']; $school_db = $_POST['school_db']; $school = $_POST['school']; $contact = $_POST['contact']; $email = $_POST['email']; } else { // not sure what to do here yet... } // end if password isset from post if (!isset($_POST['school_db'])) { $school_db = 'voting_'; } ?> how to tell gmail to send plan messages only i want to send my friend a pgp-crypted mail - but this fails since the html-based mails allways do some changes to the pgp my friend receives the mails in a broken style they are not readable any more plz advice me - any and all help is much appreciated by the way i use kgpg and the editor to create the crypted message. i do not like the enigmail-addon for tbird. + But if i should try this - : Which credentials are needed to configure the einigmail - the public key that i have generated recently. love to hear from you greetings hi, im new here i hope to learn and help in the way i can since i'm a newbie with php but here it goes. I have some old databases i need to test, i want to mail these old users from a website i had but i need to know if the database contains invalid e-mails and remove them so i dont mess up my server's good ip reputation. So i found the checkdnsrr function: Code: [Select] function checkEmail($email) { // checks proper syntax if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) { // gets domain name list($username,$domain)=split('@',$email); // checks for if MX records in the DNS if(!checkdnsrr($domain, 'MX')) { return false; } return true; } return false; } so everyone knows this function, i just wanted to run it to multiple e-mail addresses like from a text file. when i say multiple, i mean arround 500.000 or 50k at the time. i just want to output the bad e-mails to a text file. hope someone can help me on this one. thanks in advance I have an index.php code. The code doesn't recognize UTF-8. The php identify the right part (one txt has many infos) from a .txt file and send that information to browser. Can I send this information to a specific email address instead of browser? And if Yes, can I say to this code to calculate more than one day but for more? Is this possible? Please help me with that. Thanks! [attachment deleted by admin] I'm building a PHP application that's connect to gmail and download the messages. I have an account that contains more than two millions messages and the PHP cannot connect to that account. What can I do? The error is: Mailbox has more messages (2004032) exist than maximum (1000000) Hello everyone, it's my first post here. I was recommend this community for it's professionalism and "friendlyness". During my stay here, please excuse my english. I know it can be unpleasant for you to read a thread with terrible grammar, I hate it in my native language, I'll do my best. Okay, so I'm having two major issues for my website to operate like I'd like it to, I've done everything I knew about, and I can't think about anything else Google didn't help me much either this time. First one is that I seem to have a cookies/sessions problem. Well, I use Liberty Reserve to allow my members to top up their account. So I send my form to their SCI and when I either cancel or complete a transaction, I return to my website but I'm not logged in anymore! So the auto-add to balance system can't work. Alright, when I saw this I was only using sessions, so I added cookies so I could rely on them too. And there again, same thing. Doubled, tripled checked all the LR settings and everything, I know they are right. But what's really, really, weird to me and what's really doing my head in is that I'm not actually logged out, because if I use another tab/window I'm still logged in. In other words, it's only the window coming back from Liberty Reserve that won't log in. The cookies are still here and so is the session so... Another terrible thing is that it used to work when I was on my previous host (just moved to a dedicated server, which may be causing the problems, it's the first time I administrate a dedi). This is blocking my entire website from working. And my second problem is with the function mail() -there again 'caused' by new server-. I don't get any error message, or anything. The e-mails with cPanel/WHM work great. Though, I have done several tests and it never reaches my Gmail, Hotmail or Yahoo account. It did work with a Yopmail inbox though. So, I was focusing on 'why isn't it sending it' but since I just noticed it worked with Yopmail, I'm sure it is sending it and have no ideas why wouldn't it work with other e-mail service providers. I hope you understood what I meant and that, hopefully, you guys can help me out with those totally handicapping issues. Thank you, Regards. -Ben. Hello, guys. I'm using the following code to send me an automated mail in case the user find a broken link. But there are 2 problems: 1) after submitting I'd rather not disrupt their game by refreshing the page. So, is there any way to send mail without the post refreshing? 2) if the user hits F5, the page reloads and the code runs again, sending two or more times the same email. How can I avoid duplicated emails caused by manual browser refresh? (the most important solution currently is how to to avoid duplicated entries, in case an ajax solution is too hard to post here.) <form name="fbrlink" action="<?= $_SERVER['PHP_SELF']."?page=ok" ?>" method="post"> <?php echo('<input name="sbrlink" id="B1" type="button" value="broken Link?" style="border:none; background-color:#FFFFFF; font-family:Trebuchet MS; font-size:15px; font-weight:bold; color:#1A4877; cursor:pointer; display:block; text-decoration:underline;" onclick="this.form.submit();"/>'); ?> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['QUERY_STRING'] == 'page=ok') { echo '<script type="text/javascript" >confirm("Click OK to notify us.");</script>'; mail("contact@ctt.net","report broken link","Game notified:MarioBros"); echo '<script type="text/javascript" >document.fbrlink.sbrlink.disabled = true;</script>'; ?> <script type="text/javascript" >document.fbrlink.action='<?php echo $a; ?>'; alert('<?php $_SERVER['QUERY_STRING'];?>'); </script> <?php } else {} }else{ } ?> Hello, New to this forum so appreciate the patience and apologize for any breaking of etiquette. I currently have a PHP script which generates the appropriate HTML headers and body packet and would like to place it in either a Thunderbird outbox so that Thunderbird will handle sending it or put it in the Evolution outbox so Evolution will handle the actual sending of the e-mail. I've scoured the internet looking for an answer and I know it is possible because I wrote a bash script to do it a few years back that I can't find. Would appreciate any insight. Thanks, I have piping set up, where when I send an e-mail to a certain address, a script executes. This script will parse the e-mail and will post the body of the e-mails (along with a picture, if attached) to a blog. This all works okay, except the problem I keep running into is when I send from different devices (desktop, Android phone, BlackBerry), the e-mails have different character sets or encoding. So one e-mail will show up just fine, and then the body of another will look something like this: Quote --90e6ba6e83a0846c8504926b9478 Content-Type: text/html; charset=ISO-8859-1 This is the content of the e-mail. --90e6ba6e83a0846c8504926b9478-- So what I'm wondering is if there is any way to detect the charset/encoding and automatically decode it properly? The only solution I have so far -- and I'm not very good with PHP, I'll admit -- is to just "hack" my way through, by using stristr() to see if the body contains certain characters (like "ISO-8859-1"), and then extracting the text that is in between, say, "ISO-8859-1" and "--". Of course, this is very crude, and has many problems on its own. So what I am looking for is if there is some sort of way to automatically get the body of an e-mail in plain text, regardless of whether the e-mail has an attachment, how it's encoded, or what mail client was used. Thanks for your time! Hi, I Have a form after successful submission a mail must be send to particular recipient and thank you mail is send to the person who filled the form ,The problem is i am receiving mails in spam whats the reason for going in spam I have kept Capture code also Can please let me know what to do Hi, I have some code which displays my blog post in a foreach loop, and I want to add some social sharing code(FB like button, share on Twitter etc.), but the problem is the way I have my code now, creates 3 instances of the sharing buttons, but if you like one post, all three are liked and any thing you do affects all of the blog post. How can I fix this? <?php include ("includes/includes.php"); $blogPosts = GetBlogPosts(); foreach ($blogPosts as $post) { echo "<div class='post'>"; echo "<h2>" . $post->title . "</h2>"; echo "<p class='postnote'>" . $post->post . "</p"; echo "<span class='footer'>Posted By: " . $post->author . "</span>"; echo "<span class='footer'>Posted On: " . $post->datePosted . "</span>"; echo "<span class='footer'>Tags: " . $post->tags . "</span>"; echo ' <div class="addthis_toolbox addthis_default_style "> <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a> <a class="addthis_button_tweet"></a> <a class="addthis_counter addthis_pill_style"></a> </div> <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=webguync"></script>'; echo "</div>"; } ?> I have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. Advance thank you. Can you help please. The error..... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\wamp\www\test_dabase.php on line 24 code. Code: [Select] <?php //database connection. $DB = mysql_connect("localhost","root") or die(mysql_error()); if($DB){ //database name. $DB_NAME="mysql"; //select database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease change database name"); // if connection. }if($CON){ //show tables. $mysql_show="SHOW TABLES"; //select show and show. $mysql_select2="mysql_query(".$mysql_show.") or die(mysql_error())"; } //if allowed to show. if($mysql_select2){ //while it and while($data=mysql_fetch_assoc($mysql_select2)){ //show it. echo $data; } } ?> Hi, I need to insert some code into my current form code which will check to see if a username exist and if so will display an echo message. If it does not exist will post the form (assuming everything else is filled in correctly). I have tried some code in a few places but it doesn't work correctly as I get the username message exist no matter what. I think I am inserting the code into the wrong area, so need assistance as to how to incorporate the username check code. $sql="select * from Profile where username = '$username'; $result = mysql_query( $sql, $conn ) or die( "ERR: SQL 1" ); if(mysql_num_rows($result)!=0) { process form } else { echo "That username already exist!"; } the current code of the form <?PHP //session_start(); require_once "formvalidator.php"; $show_form=true; if (!isset($_POST['Submit'])) { $human_number1 = rand(1, 12); $human_number2 = rand(1, 38); $human_answer = $human_number1 + $human_number2; $_SESSION['check_answer'] = $human_answer; } if(isset($_POST['Submit'])) { if (!isset($_SESSION['check_answer'])) { echo "<p>Error: Answer session not set</p>"; } if($_POST['math'] != $_SESSION['check_answer']) { echo "<p>You did not pass the human check.</p>"; exit(); } $validator = new FormValidator(); $validator->addValidation("FirstName","req","Please fill in FirstName"); $validator->addValidation("LastName","req","Please fill in LastName"); $validator->addValidation("UserName","req","Please fill in UserName"); $validator->addValidation("Password","req","Please fill in a Password"); $validator->addValidation("Password2","req","Please re-enter your password"); $validator->addValidation("Password2","eqelmnt=Password","Your passwords do not match!"); $validator->addValidation("email","email","The input for Email should be a valid email value"); $validator->addValidation("email","req","Please fill in Email"); $validator->addValidation("Zip","req","Please fill in your Zip Code"); $validator->addValidation("Security","req","Please fill in your Security Question"); $validator->addValidation("Security2","req","Please fill in your Security Answer"); if($validator->ValidateForm()) { $con = mysql_connect("localhost","uname","pw") or die('Could not connect: ' . mysql_error()); mysql_select_db("beatthis_beatthis") or die(mysql_error()); $FirstName=mysql_real_escape_string($_POST['FirstName']); //This value has to be the same as in the HTML form file $LastName=mysql_real_escape_string($_POST['LastName']); //This value has to be the same as in the HTML form file $UserName=mysql_real_escape_string($_POST['UserName']); //This value has to be the same as in the HTML form file $Password= md5($_POST['Password']); //This value has to be the same as in the HTML form file $Password2= md5($_POST['Password2']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $Zip=mysql_real_escape_string($_POST['Zip']); //This value has to be the same as in the HTML form file $Birthday=mysql_real_escape_string($_POST['Birthday']); //This value has to be the same as in the HTML form file $Security=mysql_real_escape_string($_POST['Security']); //This value has to be the same as in the HTML form file $Security2=mysql_real_escape_string($_POST['Security2']); //This value has to be the same as in the HTML form file $sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body); echo "<h3>Your profile information has been submitted successfully.</h3>"; } mysql_close($con); $show_form=false; } else { echo "<h3 class='ErrorTitle'>Validation Errors:</h3>"; $error_hash = $validator->GetErrors(); foreach($error_hash as $inpname => $inp_err) { echo "<p class='errors'>$inpname : $inp_err</p>\n"; } } } if(true == $show_form) { ?> hey gurus, i am a newbie php coder.. i am learning by example. what i am trying to do is write a piece of code which will alter 3 tables (user, bonus_credit, bonus_credit_usage) ---------------------------------------------------------------- the table structure that will be used is as follows: user.bonus_credit user.ID bonus_credit.bonusCode bonus_credit.qty bonus_credit.value bonus_credit_usage.bonusCode bonus_credit_usage.usedBy ---------------------------------------------------------------- so lets say, in bonus_credit i have the following bonusCode = 'facebook' (this is the code they have to type to redeem the bonus qty = '10' ( number of times the bonusCode can be redeemed, but same person can't redeem it more than once) value = '5' (this is the amount of bonus_credit for each qty) Now, I need to write a code that check to see if the code has been redeemed in the bonus_credit_usage table and if the user.ID exists in this table as bonus_code_usage.usedBy, then give an error that its already been used and if it hasn't been used, then subtract 1 from qty, add ID to usedBy and then add the value to the bonus_credit ----------------------- i have started the steps just to create a simple textbox and entering a numeric value to bonus_credit, and that works.. but now i have to use JOIN and IF and ELSE.. which is a little too advanced for me.. so i'd appreciate a guide as i write the code. if(isset($_REQUEST['btnBonus'])) { $bonus_credit = addslashes($_REQUEST['bonusCode']); $query = "update user set bonus_credit=bonus_credit+'".$bonus_credit."' where id='".$_SESSION['SESS_USERID']."'"; echo "<script>window.location='myreferrals.php?msgs=2';</script>"; mysql_query($query) or die(mysql_error()); } |