Jump to content
xisto Community
alex1985

Php Code Needed?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.
Edited by alex7h3pr0gr4m3r (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 |


Edited by shadowx (see edit history)

Share this post


Link to post
Share on other sites

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.

Edited by alex7h3pr0gr4m3r (see edit history)

Share this post


Link to post
Share on other sites

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?!

Share this post


Link to post
Share on other sites

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.

Edited by alex7h3pr0gr4m3r (see edit history)

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.
Edited by alex7h3pr0gr4m3r (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.