Jump to content

New to PHP help with form


steve_spi

Recommended Posts

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

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');

?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.