I will be grateful if someone could help me with a PHP program to connect MYSQL database to a webpage to collect email addresses. Thanks Wilfred
Run the following SQL command to create 'email' table: CREATE TABLE emails ( email CHAR(50) ); Code (markup): <?php $link = @mysqli_connect("localhost","username","password"); @mysqli_set_charset($link, "utf8"); @mysqli_select_db($link, "emails"); echo "<form action='.' method='post'>"; echo "Email: <input type='text' name='email' /></form>"; if (isset($_POST['email'])) { $email = $_POST['email']; @mysqli_query($link, "INSERT INTO emails VALUES ($email)") or die("Failed."); echo "Success"; } ?> PHP: The basics should be something like that. How would you like it?
you can access the database and get all records like so: <?php // Connect to the database. mysql_connect($url, $username, $password); mysql_select_db($db_name) or die(mysql_error()); // Get the emails from the database table "emails". $query = mysql_query("SELECT * FROM emails") or die(mysql_error()); // Go through each email retrieved from the database and output them on the page. while($row = mysql_fetch_array($query)) { echo $row['email']; } ?> PHP: You can do other things with the data besides just output it too if you like.
Hi, Here We introduce that code, that's help you,Just see them <?php if(isset($_POST['posted'])) { $email_id=$_POST['dir_email_id']; $connect=mysql_connect('localhost','root',''); $db=mysql_select_db('dir_db',$connect); // Now, We Perform Saving Operation. if(isset($_POST['dir_save']) == 'Save') { $query=mysql_query("INSERT INTO dir_table(emailid)VALUES('$email_id')",$connect); } //Retrive Emial Id Which i Save In Databse $query=mysql_query('SELECT * FROM dir_table',$connect); while($row=mysql_fetch_array($query)) { $my_email_id=$row['emailid']; echo $my_email_id; exit(); } } ?> <form name="index_dir" method="post" action="index_dir.php"> <table align="center" border=""> <tr> <td> <b style="background-color:#063">Email Id</b> <input type="text" name="dir_email_id" value="Email Id" style="background-color:#966"> </td> </tr> <tr> <td><input type="hidden" name="posted" value="true>"></td> <td> <input type="submit" name="dir_submit" value="GO" style="background-color:#063"> </td> <td> <input type="submit" name="dir_save" value="Save" style="background-color:#063"> </td> </tr> </table> </form>