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 Link to comment https://forums.phpfreaks.com/topic/121834-new-to-php-help-with-form/ 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 Link to comment https://forums.phpfreaks.com/topic/121834-new-to-php-help-with-form/#findComment-628579 Share on other sites More sharing options...
waynew 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'); ?> Link to comment https://forums.phpfreaks.com/topic/121834-new-to-php-help-with-form/#findComment-628580 Share on other sites More sharing options...
waynew 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? Link to comment https://forums.phpfreaks.com/topic/121834-new-to-php-help-with-form/#findComment-628581 Share on other sites More sharing options...
waynew Posted August 29, 2008 Share Posted August 29, 2008 For mail() mail("[email protected]","subject","bodyofemail"); Or you could: $sent = mail("[email protected]","subject","bodyofemail"); if(!$sent){ echo "Not sent"; } Link to comment https://forums.phpfreaks.com/topic/121834-new-to-php-help-with-form/#findComment-628582 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.