Jump to content

michytttt

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

michytttt's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok got it! $sql2 = "UPDATE emails SET stats = (stats + 1) WHERE id='$id'"; $result2 = mysql_query($sql2); Thanks for your help it would have taken me ages otherwise!
  2. It seems to be working! The database is adding one however I get this error now when I submit the form: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/60/7908160/html/apply-for-job5.php on line 280 The code is as follows: if($_SERVER['REQUEST_METHOD']== 'POST'){ $sql2 = "UPDATE emails SET stats = (stats + 1) WHERE id='$id'"; $result2 = mysql_query($sql2);while ($row = mysql_fetch_assoc($result2)) { $stats = $row['stats']; }
  3. Ok I think this is starting to make sense to me I have this so far: if($_SERVER['REQUEST_METHOD']== 'POST'){ $sql2 = UPDATE emails SET stats = stats + 1 WHERE id='$id'"; Is this looking right?
  4. Oh right I see. yes I currently have a form that is sent to a specific email address. The email address is selected from the database - depending on what the id is. This all works fine. What I would like to now add is everytime an email is sent to one of the email address from the database the stats is +1 so that I can track how many emails have been sent to each address.
  5. Sorry I am a bit confused...would I add this to the same bit of code?
  6. Hi, I am trying to update the record in the database
  7. Hello everyone, I think what I am hoping to do should be fairly simple, although I a struggling getting the code correct. I have a row in a database table called stats and another one called id - as well as a load of other rows which are irrelevant to what I am trying to achieve here. What I am hoping to do is that when a specific id is selected from the database the stats number is what ever it was orginally +1. Any suggestions? The part of the code I am refering to is below: $sql = "SELECT email, title FROM emails WHERE id='$id'"; $result = mysql_query($sql);while ($row = mysql_fetch_assoc($result)) { $to = $row['email']; $job = $row['title']; $row['stats'] == + 1; //this is the part that I know is completely wrong! everything else works fine. Just need this to say plus one onto the orginal number.... } MOD EDIT: corrected BBCode tags . . .
  8. Sorry for late reply. The form seems to work but I do not receive the email to the required address.
  9. You have been really helpful, I have got the following so far but I cannot seem to get it to work: <?php $username = "username"; $password = "password"; $hostname = "localhost"; $id = $_GET['id']; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; $selected = mysql_select_db("db",$dbhandle) or die("Could not select db"); $sql = "SELECT email FROM emails WHERE ID='$id'"; $result = mysql_query($sql);while ($row = mysql_fetch_assoc($result)) { $to = $row['email'];} ?> The form begins: <?php function spamcheck($field) { $field=filter_var($field, FILTER_SANITIZE_EMAIL); if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } function validate_form() { $errors = array(); if(!(isset($_POST['name']) && (strlen($_POST['name']) > 3))){ $errors['name'] = '<span style="color:red; font-size:12px">*Please enter a contact name</span>'; } if(!(isset($_POST['address']) && (strlen($_POST['address']) > 3))){ $errors['address'] = '<span style="color:red; font-size:12px">*Please enter a valid e-mail address</span>'; } $mailcheck = spamcheck($_POST['address']); if ($mailcheck==FALSE) { $errors['address'] = '<span style="color:red; font-size:12px">*Please enter a valid e-mail address</span>'; } if(!(isset($_POST['telephone']) && (strlen($_POST['telephone']) > 3))){ $errors['telephone'] = '<span style="color:red; font-size:12px">*Please enter a contact No</span>'; } $phone = ereg_replace('[^0-9]', '', $_POST['telephone']); if (!filter_var($phone, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) { $errors['telephone'] = '<span style="color:red; font-size:12px">*Please enter a contact No</span>'; } if(!(isset($_POST['message']) && (strlen($_POST['message']) > 3))){ $errors['message'] = '<span style="color:red; font-size:12px">*Please include your message</span>'; } return $errors; } function display_form($errors) { $defaults['name']= isset($_POST['name']) ? htmlentities($_POST['name']) : ''; $defaults['address']= isset($_POST['address']) ? htmlentities($_POST['address']) : ''; $defaults['telephone']= isset($_POST['telephone']) ? htmlentities($_POST['telephone']) : ''; $defaults['message']= isset($_POST['message']) ? htmlentities($_POST['message']) : ''; ?> <!--name of page with form on--> <form action='apply-for-job5.php' method='post'> <table border="0" cellpadding="2" cellspacing="0" class="tablecolour" > <tr> <td width="38%" valign="top">Name*</td> <td width="62%"> <input type='text' name='name' value='<?php echo $defaults['name']?>'/> <?php print_error('name',$errors)?><br/></td> </tr> <tr> <td valign="top"><label for="tswemail"> Email Address* </label></td><td><input type='text' name='address' value='<?php echo $defaults['address']?>'/> <?php print_error('address',$errors)?><br/></td> </tr> <tr> <td valign="top"><label for="tswphone"> Contact Number* </label></td><td> <input type='text' name='telephone' value='<?php echo $defaults['telephone']?>'/> <?php print_error('telephone',$errors)?><br/></td> </tr> <tr> <td valign="top"><label for="tswcomments"> Your Message*</label><br /></td> <td valign="top"> <textarea rows="5" cols="47" name="message"> <?php echo $defaults['message']?></textarea> <?php print_error('message',$errors)?><br/></td> </tr> <tr> <td height="32" valign="top">*Required Fields </td> <!--change button name here--> <td valign="top" align="right"><input type="submit" value="Send" /></td> </tr> </table> </form> <?php } function print_error($key, $errors){ if(isset($errors[$key])){ print "<dd class='error'>{$errors[$key]}</dd>"; } } if($_SERVER['REQUEST_METHOD']== 'POST'){ $errors = validate_form(); if(count($errors)){ display_form($errors); }else{ echo '<h1 class="h1blue">Thankyou...'.ucwords($_POST['name']).' A member of our team will contact you shortly</h1>'; //===========Email address her=========// $subject = "Email Request"; $message = 'Contact Name: '.$_POST['name']; $message.= "\n".' Message: '.$_POST['message']; $message.= "\n".' Telephone no: '.$_POST['telephone']; $from = $_POST['address']; $headers = "From: $from"; mail($to,$subject,$message,$headers); } }else { display_form($errors); } ?> Hope this helps! MOD EDIT: code tags added.
  10. Sorry to be a pain but how would I tell it that the $to is to collect the correct email?
  11. Yes it does make some sense to me so the link would be something like www.mydomainname.co.uk/form.php?id=222 the $id = $_GET['id'] will grab this unique id then the SELECT Email FROM Your_Table WHERE ID='$id' will find the relevant email I think I get this thanks. In the actual form itself how would I tell it to send it to the relevant email address? Is it in the mail($to,$subject,$message,$headers); part? Thanks for all your advice!
  12. Hi Everyone, Very new to PHP and databases, so please go easy on me! I have a series on web pages each containing a link that says 'apply here'. What I am trying to achieve is when any of these links are clicked on the user is taken to a php form page where they are asked for a series of further information such as name, telephone number etc. When they click submit this information then gets sent off to a speciifc email address. My problem is that depending on which page the user has originally come from (the page where they clicked on the apply here link) needs to determine what email address the form information gets sent to. I thought that the best way to achieve this would be to create a database that contains all of the email addresses (as eventually there will be alot of them) and the form page could call in the relevant email somehow... although I am totally confused on how to go about doing this. Any help would be great! Thankyou.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.