Jump to content

Recommended Posts

Hi-

 

I am new with php and mysql and having a good bit of trouble setting up an email subscriber

form on a website I maintain. The site is hosted with godaddy and, after 2 days on the phone

with them I've come to the conclusion that while I'm not the brightest bulb on the tree, they

really don't want to be of much help.

 

I purchased a "website building for dummies" type book which contained the following code, meant by the author

as a "works across the board" kind of document. Unfortunately, it doesn't work in this case.

 

When I input information from the form I created it seems fine, but then when I check the database,

a new record has been created but the fields are empty.The database is simple in that only

three fields are required, the "ID", the subscriber's name, and the subscriber's email address.

 

Can anyone tell he either a) what is wrong with the php document below or b) does anyone

have a sample document that they know works with godaddy hosting that I might use?

 

Thanks in advance. here's the code that doesn't properly:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

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

<title>Untitled Document</title>

</head>

 

<body>

 

<?php

$Name=$_POST['Name'];

$EMail=$_POST['EMail'];

$connection=mysql_connect ("databaseaddress",

"myusername", "mypassword") or die ('I cannot

connect to the database.');

mysql_select_db ("mydatabase",$connection) or die(

"Unable to select database");

$query = "INSERT INTO `mytable` (`ID`, `Name`,

`EMail`) VALUES ('', '$Name', '$EMail')";

mysql_query($query);

mysql_close();

?>

</body>

</html>

 

One last thing...when building the database I used the following field settings:

ID:

type-integer, legnth-4, collation-empty, attributes-unsigned, null-no, default-empty, extra-auto_increment, primary key

Name:

type-varchar, length-40, collation-UTF8_unicode_ci, attributes-empty, null-no, default-empty, extra-empty

EMail:

type-varchar, length-40, collation-UTF8_unicode_ci, attributes-empty, null-no, default-empty, extra-empty

 

When I created the database I used the default setting for the database type (MyISAM).

 

Thanks to anyone who can shed some light on this for me.

Link to comment
https://forums.phpfreaks.com/topic/178124-php-and-mysql-fields-empty/
Share on other sites

Just as a side note to what mikesta707 said, the name of form fields are case sensitive. So if you have

 

<!-- this on your form -->
<input type="text" name="name" />

<?php
// and this in your script
$Name=$_POST['Name'];
?>

 

.. $Name will be a blank variable because you are looking in the $_POST array for an item with the key of 'Name', when the value is stored with the key of 'name'.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.