Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Hello all,

    This is another simple question as I weigh out my options in setting up this script to write a user's name and e-mail into the table I've set up on my web host.

    Here's the script I'm working on:
    Code:
     <?php
          /*This is the scripting section for the e-mail collection box.*/
        $email = " ";
        $connection = mysql_connect("SERVERNAME BLANKED OUT" , "LOGIN BLANKED OUT" , "PASSWORD");
        $dbconn = pg_connect("dbname=emailcollection");
        if (!$connection){
            die('Could not connect: ' . mysql_error());
       }
        
        function showWindowAndValidate()
        {
            echo'<div id="activeemailbox"><input type="checkbox" value="Yes, I would like to join the mailing list."><p>Enter the characters you see below.</p></div>' . generateRandom() . ;    
        }
        
        if (isset($_POST["go"]){
            $email = $_POST["go"];
            if (isItAValidEmail($email)){
                showWindowAndValidate();
                //call a function to write the user to database
            } else {
                invalidEntry();
        } else {
            invalidEntry();
            }
        
        /*test the e-mail address submission for valid entry */
        function Boolean isItAValidEmail($email){
            return preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$^", $email);
        }
        
        function invalidEntry()
        {
            return echo'<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back"           onclick="goBack()"></div>';
        }
        
        function generateRandom()
        {
        
        }
        
        function goBack()
        {
            header();
        }
        
        mysql_close($connection);
        
        //end e-mail box scripting section
    ?>
    Now, since I've connected through a variable called $connection using the mysql_connect() and mysql_close() to exit, should I already have the table set up with their columns, or should I code this into the script? (my guess is to already have it set up in MySQL without it in the PHP script because it could re-create the same columns???) I just want to lay write new rows of data to the same columns in the same database. I'm guessing that if I were to use the pre-defined functions for making a new MySQL database would generate duplicates of the same database.

    Maybe you can point me in the right direction.

  2.  

  3. #2
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Typically, you will create a table with the columns that you need.

    Then you'll use an insert statement to add new rows of data as the correspond to the columns and tables.

  4. #3
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Ah, okay. So I am working in PHPmyAdmin on my web host to create this table. There's a bit to figure out there. (I'm not allowed to access or manipulate the database with a third-party client)

    I do have a mysql_connect() and mysql_close() in there. Do I need something like a pg_connect() or something, so the script can access the database name? If pg_connect() is not the right one, which one shall I use?

  5. #4
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Create the table with php admin...

    Your host should have examples on how to do insert and select statements from a web page... A web page on their server that is mapped ... Using your connection string... Is not considered a 3rd party app.

    MySQL browser or MySQL workbench would be a third party app that they are talking about.

    Most host that offer MySQL do set it up by recommended settings, so pretty much any standard connection string using your defined DB IP address, username and password can interact with the DB you setup.

    You should be able to get your DB IP address as well as the table name from your host... You'll need the username and password for the table that you used to create the table ...

    Standard connection strings can be found all over..

  6. #5
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Okay! I'll get right on it.

    I have a web address for the hostname/server name but not an actual IP (e.g. 192.168.x.x). This won't suffice?

    By the way, I had already installed MySQL Workbench on this machine, so I'm aware that the online application provided by my web host is not 3rd party. :smoke:

  7. #6
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    Myphp admin has the IP address if that is what our host requires you to connect with...

    What I typically suggest to people that are learning how to connect with MySQL and insert and edit data.

    Use myphp admin to put some dummy data ( at least 3 rows of data ), into the DB ... The select statement is easier to do to establisht that you have your connection sting correct. Once you know that is correct, then you can start working on building your insert statements ( which are generally a little more finicky )...

  8. #7
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Yes, this is successful. I have put new rows successfully into the columns.

    Now I need to know the proper PHP functions for connecting to this database and the function that I can write SQL queries inside of. See my code in the original post here- I tried a couple of things, including mysql_connect() and pg_connect().

  9. #8
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    You're not going to have a function ( straight off ), unless you setup the function and include it on all your pages..

    Does your host have a FAQ section with a sub section on MySQL ? Typically, if they do have it, they will have some working examples of how to query your DB ... Substitute your server name / IP address, usrname and password ...

    Again, do a "select query" first

  10. #9
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    I didn't see anything on my host's Help/Support site that went beyond tutorials for phpMyAdmin. I guess I can start a live chat with them...

  11. #10
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    http://www.webdesignforums.net/threa...7/#post-243669

    Tons of info on this forum already


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:42 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com