Jump to content

Trying to create a subscribe form


liamloveslearning

Recommended Posts

Hi everyone,

 

Im trying to create a subscription form which only needs to collect the users name and email, I cant understand mysql and so I was wondering is there a way I can host a .txt file which has its permissions set to 777 where the form can possibly write all the data to this? if anybody can point me in the right direction Id be really grateful, thanks

Link to comment
Share on other sites

You can store the details in a flat file, but I'd recommend against it. If you wish to do much PHP programming language then working with some form of PHP is likely to be ultimately unavoidable so best to learn it sooner rather than later. Standard MySQL is really not that complicated, you should be able to pick up the basics in under an hour. If you use a visual editor to create the tables (PHPMyAdmin for example), the only lines your likely to need for your current task are...

 

SELECT name, email FROM users
INSERT INTO users(name,email) VALUES('$name', 'email')

 

At it's most basic MySQL is fairly 'readable', I think for example that even somebody without any knowledge of it can look at the above two lines and have a fairly good idea of what they actually do.

Link to comment
Share on other sites

Technically you don't have to have an index, but generally you would have a column called `id` or `user_id`, in case you needed to identify a particular row in your database uniquely. If you don't have a specific method for generating an id (as shops often do for stock codes etc), then you would normally set it to auto increment. Without an `id` column, there would be nothing stopping you adding multiple rows with the name 'John' and the email 'john@domain'. If you did so you would have no way of identifying them as individual rows.

Link to comment
Share on other sites

Ive managed to sort that out, with the auto increment too; may sound stupid but this says it cant connect to my database have you any idea why?

 

<?php
$con = mysql_connect("localhost","newsletter","mypassword");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$sql="INSERT INTO users (name, email)
VALUES
('$_POST[name]','$_POST[email]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.