www.webdeveloper.com
Results 1 to 6 of 6

Thread: CGI + Database

  1. #1
    Join Date
    Dec 2002
    Location
    NJ
    Posts
    5

    CGI + Database

    Ok i setup a database using the instructions on htmlgoodies... now it doesnt really say how to get info on there.. i mean sure it gives variables and codes. But it deosnt say where to apply the codes. it's very simple database... first name lastname and email. Now how do i write a script to send stuff to there?
    -ZyouS
    www.zyous.com

  2. #2
    Join Date
    Dec 2002
    Location
    NJ
    Posts
    5
    ok sorry... bare with me i'm fairly new at all this database stuff.... Ok here is my scenario, I just learned how to make a table database (real basic) using Access (downloading SQL as we speak). Anyway, My database table consists of first_name last_name and email.. as per example of htmlgoodies database. Now the next section after making the database is inserting text into the database. How exactly do i Insert stuff into the required fields. Do i have to make an html page with certain values that tells the information where to be added into the database? My question basically is how do i send information to be collected to the database?
    -ZyouS
    www.zyous.com

  3. #3
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    First we should be clear about what language you plan on doing this in.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  4. #4
    Join Date
    Dec 2002
    Posts
    34
    Here's a sample script that will input data into a MySQL database using PHP:

    PHP Code:
    <?php
    $hostname 
    "localhost";
    $db_name "name of the database";
    $db_user "your database username";
    $db_pass "your database password";

    $input_fname "Dave";
    $input_lname "Clark";
    $input_email "email@mail.com";

    $query "INSERT INTO name_table (firstname, lastname, email) VALUES ('$input_fname', '$input_lname', '$input_email')";

    // Connect to database using variables already defined
    mysql_connect($hostname$db_user$password);
    mysql_select_db($db_name);

    // Input information in variables or stop script
    $result mysql_query($query) or die("MySQL Error");

    ?>
    That will put the values "Dave", "Clark", and "email@mail.com" in the columns "firstname", "lastname", and "email". If the query fails, the die() function is called, which stops the script with an error message you specify. Obviously, you'll have to change the first four variables to fit your particular database, except for $hostname, which should be localhost in your case. If your database doesn't have a password, you can just omit that parameter from the mysql_connect() function call. Also, it's always smart to put these variables in a .php include file, for tighter security. Actually, because it seems you're hosting your own site, it would be even more logical to put the variables in a directory seperate from your web root, so that it can't be accessed at all outside of the script (and directly by you).

    Note that this script assumes that MySQL is set up, that there is a database called "name of the database", and that there are three columns with appropriate names in that database. Setting up the database and tables can be done with another script, which I'll write for you if you want.

    (sorry to widen the topic)
    :-D

  5. #5
    Join Date
    Dec 2002
    Posts
    34
    :-D You wrote the post above mine, and you have a first and last name in your user name. Anyway, I thought you'd like being put into zyous's database.
    :-D

  6. #6
    Join Date
    Dec 2002
    Location
    APR / Europe
    Posts
    1
    Here's a sample script that will input data into a MySQL database using PHP
    Thank you... that makes for easier comprehension for all of us here :-)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles