#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    26
    Rep Power
    0
    Hello all,

    I have been doing alot of observing on this forum and Dev Shed articles on PHP. I have come across numerous topics relating to my application.

    Here is what Iam trying to do:

    I have created an HTML from file using the post function as follows:

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#CCCC00">
    <p>Enter data please:</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <form name="form1" method="post" action="verify.php3" >
    <p>First name:
    <input type="text" name="first_name" size="15" maxlength="30">
    </p>
    <p>lastname:
    <input type="text" name="last_name" size="15" maxlength="20">
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    </p>
    </form>
    </body>
    </html>


    *********************** Here is my verify.php3 file:

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FF9933">
    <?
    /* This php3.0 script will provide the sign up form processing.
    */


    /* declare some relevant variables
    */

    $hostname = "I entered my hostname name here";
    $username = "I entered my username name here";
    $password = "I entered my password name here";
    $dbname = "I entered my database name here";

    /* make connection to the database
    */

    MYSQL_CONNECT($hostname, $username, $password) OR
    DIE("Unable to connect to the database");

    /* Print some data
    */

    PRINT "<CENTER>";
    PRINT "HELLO, $first_name $last_name";
    PRINT "<BR><BR>";
    PRINT "Your info has been entered into our database";


    /* Insert info into the table contact
    */


    MYSQL_SELECT_db (contact);

    MYSQL_QUERY ("INSERT INTO contact (first_name, last_name)

    VALUES ('$first_name', '$last_name')
    ");


    print ($first_name);

    print ($last_name);


    /* close database connection
    */


    MYSQL_CLOSE();


    ?>

    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>

    ************************My admin dump file is as follows:

    CREATE TABLE contact (
    first_name varchar(20) NOT NULL,
    last_name varchar(30) NOT NULL
    );
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    rway,
    Here is an example for you..how to insert record into database...

    <?
    $con=mysql_connect('localhost','yourusername','yourpassword');

    //make connection to the database

    mysql_select_db('yourdatabasename',$con);
    //select your database..

    $result=mysql_query("INSERT INTO contact (first_name, last_name) VALUES '$first_name', '$last_name')",$con);
    //issue your insert query..

    if (mysql_affected_rows($result) == 1){
    //updated the database..

    echo "HELLO, $first_name $last_namen";
    echo "Your info has been entered into our databasen";
    }else{
    //couldn't update database..

    echo "Error !! while insertionn";
    exit;
    }
    ?>

    //----------------------------------------

    That is it!!!
    just try this and see how it works..




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    26
    Rep Power
    0
    Thanks for your help Shiju, but when I run the file I end up with an error stating that their is an error on this line:

    if (mysql_affected_rows($result) == 1){


    Consequently data is not inserted into the database.

    Regards

    Richard
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Oh sorry!!,

    we have missed an open bracket in insert statement.

    it should be:

    $sql="INSERT INTO contact (first_name, last_name) VALUES ('$first_name', '$last_name')";


    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited July 15, 2000).]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    26
    Rep Power
    0
    Thank you SR,

    That has got my tables cooking!

    Just to follow up. I based my code on a tutorial. I am a little dissatisfied after following the beginners tutorial from devshed by GJ Gillmore and now finding out I needed to take a completely different approach (as explained by RJ).
    Is it due to the code that is explained on devshed is written for SQL in general and not MySQL ?

    Just when I thought I was getting some where with this new language! Bummer..
    Regards

    Richard

Similar Threads

  1. Newbie needing help sending data to mysql database
    By blackface in forum PHP Development
    Replies: 3
    Last Post: February 13th, 2004, 01:26 AM
  2. Sending data from form to database securely!
    By dr.phil in forum PHP Development
    Replies: 2
    Last Post: February 12th, 2004, 07:52 AM
  3. Replies: 3
    Last Post: February 11th, 2004, 09:30 AM
  4. Retreiving data from a database
    By boddah in forum ASP Programming
    Replies: 0
    Last Post: January 30th, 2004, 06:55 PM
  5. trouble deleting data from database
    By skootz in forum PHP Development
    Replies: 3
    Last Post: January 13th, 2004, 06:15 AM

IMN logo majestic logo threadwatch logo seochat tools logo