Posting HTML Form data to MySQL via PHP

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Posting HTML Form data to MySQL via PHP

    I just need a correct PHP statement that will allow me to instert a record
    into a MySQL database/table. The "mysql_query(" statment used below does
    not work.
    ----------------------------------------------------------------------------
    $hostname="mysql5.secureserver.net";
    $username="xxxxxxx";
    $password="yyyyyy";
    $dbname="zzzzzzzz";
    $usertable="Visitors";
    $verbindung = @mysql_connect($hostname, $username, $password)or die
    ("Failed");
    mysql_select_db($dbname);

    $firstname=$_POST['firstName'];
    $lastname=$_POST['lastName'];
    $address1=$_POST['address1'];
    $address2=$_POST['address2'];
    $city=$_POST['city'];
    $state=$_POST['state'];
    $zipcode=$_POST['zipCode'];
    $country=$_POST['Country'];
    $phone=$_POST['phone'];
    $email=$_POST['eMail'];

    mysql_query("INSERT INTO $usertable VALUES
    '$firstname','$lastname','$address1','$address2',' $city','$state','$z
    ipcode','$country','$phone','$email'");

    mysql_close($verbindung);
    echo "<br>Done...";
    ?>
    ----------------------------------------------------------------------------
    -

    --Mark


    "Mark Johnson" <mdjohns5@comcast.net> wrote in message
    news:4oKdnax6JMVsh-HcRVn-rA@comcast.com...
    > I have a very straight forward FORM in a HTML page with 10 fields (name,
    > address, phone, email, etc.)
    >
    > On the backend I have a MySQL database/table defined with the
    corresponding
    > fields.
    > (FirstName, LastName,Address1,Address2,City,State,ZipCode,Coun try, Phone,
    > Email)
    >
    > I need to know what PHP syntax to use to store the data caputred in the
    FORM
    > to to the MySQL database. (This is not rocket science, I am just a newbie
    to
    > MySQL/PHP.)
    >
    > Here is the syntax for my HTML form:
    > ---------------------------------------
    > <form action="scripts/mySQLTest.php" method="post" name="reg" id="reg">
    >
    > Here is the syntax for the PHP script: (UID/PWD changed to protect the
    > innocent ;?)
    > --------------------------------------------------------------------------
    --
    > ---------
    > <?php
    > //Database Connection Syntax for PHP and MySQL.
    > //Connect To Database
    >
    > $hostname="mysql5.secureserver.net";
    > $username="xxxxxxx";
    > $password="yyyyyy";
    > $dbname="zzzzzzzz";
    > $usertable="Visitors";
    >
    > mysql_connect($hostname,$username, $password) OR DIE ("<html><script
    > language='JavaScript'<alert('Unable to connect to database! Please try
    again
    > later.'),history.go(-1)</script></html>");
    >
    > mysql_select_db($dbname);
    > ?????????????????????????????????????????????????? ???????????????
    > echo "Done";
    > ?>
    > --------------------------------------------------------------------------
    --
    > -----------------
    >
    > I know the database is set up correctly because I have been able to
    manually
    > add records (via the Admin panel) and then write a PHP script to read that
    > data and echo it out to a HTML page.
    >
    > I am using Macromedia Dreamweaver to create the HTML and PHP. When the
    FORM
    > is selecetd in Dreamweaver, I can choose to alter the following
    properties:
    > * Action (scripts/mySQLtest.php)
    > * Method (default, GET or POST) ???
    > * Enctype ("", application/x-www-form-urlencoded, or multipart/form-data)
    > ???
    >
    > In addition to needing the PHP line to post to MySQL, I need some guidance
    > on what to choose for the ablve "Method" and "Enctype" (or does it
    matter).
    >
    > Thanks in advance!
    >
    > Mark
    >
    >


    Mark Johnson Guest

  2. Similar Questions and Discussions

    1. Form Data not posting...
      Hi, Here is the action script from movie. When I click submit the from data loads I can see it with trace. However when it gets posted to CFpage...
    2. ASP.NET not posting form data
      Dear all, We are a library and are trying to get an ASP.NET form page working on our site. the buttons and fields appear, but we are still having...
    3. getting data from mysql to display in html form
      hi guys, i have a mysql database with usersnames in it. i am creating a html form with a multiple listing field. i want to get the usernames form...
    4. Posting data from MySQL?
      If you had gone to alt.php.sql first you could have found the answer without posting. There's a standard way of doing things over there which goes...
    5. Help: Posting data from MySQL?
      rob@exau.com wrote: I'm not sure what you want, but let's see. As you have a <tr> statement that opens up each time you enter the loop, you...
  3. #2

    Default Re: Posting HTML Form data to MySQL via PHP

    > mysql_query("INSERT INTO $usertable VALUES
    > '$firstname','$lastname','$address1','$address2',' $city','$state','$z
    > ipcode','$country','$phone','$email'");
    Missing ( ) around the values after VALUES
    mysql_query("INSERT INTO $usertable VALUES
    ('$firstname','$lastname','$address1','$address2', '$city',
    '$state','$zipcode','$country','$phone','$email')" );


    Dae



    Daedalus Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139