-2

I am having a problem with a newsletter subscription I am writing. The problem is I don't seem to be getting any errors or in fact anything at all when someone clicks submit, all that happens is they are presented with a blank white page and nothing more, so its difficult to diagnose.

Basically the policy reminder form has a field on it called newslettersubscribe, if this is equal to yes the user is also subscribed to the newsletter list as well as the policy reminder list they are signing up for. I am not 100% sure if I am using the real_escape_string functions correctly though or not ?.

<?php
$email = real_escape_string($_POST['email']);
$name = real_escape_string($_POST['name']);
$newslettersubscribe = real_escape_string($_POST['newslettersubscribe']);
if ($newslettersubscribe == 'no'){
}
else{
mysql_query("INSERT INTO ymeg_chronoforms_data_NewsletterDesigner (email, name)
VALUES ('$email', '$name')") or die(mysql_error());
}
?>

EDIT >>>>>>>>>>>>>>>>>>>

If I remove the real escape string I get the error

Unknown column 'email' in 'field list'

when hitting submit, so that probably explains the white page, what does the above error mean ?.

EDIT 2 >>>>>>>>>>>>>>>>>

This is a sample record from the database im trying to connect to :

cf_id   6
cf_uid  5f04f21f80a596f17341cec92a48b197
cf_created  2012-06-01 10:13:16
cf_modified     
cf_ipaddress    217.154.186.84
cf_user_id  44
name    Iain Simpson
email   test@1testdsdsfswqewed.csdom
Iain Simpson
  • 8,011
  • 13
  • 47
  • 66
  • 1
    what does your html looks like? Are the values getting posted? – Grumpy Jun 01 '12 at 13:28
  • use `mysql_real_escape_string`. Also, `or die()` ain't good practice, use proper error handling. – Tikkes Jun 01 '12 at 13:28
  • How do you know it's "dying"? It looks like if either `$newslettersubscribe` was set to `'no'` or if the query succeeds, then no output will be generated. Maybe you should add some `echo` statements to see what's really happening. – nickb Jun 01 '12 at 13:34
  • Because it takes out the whole website theme with it when you hit submit, where as before it was keeping the nav bar, header footer etc, now it dies to white. – Iain Simpson Jun 01 '12 at 13:59

1 Answers1

1

Try echoing values to make sure it isn't an issue with simply defaulting to

$newslettersubscribe = 'no';

You would need to do something simple like the following:

$email = real_escape_string($_POST['email']);
$name = real_escape_string($_POST['name']);
$newslettersubscribe = real_escape_string($_POST['newslettersubscribe']);

echo $email.' | '.$name.' | '.$newslettersubscribe;
exit();

That should at least show you what your values are for the required variables. Its all about simply troubleshooting what is coming in, and how it impacts your sql query.

Jakub
  • 20,418
  • 8
  • 65
  • 92
  • I have tried echoing the values and they echo out fine, its when I try to add them to the table it goes crazy. Now I have temp removed the real escape strings I am getting the error : Unknown column 'email' in 'field list' – Iain Simpson Jun 01 '12 at 14:23
  • 'field list' would imply that its the database schema that is missing the column 'email', what is the DB schema? Can you post it and add to your question? – Jakub Jun 01 '12 at 14:25
  • The datebase it is posting to is ymeg_chronoforms_data_NewsletterDesigner Columns = cf_id (primary key) cf_uid name email – Iain Simpson Jun 01 '12 at 14:28
  • try swapping the order of columns/values, see if you get something like 'name' not found in 'field list' could be a typo somewhere for table maybe. – Jakub Jun 01 '12 at 14:30
  • If I swap the order I then get : Unknown column 'name' in 'field list' – Iain Simpson Jun 01 '12 at 14:33
  • ok so your database table name is invalid, none of the columns are in there... the issue is with inserting into invalid columns for one reason or another. – Jakub Jun 01 '12 at 14:36
  • You were right one the money !, I had miss spelt the table !, thanks :-) – Iain Simpson Jun 01 '12 at 14:36