Forum Moderators: coopster

Message Too Old, No Replies

n00b and its not working - form processing into database

form processing into database

         

adamdwalker

12:08 am on Oct 28, 2005 (gmt 0)

10+ Year Member



Hi, i have posted on another webmaster forum but had no look so you all have a new member yey!

<?
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();

$db_name ="web13_adsadsa";
$table_name ="details1";
$server = "localhost";
$dbusername = "web13_asdsadsadsa";
$dbpassword = "asdsadsadsadsadsdas";

$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());

$un = $_POST['un'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$bcl= $_POST['bcl'];
$whereborn= $_POST['whereborn'];
$nsn = $_POST['nsn'];
$md = $_POST['md'];
$wheremarried = $_POST['wheremarried'];
$mc1 = $_POST['mc1'];
$mc2 = $_POST['mc2'];
$nextofkin = $_POST['nextofkin'];

$query = "INSERT INTO details1 ('un', 'name', 'phone', 'email', 'dob', 'bcl', 'whereborn', 'nsn', 'md', 'wheremarried', 'mc1', 'mc2', 'nextofkin')
values ('&un', '&name', '$phone', '$email', '$dob', '$bcl', '$whereborn', '$nsn', '$wheremarried', '$mc1', '$mc2', '$nextofkin')"
or die(mysql_error());

header('Location:../index.htm');
?>

the script sends you to index.htm but doesnt insert anything into the db and yes the un and pw e.t.c. are correct.

Regards

Walker

panos

2:22 am on Oct 28, 2005 (gmt 0)

10+ Year Member



Hello adamdwalker and welcome to Webmasterworld :)

The $query variable is only a string.

You should add:

mysql_query("$query");

before:

or die(mysql_error());

adamdwalker

5:30 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



ok, ta i tried and got some funny error but ive spotted a stupid mistake & instead of $.

Anyway ive played around and looked at other workign codes

and got this now


<?
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();

$db_name ="erm";
$table_name ="details1";
$server = "localhost";
$dbusername = "erm";
$dbpassword = "erm";

$connection = mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = mysql_select_db($db_name,$connection)or die(mysql_error());

$un = $_POST['un'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$bcl= $_POST['bcl'];
$whereborn= $_POST['whereborn'];
$nsn = $_POST['nsn'];
$md = $_POST['md'];
$wheremarried = $_POST['wheremarried'];
$mc1 = $_POST['mc1'];
$mc2 = $_POST['mc2'];
$nextofkin = $_POST['nextofkin'];

$sql = "INSERT INTO $table_name ('un', 'name', 'phone', 'email', 'dob', 'bcl', 'whereborn', 'nsn', 'md', 'wheremarried', 'mc1', 'mc2', 'nextofkin')
values ('$un', '$name', '$phone', '$email', '$dob', '$bcl', '$whereborn', '$nsn', '$wheremarried', '$mc1', '$mc2', '$nextofkin')";

$result = @mysql_query($sql,$connection) or die(mysql_error());

header('Location:../index.htm');
?>


basically i think it might be something to me not assigning the $sql to anything as the other script im using is to register the user and it has

$sql ="SELECT * FROM $table_name WHERE username= '$_POST[username]'";

and this works.

basically all i want to do is wack everything from the form into a database im not bothered about checking it against a username / password i just want it to go into the table under the correct hendings.

Cheers

adamdwalker

6:06 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



solved on another board thanks