Form data to sql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wileee
    New Member
    • Sep 2007
    • 2

    Form data to sql database

    Hi,

    I'm trying to setup a web form that will put data into a sql database. I had everything working with a simple test database (first name, last name, phone number). But once I added "address" and "city" to the process, the data collected in the database simply shows "Array(address) " or "Array(city )" and not the actual data I typed into the form. (The other fields work normally).

    Any help would be appreciated.

    Here is my code:

    [CODE=php]<?php

    $EntryDate= date('Y-m-d H:i:s');

    $con = mysql_connect(" localhost", "login", "password") ;
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_selectdb( "database_name" , $con);

    $sql="INSERT INTO data (`EntryDate`, `FirstName`, `LastName`, `Institution`, `Address`, `City`)
    VALUES
    ('$EntryDate', '$_POST[fname]', '$_POST[lname]', '$_POST[inst]', '$_POST(address )', '$_POST(city)' )";

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

    mysql_close($co n);

    ?>[/CODE]
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    [CODE=php]
    ('$EntryDate', '$_POST[fname]', '$_POST[lname]', '$_POST[inst]', '$_POST[address]', '$_POST[city]' )";
    [/CODE]

    Mind the Brackets. It should be square ones. not the parenthesis.

    Comment

    • wileee
      New Member
      • Sep 2007
      • 2

      #3
      Guess I was in a hurry to get things working.

      Thank you very much.

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Originally posted by wileee
        Guess I was in a hurry to get things working.

        Thank you very much.
        Glad to hear that.Good luck with your projects. If you ever need anything post back to the Forum.

        Comment

        Working...