Jump to content

newsletter subscribe


poleman

Recommended Posts

Hi, not sure where I'm going wrong with this... was working the other day...

Hope you can help...

 

PHP file:

<?php
$con = mysql_connect 
("db778.oneandone.co.uk","dbo191523062","*****");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("db191523062", $con);$sql="INSERT INTO Newsletter(name, 
email)
VALUES
('$_POST[name]','$_POST[email]')";if (!mysql_query 
($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Thank you for subscribing to the JSay Newsletter. We look forward to keeping you up to date with what's happening on JSay and in your community.";mysql_close($con)
?>

 

HTML

 

 

<form>
          </span><span style="font-family: tahoma; font-size: 13px">Name:</span></font><form method="POST" action="newsletter.php">
           
            <input type="text" name="name" size="12"><font color="#003366"><span style="font-family: tahoma; font-size: 13px"> 
            Email:</span></font><br>
            <font color="#003366">
            <span style="font-family: tahoma; font-size: 13px"><input type="text" name="email" size="20"><br>
            <button name="B1">Subscribe</button></span></font></p>
          </form>

 

Would also like to have it so that the redirect page goes back to the homepage. Think it has something to do with a Location: () command but not sure what it is and where to put it.

 

Thanks

Rich

 

 

Link to comment
Share on other sites

The problem is that when testing the "subsribe to newsletter" form, nothing happens. It is not sending the person's email address to my SQL database. Not sure what's wrong with the form or php code. Hope you can help and apologie for the code being lined through. No idea why it did that when posting.

Link to comment
Share on other sites

Ive modified your code so its more readable, added a little debugging and fixed a slight bug. Are you getting any errors?

 

<?php
  error_reporting(E_ALL) ; ini_set('display_errors',1);
  $con = mysql_connect("db778.oneandone.co.uk","dbo191523062","******");
  if (!$con) {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("db191523062", $con);
  $sql="INSERT INTO Newsletter(name, email) VALUES ('{$_POST['name']}','{$_POST['email']}')";
  if (!mysql_query($sql,$con)) {
    die('Error: ' . mysql_error().$sql);
  }
  echo "Thank you for subscribing to the JSay Newsletter. We look forward to keeping you up to date with what's happening on JSay and in your community.";mysql_close($con)
?>

 

PS; Ive also blanked out you password. DO NOT post your password on the board.

Link to comment
Share on other sites

No, no other errors:

 

This is the name of my homepage: http://www.jsay.co.uk/

 

Please try testing the subsribe form at the bottom right hand corner.

 

When I put in a test name and email, I get returned to the home page but with that funny url. No error message.

 

The php code I'm using is:

<?php
  error_reporting(E_ALL) ; ini_set('display_errors',1);
  $con = mysql_connect("db778.oneandone.co.uk","dbo191523061","******");
  if (!$con) {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("db191523061", $con);
  $sql="INSERT INTO Newsletter(name, email) VALUES ('{$_POST['name']}','{$_POST['email']}')";
  if (!mysql_query($sql,$con)) {
    die('Error: ' . mysql_error().$sql);
  }
  echo "Thank you for subscribing to the JSay Newsletter. We look forward to keeping you up to date with what's happening on JSay and in your community.";mysql_close($con)
?>

 

Hope you can help. Thanks.

 

Link to comment
Share on other sites

I'm not sure I get you...

 

my html form does go to newsletter.php.

 

It also does have a <form> element and closes it too..

 

Forum Newsletter:<br><form>
          </span><span style="font-family: tahoma; font-size: 13px">Name:</span></font><form method="POST" action="newsletter.php">
           
            <input type="text" name="name" size="12"><font color="#003366"><span style="font-family: tahoma; font-size: 13px"> 
            Email:</span></font><br>
            <font color="#003366">
            <span style="font-family: tahoma; font-size: 13px"><input type="text" name="email" size="20"><br>
            <button name="B1">Subscribe</button></span></font></p>
          </form>

 

posting to :

<?php
  error_reporting(E_ALL) ; ini_set('display_errors',1);
  $con = mysql_connect("db778.oneandone.co.uk","dbo191523061","*******");
  if (!$con) {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("db191523061", $con);
  $sql="INSERT INTO Newsletter(name, email) VALUES ('{$_POST['name']}','{$_POST['email']}')";
  if (!mysql_query($sql,$con)) {
    die('Error: ' . mysql_error().$sql);
  }
  echo "Thank you for subscribing to the JSay Newsletter. We look forward to keeping you up to date with what's happening on JSay and in your community.";mysql_close($con)
?>

 

Thank you for your time...

Link to comment
Share on other sites

here is the php form:

<?php
  error_reporting(E_ALL) ; ini_set('display_errors',1);
  $con = mysql_connect("db778.oneandone.co.uk","dbo191523061","*******");
  if (!$con) {
    die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("db191523061", $con);
  $sql="INSERT INTO Newsletter(name, email) VALUES ('{$_POST['name']}','{$_POST['email']}')";
  if (!mysql_query($sql,$con)) {
    die('Error: ' . mysql_error().$sql);
  }
  echo "Thank you for subscribing to the JSay Newsletter. We look forward to keeping you up to date with what's happening on JSay and in your community.";mysql_close($con)
?>

 

would also really like the redirect to not echo out that line but instead redirect them back tot he home page. Think you mentioned it needs a header Location thing or something, right? what would that be and where would it go in the code?

 

Thanks

Link to comment
Share on other sites

here is the php form

 

There is no such thing as a php form. The problem has already been pointed out in your html. You have a nested <form> tag.

 

Forum Newsletter:<br><form>
          </span><span style="font-family: tahoma; font-size: 13px">Name:</span></font><form method="POST" action="newsletter.php">

 

So the above php script is never being executed.

Link to comment
Share on other sites

is this better?

 

Forum Newsletter:<br><form method="POST" action="newsletter.php">

          </span><span style="font-family: tahoma; font-size: 13px">Name:</span></font>         

            <input type="text" name="name" size="12"><font color="#003366"><span style="font-family: tahoma; font-size: 13px">

            Email:</span></font><br>

            <font color="#003366">

            <span style="font-family: tahoma; font-size: 13px"><input type="text" name="email" size="20"><br>

            <button name="B1">Subscribe</button></span></font></p>

          </form>

 

Link to comment
Share on other sites

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.