Take the 2-minute tour ×

I created this form:

<form method="post" action="process-form.php" id="emailForm" name="emailForm"      target="_self">  
    <h4>Sign up to be notified when we go live!</h4>
<label for="email">E-mail</label>
    <input type="text" name="email" id="email" />
<input type="submit" name="submit" id="submit" value="Submit"  onclick="return alert('Thanks! Your email has been added.');">

    <p>emails will not be shared with third parties</p>

With this php code


//open database connect
$username = "username";
$password = "password";
$hostname = "server"; 

$conn = mysql_connect($hostname, $username, $password);
if (!$conn) die('Could not connect: ' . mysql_error());

//emaillist is the name of the database

//Clean data
function clean_data($string){
  if (get_magic_quotes_gpc()){
    $string = stripslashes($string);
  $string = strip_tags($string);
  return mysql_real_escape_string($string);

//Mail Header removal
function remove_headers($string){
  $headers = array(

    $string = preg_replace($headers, '', $string);
    return strip_tags($string);

//Pick up cleaned data
$email = clean_data($_POST['email']);

//Insert data
//emails is the name of the table
$query ="INSERT INTO emails (email)
  VALUES ('$email')";


//close Connection

//redirect to page
header('Location: defaultUpCyc.html');

Everything was working fine and dandy in my testing environment and for a couple of days when I put it live. However, I went to my database to see if any emails were submitted and its totally empty. I have put test emails into the form and checked the db and there is nothing. I haven't changed a thing since I put it live so I'm at a loss. Here is the test site: http://upcycledonline.com/test/Site/defaultUpCyc.html

Thanks for the help!

share|improve this question
Your code isn't doing any kind of error reporting at all or even checking if events were successful. mysql_connect, for example, will either return a database handle or false if it failed to connect to the database. You're not checking whether or not mysql_connect returned a valid db handle though, so how is your script supposed to know if it failed to connect to the database? There are any number of points in the code where you're not checking if the operation succeeded, your script may be failing on any one of those points. –  GordonM Nov 12 '11 at 19:11
I should have mentioned that I am a newb to most of this. –  bjstone15 Nov 12 '11 at 19:25
As a side note, you should start using the OO MySQLi class as this allows you to access the functionality provided by MySQL 4.1 and above –  Chief17 Nov 12 '11 at 20:14
add comment

4 Answers

up vote 1 down vote accepted

The form tag on your test site doesn't have its action defined which means it's sending the data to itself and HTML can't work with databases.

share|improve this answer
Would you expand on this more? –  bjstone15 Nov 12 '11 at 19:35
Sure, you're not submitting the data to that process-form.php file of yours - see the code on your test site: <form id="landing"> –  Shomz Nov 12 '11 at 19:39
Thanks Shomz! I didn't even see that that was in there! –  bjstone15 Nov 12 '11 at 20:00
No problem! It's usually small and stupid things that make most of our problems. :) Is everything ok now? –  Shomz Nov 12 '11 at 20:02
Yep, working like a charm :D –  bjstone15 Nov 14 '11 at 3:43
add comment

i dont know how to add code here so i made a paste: http://pastebin.com/baPUPhbt you may use this

share|improve this answer
add comment

i think your problem is at that onclick javascript, try to remove it, it may work

share|improve this answer
No luck Keli :( –  bjstone15 Nov 12 '11 at 19:40
add comment

you should check to see if your connection works by adding:

if (!$conn) { die('Could not connect: ' . mysql_error()); }

also check firebug to make sure the form posts with the data. you could also echo out your query to check the format. everything looks good otherwise, so my assumption is the db connection is bad.

just a guess though :)

share|improve this answer
Thanks Robert. I have added if (!$conn) die('Could not connect: ' . mysql_error()); right after I make my connect. I still am not getting an error though. How would I go about echoing my query to check the format? –  bjstone15 Nov 12 '11 at 19:27
you could just echo $query; or silently error_log($query); which will be in your error logs of your server. –  Robert Van Sant Nov 12 '11 at 19:29
not sure if you have access to bash but if you do mysql -h HOSTNAME -uUSERNAME -p DATABASE you should be able to access your mysql database from command line. you then can run your query to see if it inserts or errors out. just more added debugging tips :) –  Robert Van Sant Nov 12 '11 at 19:33
hhmm I don't know about if I have bash or not but I will look into it. Thanks! –  bjstone15 Nov 12 '11 at 19:36
add comment

Your Answer


