HOME       >>       Programming

Php Code Needed?


alex1985

Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the web-site2. On the main screen, there is a some kind of field windows, the one you get used to type in, when you go to google, for instance.3. He or she types her email address and it's going to be saved in my SQL database. 4. That's it.Help me if you can.


galexcd

Alright, first I'd suggest creating the structure of the database in phpmyadmin, but if you don't have phpmyadmin, I've included the code below. Ok So the database only needs to hold emails so it is easy. Make a table called email and put one field called address, type varchar, and lets say 30 characters. Incase you don't have phpmyadmin, type this code into a php page, upload it to your server and load the page once.

<?phpmysql_connect("localhost",$username,$password);mysql_select_db($database);mysql_query("Create Table 'email'('address' VARCHAR( 30 ));");mysql_close();?>

Now that we've got the structure, lets write the php page to add emails to the table.
<?phpif(isset($_POST['email']){if(strpos($_POST['email'], "@")!==false&&strpos($_POST['email'], ".")!==false)echo"The email address you entered is not valid";else{mysql_connect("localhost",$username,$password);mysql_select_db($database);mysql_query("Insert INTO 'email' SET 'address'='".addslashes($_POST['email'])."'");mysql_close();}}else{?><form action="" method="post">Email:<input name="email"><input type="submit" value="Add"></form><? } ?>


And that should be it.

jlhaslip

Sounds like you want a Log-in script with a Database to store the information in. You don't mention what you will be using the email addresses for. If you could tell us what you plan on doing with the email addresses, that might make a difference in the script we point you to.In the meantime, have a look in the Tutorial section. There are several Login scripts there that save email addresses. Most of them include password information. Some will allow edits to the information.


alex1985

I wanna use like a login form, instead of username, you put the desired password.


shadowx

Do you mean you want a basic login where their username is their email address and then they enter a password too? Like this:

 

Username: |email@email.com |

Line break

Password: |*********** |


Or that the email should be a password, (or you only need an email and no password) EG:

 

Email: |************** |

OR

Email: |email@email.com |



galexcd

Ohh I thought this was some kind of newsletter or something. Didn't realize you wanted a login script. Yeah those are a bit more complicated. Oh and haslip, how did you know he wanted a login script? His initial post had nothing in it to hint to that... I guess you are just a psychic.


alex1985

That's quite good I wanna learn how to do one thing, but thinking to learn more due to you guys, write more replies in this topic!


galexcd

Well we can't really help you unless you tell us what you want. Do you want this for an account login system, or for an email list or what?


alex1985

That's replies were not bad. So, you help me to study PHP step-by-step. Thanks for that. When someone go to my page, they type their emails, which will be stored in my database, then, I go to another page, where I have a big dialog field where I type some text and then send to those emails. That's now clear?!


galexcd

Ah so you want an email list, that's what I thought. Use the code in my first reply to store it in the database, and you can use the php mail() function to send it out to everyone in the database.


alex1985

Ah so you want an email list, that's what I thought. Use the code in my first reply to store it in the database, and you can use the php mail() function to send it out to everyone in the database.

Could you explain in more details? How can I use the function? Sorry, I am a novice! By participating in such forums, I will learn faster than reading the books. Just give the sample code that I can understand!

jlhaslip

Read about the mail function in php at the php.net site nearest to you.

http://ca.php.net/manual/en/function.mail.php

and search through the Tutorials Forum to find a Log-in script and an email script. When you understand those tutorials, you should be able to 'join' the two into a set of pages to do what you need.

Feel free to continue learning always and all ways. Learning by doing is the best way.


galexcd

Could you explain in more details? How can I use the function? Sorry, I am a novice! By participating in such forums, I will learn faster than reading the books. Just give the sample code that I can understand!


Alright. Use the code I gave you for the "frontend" of your website, meaning the part that the users will see. After you run the first block of code I gave you, upload the second block and name it whatever you want. Then when people go to that page they will see a box where they enter their email and it will add that email to the database.

Now for the "backend" part of it that will let you send an email to every single email in that database:

First put this code into a .php file and upload it to your server:
<?phpif(isset($_POST['from'])){mysql_connect("localhost",$username,$password);mysql_select_db($database);$query=mysql_query("SELECT * FROM 'email'");$to="Bcc:".mysql_result($query,0,"address");for($i=1;i<mysql_num_rows($query);i++)$to.=",".mysql_result($query,i,"address");mysql_close();if(mail($_POST['from'],$_POST['subject'],$_POST['message'],"From:".$_POST['from']."\r\n".$to))echo"Mail sent successfully!";else echo"There was an error when sending the message";}?><form method="post" action="">From:<input name="from"><br>Subject:<input name="subject"><br>Message:<br><textarea name="message"></textarea><input type="submit" value="Send!"></form>
Then whenever you want to send an email to everyone on your list just go to this page and hit send. The email puts all of your emails in blind carbon copy so everybody can't see everybody else's email address. The from field is whatever email address you want to send this email from. It will also send a copy to this email for your records.

Once again this code wasn't tested so if you have any problems just post em back here and I'll take a look at it.

alex1985

I really appreciate for your reply. Thanks.


alex1985

Thanks for your useful replies. How can I add to this script an additional function that like everyone can BB Codes when typing something? That's very popular used in forums as well as portals, for instance, insert a link.


galexcd

Thanks for your useful replies. How can I add to this script an additional function that like everyone can BB Codes when typing something? That's very popular used in forums as well as portals, for instance, insert a link.

You mean bbcodes in the email itself? Well you would have to use a function to parse the bbcode into html such as preg_replace, and then use the headers in the mail function to allow html in the email.

 

For parsing bbcode you should learn regular expressions if you want to be able to do this efficiently.

Here is an example of parsing the bold bbcode tag into html:

preg_replace(array("/\[b\]/","/\[\/b\]/"),array("/<b>/","/<\/b>/"),$input);

And for the headers add this:

MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n



VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.