FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


script for a newsletter





pollux1er
I am a beginner in php. I just want to create a newsletter on my web page. Can i have a script to make it? i am using easyphp to test my script.
What i need is to insert an adress mail into my database, and how to create that database. For a start i think it is the least i should be able to do. Laughing
Manofgames
All the info you need to do that is available on http://www.tizag.com
But there are also many free programs that can do this, I think there is one in DA actually...
pollux1er
Manofgames wrote:
All the info you need to do that is available on http://www.tizag.com
But there are also many free programs that can do this, I think there is one in DA actually...


What i am really looking for is the complete code for a newsletter. But there is not in that website you gave the link!
Manofgames
Ah, sorry.
I thought you wanted to try and make one Embarassed
The following site has a lot of newsletter scripts: http://www.hotscripts.com/PHP/Scripts_and_Programs/Mailing_List_Managers/index.html

Also, a quick google: http://www.google.co.uk/search?sourceid=navclient&aq=t&ie=UTF-8&rls=GGLJ,GGLJ:2006-44,GGLJ:en&q=php+newsletter+script+free
aningbo
you cant get better scripts but look for it in hotscripts.com they have a huge database of codes or wanna create yourself, then google it. good luck.
pollux1er
Ok, thanks for the links.
The first step i've already done it. Create the HTML part, i wrote a a form so that anybody can enter his address, but now, my problem is to get the address entered in and send it to the database.

I need a code for this. So if there is somebody who has already done it, let me know.

Thans in advance.
Manofgames
Alright, I've litterally just thrown this together, so it may not be that brilliant, or secure(though I have put some protection in, it may go a bit crazy depending on how your web hosting is set up).

All the vars are created at the begining of the script, and I've included comments as well.

Code:

<?php
//Enter the general info here:
//
//Enter your MYSQL database info here
$dbhost = 'localhost'; //usually this is localhost, it is with frihost
$dbuser = 'root'; //This is usually in the format of 'yourhostingusername_databaseusername'
$dbpass = ''; //This is whatever you set it up to be
$dbdata = 'newsletters'; //This is the database to put the stuff in
$dbtabl = 'subscribers'; //This is the table in the database to put stuff in
$dbfiel = 'email'; //The table field

//Form settings
$ff_email = 'email';//This is the name of the field the user puts their address into

//Optional settings

$redaddrr = 'http://www.myhost.com/'; //Redirect url




if($_POST[$ff_email] != null){

// Make a MySQL Connection
mysql_connect("$dbhost", "$dbuser", "$dbpass") or die(mysql_error());
mysql_select_db("$dbdata") or die(mysql_error());

// Insert a row of information into the table
$value = mysql_real_escape_string($_POST[$ff_email]);

$query = mysql_query("INSERT INTO $dbtabl ($dbfield) VALUES('$value') ")
or die(mysql_error()); 

if($query){
header("Location: $redaddrr")
exit();
}



}

else{
echo 'Please enter an email address';
}
?>



In your html form, make sure where it says <form name="...." etc.
that you include the option action="post", otherwise this script will fail.

example form:
Code:

<form name="subscribe" action="post" method="dir/to/script.php">
.....
</form>
pollux1er
Thanks for that code. I'ill try it but if anybody thinks he can give me another one, don't hesitate. I need, may be it could help me to understand once.

Thanks Manofgames!
emizapod
firs you can make your form like this:

Code:
<!-- File: new_user.html -->
<html>
<body>
<!-- beginning of document -->
<form action="valid.php">
Name: <input type="text" name="name"/><br/>
Address: <input type="text" name="address"/><br/>
<input type="submit" value="Save" />
</form>
<!-- end of document -->
</body>
</html>


The file valid.php to send data to the database:

Code:
<?php
//-----------------------
// Name of the file : valid.php
// sample:
//      valid.php?id=jdupond&name=Dupond&address=blabla
//-----------------------

   $dbhost="localhost";
  $dblogin="root";
  $dbpassword="";
  $dbname="phpfacile_test";



$name     = $_GET["name"];
$address = $_GET["address"];

   echo "Bonjour $name,<br>";
  mysql_connect($dbhost,$dblogin,$dbpassword);mysql_selectdb($dbname);
  $result=mysql_query("INSERT INTO table_utilisateurs (name,address)
              VALUES ('$name','$address')");
  if (!$result) {
     echo "L'enregistrement de vos données a échoué. Essayez plus tard<br>";
  } else {
     echo "Félicitations. Vous êtes desormais un nouveau membre de PHP Facile!<br>";
  }
  mysql_close();
?>


it should work
Fire Boar
Manofgames wrote:
Code:

<form name="subscribe" action="post" method="dir/to/script.php">
.....
</form>


Actually...

Code:

<form name="subscribe" method="post" action="dir/to/script.php">
.....
</form>


Don't get methods and actions mixed up!
Manofgames
Ah, thanks Embarassed
Its absolutely ages since I've needed to create forms and stuff, I just forgot.
pollux1er
Thank you for the attention fire boar. I didn't noticed it.
Related topics
Which is your favourite weblog Script?
Chat script
Script Upload (obiefileman)
script backup database
Script run background
Can someone make me a php script?
target = _parent redirect script?
Bookmark Script:
Some Script Show
Image transparency script
A script for Loading
Need help with PHP script[RESOLVED]
Newsletter component for joomla
Looking for free Newsletter subscribe script or software
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.