Results 1 to 4 of 4
  1. #1
    Join Date
    May 2007
    Posts
    213
    Plugin Contributions
    0

    Default How to insert data into a new table

    Ok, I created a new little form in my footer (you can see it here: http://74.52.161.178/~gridiron/index.php) where people can sign up to receive emails/newsletters. I am not requiring them to be customers to join so, I will be managing two list basically.

    What I would like to do it create a new table in my store database to store their name, email address and format they wish to receive. I am fine with creating the table, but I am not sure how to write the php code to insert the data into the table and throw an alert that the address was sucessfully added.

    So, can someone tell how I would take the data from the form I've designed and enter the values into a new table? Once the record has been inserted an alert window can come up saying thanks for signing up and one they click ok they can stay on the page they are on.

    Thanks so much.

    PS: If you have any hints on validating that it is an email address would be cool too :)

    Thanks

  2. #2
    Join Date
    May 2007
    Posts
    213
    Plugin Contributions
    0

    Default Re: How to insert data into a new table

    Here is a little more information if this helps...

    I have the following form:
    Code:
      <form method="post">
        <input type="text" name="cust_name" value="Enter your name" onFocus="clearText(this)" onBlur="clearText(this)" />
        <input type="text" name="email_address" value="Enter your email address" onFocus="clearText(this)" onBlur="clearText(this)" />
        <select name="format">
          <option value="">Mail Format</option>
          <option value="html">HTML</option>
          <option value="text">TEXT</option>
        </select>
        <input class="submit" type="submit" value="" />
      </form>
    I would like to run the following when the user clicks the submt button.

    Code:
    <?php
      $name=$_POST['cust_name']; 
      $email=$_POST['email_address']; 
      $format=$_POST['format']; 
      mysql_connect("localhost", "myDB", "myPassword") or die(mysql_error()); 
      mysql_select_db("gridiron_sportsgear") or die(mysql_error()); 
      mysql_query("INSERT INTO `email_subscribers` VALUES ('$name', '$email', '$format')"); 
    ?>
    Once the record has been entered into the DB I would like an alert to show stating the record was entered successfully. Once they click OK they will be returned to the page they were on when they submitted the form.

    Right now when I submit it the form nothing is getting added to the DB? Any idea why?

  3. #3
    Join Date
    Feb 2008
    Posts
    41
    Plugin Contributions
    0

    Default Re: How to insert data into a new table

    well it looks to me like your inserting all of your values into one table field.
    Try putting the names of the fields that you want the values inserted into in your sql insert.
    eg .. INSERT INTO 'field1' , 'field2', 'field3' VALUES 'value1', 'value2' , 'value3' etc etc ....
    <my syntax may not be exact> but i think that might help with that.



    ~B.

  4. #4
    Join Date
    Apr 2007
    Location
    Herts. UK
    Posts
    890
    Plugin Contributions
    4

    Default Re: How to insert data into a new table

    Quote Originally Posted by MCanes View Post
    Ok, I created a new little form in my footer (you can see it here: http://74.52.161.178/~gridiron/index.php) where people can sign up to receive emails/newsletters. I am not requiring them to be customers to join so, I will be managing two list basically.

    What I would like to do it create a new table in my store database to store their name, email address and format they wish to receive. I am fine with creating the table, but I am not sure how to write the php code to insert the data into the table and throw an alert that the address was sucessfully added.
    Why re-invent the wheel?
    http://www.zen-cart.com/index.php?ma...roducts_id=106

    Regards,
    Christian.

 

 

Similar Threads

  1. Replies: 0
    Last Post: 26 Feb 2014, 07:21 AM
  2. how can I insert extra product info into extra db table?
    By lndlyb4 in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 1 Feb 2010, 07:18 PM
  3. Replies: 2
    Last Post: 23 Jul 2009, 12:59 AM
  4. insert attributes into a table
    By davidpiddington in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 9 Jul 2009, 03:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg