Hello There, Guest!
View New Posts  |  View Today's Posts
How to Build a Simple HTML Form Using PHP and MySQL?

  • 0 Vote(s) - 0 Average


12-30-2014, 06:16 PM #1
william7
Member
**
Posts: 205 Threads:49 Joined: Feb 2012 Reputation: 0

How to Build a Simple HTML Form Using PHP and MySQL?
I tried the html form and php code below on my website and couldn't get it to work. My database is on a hostgator cpanel. Does anybody know what the problem is? I got the message directly below when I tested it. The idea to try this came from the You Tube video, at https://www.youtube.com/watch?v=wp6Ngpk5XiY.

Quote:Parse error: syntax error, unexpected '', '' (T_CONSTANT_ENCAPSED_STRING) in /home1/will777/public_html/greendrinksforschools.info/contact/database.php on line 6

PHP Code:
<?php

define
('DB_NAME''myemaildata');
define('DB_USER''will777');
define('DB_PASSWORD''D241777');
define(DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
        die('
Could not connect' . mysql_error());

}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
    die('
Can\'t use ' DB_NAME ': ' mysql_error());

}



$value $_POST['Email'];

$sql "INSERT INTO EmailList (Email) VALUES ('$value')";

if (!
mysql_query($sql)) {
       die(
'Error: ' mysql_error());

}

mysql_close();
?>

Code:
<form action="database.php" method="post" />
            <p>Submit your email address here to receive my blog posts by email: <input type="text" name="Email" /><input type="submit" value="Submit" /></p>
            
            </form>
This post was last modified: 12-30-2014, 07:32 PM by william7.

12-30-2014, 06:44 PM #2
Epixors
(づ。◕‿‿◕。)づ・。*。✧・゜゜・。
*****
TLF Coders
Posts: 420 Threads:58 Joined: Aug 2012 Reputation: 6

RE: How Build a Simple HTML Form Using PHP and MySQL?
Your error comes from this line:

Code:
define(DB_HOST', 'localhost');

Remove the apostophe after DB_HOST.

The error points this out rather clearly so I urge you to read the message very thoroughly as it's a pretty obvious mistake. Learning how to interpret error logs will help you a lot.

12-30-2014, 07:34 PM #3
william7
Member
**
Posts: 205 Threads:49 Joined: Feb 2012 Reputation: 0

RE: How to Build a Simple HTML Form Using PHP and MySQL?
Thanks Epixors! I'm going to give that a try.

Double thanks!! It worked!
This post was last modified: 12-30-2014, 07:45 PM by william7.

12-30-2014, 08:16 PM #4
Louis
Master of the IRCs!
**
Posts: 153 Threads:23 Joined: May 2012 Reputation: 11

RE: How to Build a Simple HTML Form Using PHP and MySQL?
Whoa whoa whoa, do NOT use mysql_*, it's very insecure and not to mention depricated in PHP 5.5.0! I don't personally use MySQL as I'm a MongoDB fanboy, but I'm aware of the very terrible flaws of mysql_*! You should use MySQLi or PDO. My personal preference (when I've had no other choice but to use MySQL) has been PDO. I've had a few people suggest the same thing to me as well.
.
See the warning about mysql_* here: http://php.net/manual/en/function.mysql-connect.php

12-30-2014, 08:51 PM #5
william7
Member
**
Posts: 205 Threads:49 Joined: Feb 2012 Reputation: 0

RE: How to Build a Simple HTML Form Using PHP and MySQL?
I'll look into this Louis. Thanks for the advice!




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
  PNGb.in - Simple Image hosting KoBE 10 4,636 05-19-2014, 09:53 AM
Last Post: KoBE
  Make space with html without &nbsp; Crystalii 14 10,635 01-29-2013, 09:27 AM
Last Post: Adriana
  HTML Basics Part 3 Predator 7 4,942 01-23-2013, 02:35 AM
Last Post: Adriana
  HTML Basics 2 Predator 14 7,226 01-18-2013, 04:21 PM
Last Post: Adriana
  HTML Basics Part 1 Predator 1 1,598 01-13-2013, 05:10 AM
Last Post: Adriana


Users browsing this thread: 1 Guest(s)