steve_spi Posted August 29, 2008 Share Posted August 29, 2008 Hello Im Completely New to PHP... I am trying to build a website with a number of forms. I have managed to build a simple form, which will then update my SQL database... This all seemed pretty ok, but for some reason. After the script has updated, I want it to go to a new website. At the moment all I can do is get it to open a blank page with some text on it... Also on some forms, I want the the details to be added, which then populates mysql table. But I always want to be able to get the person to attached a document which is also emailed to email address... Can you help. This is what I has so far... <?php $con=mysql_connect("localhost", "username", "password"); mysql_select_db("username", $con); if (!$con) {die('Could not connect: ' . mysql_error());} mysql_select_db("my_db", $con);$sql="INSERT INTO persn (FirstName, LastName, Age, Position) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]','$_POST[position]')";if (!mysql_query($sql,$con)) {die('Error: ' . mysql_error());} echo "http://www.newtophp.co.uk"; mysql_close($con) ?> Many thanks, Stephen Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted August 29, 2008 Share Posted August 29, 2008 For redirecting to a different page or site use Header function eg: header('Location: sitename.com'); exit; For mailing the user use mail() function.(http://in2.php.net/manual/en/function.mail.php) Regards Ranju Quote Link to comment Share on other sites More sharing options...
waynewex Posted August 29, 2008 Share Posted August 29, 2008 May I suggest this: <?php $con=mysql_connect("localhost", "username", "password"); mysql_select_db("username", $con); if (!$con) {die('Could not connect: ' . mysql_error());} $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); $age = mysql_real_escape_string($_POST['age']); $position = mysql_real_escape_string($_POST['position']); mysql_select_db("my_db", $con);$sql="INSERT INTO persn (FirstName, LastName, Age, Position) VALUES ('$firstname','$lastname','$age','$position')"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } mysql_close($con) header('Location: http://www.newtophp.co.uk'); ?> Quote Link to comment Share on other sites More sharing options...
waynewex Posted August 29, 2008 Share Posted August 29, 2008 Also, you may have meant to do this, but you have the name of your table set to persn. Was this supposed to be person? Quote Link to comment Share on other sites More sharing options...
waynewex Posted August 29, 2008 Share Posted August 29, 2008 For mail() mail("emailyouraresendingto@email.com","subject","bodyofemail"); Or you could: $sent = mail("emailyouraresendingto@email.com","subject","bodyofemail"); if(!$sent){ echo "Not sent"; } 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.