Jump to content

jeliot

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Everything posted by jeliot

  1. jeliot

    PHP mail

    [!--quoteo(post=363132:date=Apr 9 2006, 06:51 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 9 2006, 06:51 PM) [snapback]363132[/snapback][/div][div class=\'quotemain\'][!--quotec--] OK you're closing the connection to the database after running a query then counting the result. Any further calls to the database will not work as there is no longer a connection. What you need to do is keep the connection open then use something like this: [code]$header="From: Ggap <jason@domain.com>\r\n"; $body="This is a test email for Ggap New Show Reminders"; $subject="Ggap Show Reminder"; $query=mysql_query("SELECT email FROM email_list"); while ($fetch=mysql_fetch_array($query)) {   $email=$fetch[email];   if (!mail($email,$subject,$body,$header)) {echo "Email failed for $email<br>";} }[/code] Then close the connect at the end. Off the top of my head, hope it works :) [/quote] Thanks SO...................Much you where right on the money............
  2. After a week and a half of researching and trial and error I'm in desperate need of some help........ I can't get my script to retrieve a specific field of data from MySQL....ie.....email addresses.....and send out a email to each of the addresses...... Here's the script i have now....I've changed it so many times at this point I might not even be close mysql_connect("host", "user", "password") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $query = " SELECT email FROM email_list"; $result = mysql_query($query); $num=mysql_numrows($result); mysql_close($link); $subject = "Ggap Show Reminder"; $body = "This is a test email for Ggap New Show Reminders"; $headers = "From: jason@domain.com"; $i=0; while ($i < $num) { $email=mysql_result($result,$i,"email"); // on the line above I've tried 'email', "'email'", and "email" and still nothing mail($email,$subject,$body,$headers}; $i++;
  3. [!--quoteo(post=361818:date=Apr 4 2006, 11:17 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 4 2006, 11:17 PM) [snapback]361818[/snapback][/div][div class=\'quotemain\'][!--quotec--] sorry, I forgot that mysql_numrows is just an earlier version, but probly a good idea to change it anyway. do you receive any errors or does it just not run. oh, maybe a ";" after defining $email will do it [/quote] Yah the ; was a typo from my last edit.........still nothing......id did have the script running but it was using every field and data in each field as a email address so i think my only poblem is getting to just pull the email field and no i'm not getting any errors i'm still chuggin...........
  4. [!--quoteo(post=361807:date=Apr 4 2006, 10:28 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 4 2006, 10:28 PM) [snapback]361807[/snapback][/div][div class=\'quotemain\'][!--quotec--] I believe you want to change [code] $num=mysql_numrows($result); [/code] to [code] $num=mysql_num_rows($result); [/code] [/quote] Thanks but still a no go........I'm a little confused on where I'm actually getting just my email....field/Colum
  5. I've been all over the Manual and was able to get bits and pieces of what I need to collect just the email field from my db and send email but its just not FLYIN............... Here's what i've got <? $link = mysql_connect("host", "user", "password"); mysql_select_db("test"); $query = "SELECT * FROM test_list"; $result = mysql_query($query); $num=mysql_numrows($result); mysql_close($link); $i=0; while ($i < $num) { $email=mysql_result($result,$i,"email") $subject = "Ggap Show Reminder"; $body = "This is a test email for Ggap New Show Reminders"; $headers = "From: user@mydomain.com"; mail($email,$subject,$body,$headers); $i++; } ?> Please Help.......I'M CROSSED EYED...........=)
  6. [!--quoteo(post=361436:date=Apr 3 2006, 10:09 PM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Apr 3 2006, 10:09 PM) [snapback]361436[/snapback][/div][div class=\'quotemain\'][!--quotec--] Check out the data about the mail function in the [a href=\"http://php.inspire.net.nz/manual/en/function.mail.php\" target=\"_blank\"]manual[/a] [/quote] Well I've been to the php manual and then to my yahoo host and back to the manual again and I've dwindled my scipt down to this <? $mail = "me@mydomain.com"; $subject = "test"; $msg = "test email"; $header = "From: mealso@mydomain.com"; mail($mail,$subject,$msg,$header); ?> Thanks for the advice I've got the send mail part working now the part i dread is getting the info from the db and sending a mass email to everyone It seems like I may have to read a whole book on php just to use a few of the abbilities of php but I hope not...................
  7. I'm trying to write a script to collect email addresses from MySQL and send a generic email (possible a template with the ability to insert custom body) to everyone on the list. Here's what I've got so far <? //conects to the data base $db_host = "mysql"; $db_user = "user"; $db_pwd = "password"; $db_name = "test"; mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error()); mysql_select_db($db_name) or die(mysql_error()); //gets the data $data = mysql_query("SELECT * FROM test_list") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { $to = $info['email']; $subject = "Ggap Show Reminder"; $body = "This is a test email for Ggap New Show Reminders"; $headers = "From: jason@bandsite.com\n"; mail($to,$subject,$body,$headers); echo "Mail sent to $to"; </? obviously not a working script yet.........I KNOW i do need to somehow keep the header of the email from showing other on the list. Any Suggtions are welcome Thanks
  8. [!--quoteo(post=361075:date=Apr 2 2006, 09:29 PM:name=play_)--][div class=\'quotetop\']QUOTE(play_ @ Apr 2 2006, 09:29 PM) [snapback]361075[/snapback][/div][div class=\'quotemain\'][!--quotec--] { $name = $_POST['name']; $email = $_POST['email']; $check = "SELECT * FROM email_list WHERE name='$name' and email='$email'"; $check_result = mysql_query($check); $num = mysql_num_rows($check_result); if (num > 0) { echo "You are already on the mailing list"; } else { $query = "INSERT INTO email_list (name,email) VALUES ('".$name."','".$email."')"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. // start visual if($result) { print "This is a message displayed upon query success!"; } else { print "This is a message displayed due to insert failure"; } // end visual } } [/quote] I gave the script a shot with a name and email already in the db and it went through successfully Thanks for the input i have a starting point atleast let me know if you find any thing i should try changing
  9. [!--quoteo(post=360981:date=Apr 2 2006, 04:37 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ Apr 2 2006, 04:37 PM) [snapback]360981[/snapback][/div][div class=\'quotemain\'][!--quotec--] [code] { $name = $_POST['name']; $email = $_POST['email']; $query = "INSERT INTO email_list (name,email) VALUES ('".$name."','".$email."')"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. // start visual if($result) { print "This is a message displayed upon query success!"; } else { print "This is a message displayed due to insert failure"; } // end visual } [/code] [/quote] Thanks that worked great............now I'll really test ya.....wink....wink how about code that will read the data fields and display "You are already on the mailing List" if it finds the same data in the db
  10. [!--quoteo(post=360950:date=Apr 2 2006, 02:20 PM:name=play_)--][div class=\'quotetop\']QUOTE(play_ @ Apr 2 2006, 02:20 PM) [snapback]360950[/snapback][/div][div class=\'quotemain\'][!--quotec--] post the code yo. [/quote] <?php $db_host = "mysql"; $db_user = "jeliot"; $db_pwd = "8013301"; $db_name = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); if (!isset($_POST['submit'])) { ?> <img src="images/email_list_logo.jpg" width="500" height="204"> <form action="" method="post"> Name: <input type="text" name="name" size="50"><br> Email: <input type="text" name="email" size="50"><br> <input type="submit" name="submit" value="Submit!"> </form> <?php } else { $name = $_POST['name']; $email = $_POST['email']; $query = "INSERT INTO email_list (name,email) VALUES ('".$name."','".$email."')"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. } ?> sorry .............brain fart..............I'm still working on cleaner less complicated script but every time I mess with it.......it either won't display or won't populate the db with any data also is there a way to get this form to open in a new smaller browser window with a php script or do I have to implement java code
  11. I want to add a statement to print "Your Email Has Been Submitted" into my email form but I'm having trouble ANY SUGGESTIONS Thanks
  12. [!--quoteo(post=360910:date=Apr 2 2006, 12:04 PM:name=Desdinova)--][div class=\'quotetop\']QUOTE(Desdinova @ Apr 2 2006, 12:04 PM) [snapback]360910[/snapback][/div][div class=\'quotemain\'][!--quotec--] first of all, tab your code. lets pretend '-' is a tab. Do it like this: if ($something){ - do this; } if ($somethingtwo){ - if ($somethingthree){ - - do that; - } } this way you can see what is happening where. I suggest you download crimson editor, and go to options to add another vertical guideline halfway the screen. al the //comments and /* comments */ could be placed right next to it, giving you a short and brief overview. another quick comment, I wouldn't suggest the submit button as an identification as to what process you should run. Somebody hitting enter in your form will not activate the button, thus not POSTing the submit button value. Rather place a hidden field with name submit and value set or something, so you really know what's going on. Unless you have multiple formbuttons with different option. Then you should use the submitname, and preferably disable the enter button. The code itself looks ok. You could be able to connect your database using 2 lines mysql_connect("localhost","username","pass"); mysql_select_db("dbname"); just 2 cents :) mind the tabbing! You'll need it lateron. I promise. [/quote] Thanks the tabbing sounds like a good idea and i just downloaded crimson........... i'm still at a loss for why that second scpript i posted isn't working in conjunction with my connect.php script to work like the first script does i must have somthing wrong somewhere...........
  13. Here I have a working php form script its nothing to write home about but it works <head> <title>Join Mailing List</title> </head> <?php $db_host = "host name"; $db_user = "jeliot"; $db_pwd = "password"; $db_name = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); if (!isset($_POST['submit'])) { ?> <form action="" method="post"> Name: <input type="text" name="name" size="20"><br> Email: <input type="text" name="email" size="20"><br> <input type="submit" name="submit" value="Submit!"> </form> <?php } else { $name = $_POST['name']; $email = $_POST['email']; $query = "INSERT INTO email_list (name,email) VALUES ('".$name."','".$email."')"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. } ?> Here is my cleaner more organized script if have been woring with <head> <title>Join Mailing List</title> </head> <body> <form action="" method="post"> Name: <input type="text" name="name" size="20"><br> Email: <input type="text" name="email" size="20"><br> <input type="submit" name="submit" value="Submit!"> </form> <body> <?php if (!isset($_POST['submit'])) { inlclude('./connect.php'); $name = $_POST[‘name’]; $email = $_POST[‘email’]; $query = "INSERT INTO email_list (name, email) VALUES ('$name', '$email' )"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. } ?> </head> </html> and here is my script to connect to my database <html> <head> <title>Untitled</title> </head> <body> <? $db_host = "host name"; $db_user = "jeliot"; $db_pwd = "password"; $db_name = "email"; mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error()); mysql_select_db($db_name) or die(mysql_error()); ?> </body> </html> I'm hoping for some different opinions on how i SHOULD be shorting this scipt to clean it up and descriptions on why those changes are better ALL OPINIONS WELCOME THANKS
  14. [!--quoteo(post=360785:date=Apr 1 2006, 09:48 PM:name=jeliot)--][div class=\'quotetop\']QUOTE(jeliot @ Apr 1 2006, 09:48 PM) [snapback]360785[/snapback][/div][div class=\'quotemain\'][!--quotec--] I tried that script and the form comes up blank I did notice the with my first version of the script if i took out the ! berfore the isset IT TO WOULD display a blank page Thats all I have so far I'm still messing around [/quote] I've got my form script working thanks to ALL that helped the only problem i have is the script isn't short and organized i still need some help cleaning up the script i'm going to post another forum with my working script and my revised cleaner script that isn't working............
  15. I tried that script and the form comes up blank I did notice the with my first version of the script if i took out the ! berfore the isset IT TO WOULD display a blank page Thats all I have so far I'm still messing around
  16. [quote name='jeliot' date='Apr 1 2006, 06:48 PM' post='360751'] Ok i figured out that if i take out the ID field I recently added in my db then my populate.php WILL populate my db with test names but................ my email form has stoped adding emtpy rows and has reverted to sending nothing but i'm getting no errors I'm starting to dig myself deeper [/quote] Ok i figured out that if i take out the ID field I recently added in my db then my populate.php WILL populate my db with test names but................ [/quote] my old email_form script <?php $db_host = "mysql"; $db_user = "jeliot"; $db_pwd = "8013301"; $db_name = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); if (!isset($_POST['submit'])) { ?> <form action="" method="post"> Name: <input type="text" name="name" size="20"><br> Email: <input type="text" name="email" size="20"><br> <input type="submit" name="submit" value="Submit!"> </form> <?php } else { $name = $_POST[‘name’]; $email = $_POST[‘email’]; $query = "INSERT INTO `email_list` (name, email) VALUES ('$name', '$email' )"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. } ?> still sends the form with the Name: empty and Email: empty my revised script (with play's help) <?php $db_host = "mysql"; $db_user = "jeliot"; $db_pwd = "8013301"; $db_name = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); if (!isset($_POST['submit'])) { ?> <form action="" method="post"> Name: <input type="text" name="name" size="20"><br> Email: <input type="text" name="email" size="20"><br> <input type="submit" name="submit" value="Submit!"> </form> <?php } else { $name = $_POST[‘name’]; $email = $_POST[‘email’]; $query = "INSERT INTO `email_list` (name, email) VALUES ('$name', '$email' )"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. } ?> doesn't error but doesn't send anything to the database
  17. [!--quoteo(post=360747:date=Apr 1 2006, 06:26 PM:name=jeliot)--][div class=\'quotetop\']QUOTE(jeliot @ Apr 1 2006, 06:26 PM) [snapback]360747[/snapback][/div][div class=\'quotemain\'][!--quotec--] All great info I've been looking to try to neaten up my script What I meant by creating a field is when id use my download script it shows me a new field but with no data....almost like submitting an empty form (if that was possible) In my database I have 1 table with 3 fields ID INT no / null auto increment primary name VARCHAR no / null email VARCHAR no / null i'm not sure if the problem is with how the db is set up or not but i just changed the ID field to include auto increment and primary key and now my populate.php won't populate my db any more so I've gone a little backwards Thanks for the help............. i'm still chuggin a long [/quote] Ok i figured out that if i take out the ID field I recently added in my db then my populate.php WILL populate my db with test names but................ my email form has stoped adding emtpy rows and has reverted to sending nothing but i'm getting no errors I'm starting to dig myself deeper
  18. All great info I've been looking to try to neaten up my script What I meant by creating a field is when id use my download script it shows me a new field but with no data....almost like submitting an empty form (if that was possible) In my database I have 1 table with 3 fields ID INT no / null auto increment primary name VARCHAR no / null email VARCHAR no / null i'm not sure if the problem is with how the db is set up or not but i just changed the ID field to include auto increment and primary key and now my populate.php won't populate my db any more so I've gone a little backwards Thanks for the help............. i'm still chuggin a long
  19. [!--quoteo(post=360705:date=Apr 1 2006, 04:59 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ Apr 1 2006, 04:59 PM) [snapback]360705[/snapback][/div][div class=\'quotemain\'][!--quotec--] you have back-ticked around $email in your query change [code] mysql_query("INSERT INTO `email_list` (name, email) VALUES ('$name', ‘$email’)"); [/code] to [code] mysql_query("INSERT INTO `email_list` (name, email) VALUES ('$name', '$email')"); [/code] and you should be fine... [/quote] Thanks guys you have been great I'm getting there........now the script is just creating empty field in my database...here's my revised script <head> <title>Join Mailing List</title> </head> <body> <?php $db_host = "mysql"; $db_user = "jeliot"; $db_pwd = "8013301"; $db_name = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); if (!isset($_POST['submit'])) { ?> <form action="" method="post"> Name: <input type="text" name="name" size="20"><br> Email: <input type="text" name="email" size="20"><br> <input type="submit" name="submit" value="Submit!"> </form> <?php } else { $name = $_POST[‘name’]; $email = $_POST[‘email’]; $query = "INSERT INTO `email_list` (name, email) VALUES ('$name', '$email' )"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. } ?> I'm going to do some research if anyone knows the solution right off thanks in advance
  20. [!--quoteo(post=360686:date=Apr 1 2006, 03:13 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 03:13 PM) [snapback]360686[/snapback][/div][div class=\'quotemain\'][!--quotec--] It means the first line of the SQL query If you put the query all on one line then the error, if there is one, wil always be on line 1. [code]SELECT a.cola, b.colb, b.colc FROM table1 a INNER JOIN table2 b ON a.cola = b.cola WHERE b.colc = '$x' AND b.colx = 42[/code] or you could split it over several lines [code]SELECT a.cola, b.colb, b.colc FROM table1 a         INNER JOIN table2 b ON a.cola = b.cola WHERE b.colc = '$x'         AND b.colx = 42[/code] [/quote] thanks atleast i have a starting point to find the problem
  21. Newbie question when the SQL error says line on does that mean line of the whole HTML/PHP script or just the first line of the actuall php script in the HTML script thanks
  22. [!--quoteo(post=360558:date=Apr 1 2006, 02:06 AM:name=play_)--][div class=\'quotetop\']QUOTE(play_ @ Apr 1 2006, 02:06 AM) [snapback]360558[/snapback][/div][div class=\'quotemain\'][!--quotec--] You dont need a coma after your last values on the query. so change this [code]mysql_query("INSERT INTO `email_list` (name, email, ) VALUES ('$name', ‘$email’, )");[/code] to this [code]mysql_query("INSERT INTO `email_list` (name, email) VALUES ('$name', ‘$email’)");[/code] Also, You wanna put the sql query in a variable, so you can check it. so instead of this: [code]mysql_query("INSERT INTO `email_list` (name, email, ) VALUES ('$name', ‘$email’, )");[/code] Do this: [code] $query =  "INSERT INTO `email_list` (name, email) VALUES ('$name', ‘$email’ )"; $result = mysql_query($query) or die(mysql_error()); // this performs the actual query. [/code] That should do it and if not it will print out an error message. If it does, let us know what it was [/quote] Ok thanks for the info I'm a step closer i think........the query created this error to which I could not figure a solution. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘ )' at line 1
  23. This is my first post and yes I am a newbie but I did alot of research before posting.... so here it goes I have a test script wich will populate my db and I have a test script wich will then take the data make it viewable in a browser...but..... this email form script <?php $db_host = "host_name"; $db_user = "my_user_name"; $db_pwd = "3456789"; $db_name = "email"; mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); ?> <?php if (!isset($_POST['submit'])) { ?> <form action="" method="post"> Name: <input type="text" name="name" size="20"><br> Email: <input type="text" name="email" size="20"><br> <input type="submit" name="submit" value="Submit!"> </form> <?php } else { $name = $_POST[‘name’]; $email = $_POST[‘email’]; mysql_query("INSERT INTO `email_list` (name, email, ) VALUES ('$name', ‘$email’, )"); } ?> won't populate the data to my db Any Help with this would be greatly appreciated I've been racking my brain
×
×
  • 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.