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

?> 

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.