poleman Posted February 11, 2007 Share Posted February 11, 2007 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 Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 Besides the fact that your code is terribly hard to read, what is the problem? Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 Thanks....but it still isn't working. This is the url I get given instead of the thankyou message: http://www.jsay.co.uk/?name=richard&email=test%40tes.tocm&B1= I changed the name of the databse before posting but won't put passwords up again. thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 Sorry, but that code cannot generate that url. Are you getting any errors? Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 The problem is your form does not post to the above script. In fact you have no opening <form> element. Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 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... Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 <form>s need action="" and method="" Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 but i have that in my html form form method="POST" action="newsletter.php"> ??? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2007 Share Posted February 11, 2007 You have two forms, so I only saw the first one. Forum Newsletter:<br><form> </span><span style="font-family: tahoma; font-size: 13px">Name:</span></font><form method="POST" action="newsletter.php"> Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 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 Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 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> Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 yes! it worked! now how do i get the success page to redeirect back the the homepage?? Quote Link to comment Share on other sites More sharing options...
poleman Posted February 11, 2007 Author Share Posted February 11, 2007 yes! it worked!! now how do i get the page to redirect back to my homepage instead of echoicing out the thank you message? Its something to do with the Location: function but not sure what it is or where to put it in the php code. Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 header("Location :foo.php"); Where foo is the name of the file you wish to direct too. Quote Link to comment Share on other sites More sharing options...
poleman Posted February 12, 2007 Author Share Posted February 12, 2007 how do i put the html into the php file? the html page i would like to go into the foo.php file can be found at www.jsay.co.uk once this is done, where exaclty do i put the header("Location :foo.php"); line in the code? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.