...

View Full Version : Help me to fix undefined index on my php code



luxersus
02-20-2012, 03:29 AM
1.<?php
2.$db_connect = mysql_connect ('localhost', 'root', '');
3.if (!$db_connect) {
4. die ('cannot connect: ' . mysql_error());
5. }
6.
7.$db_select = mysql_select_db ('trial', $db_connect);
8.if (!$db_select) {
9. die ('cant connect: ' . mysql_error());
10. }
11.
12.$FirstName = $_POST['Fn'];
13.$LastName = $_POST['Ln'];
14.
15.$sql = "INSERT INTO sample (FirstName, LastName) VALUES ('$FirstName', '$LastName')";
16.if (!mysql_query($sql)) {
17.die ('cant connect: ' . mysql_error());
18.}
19.
20.mysql_close ();
21..?>

Notice: Undefined index: Fn in C:\wamp\www\trial\last.php on line 12
Notice: Undefined index: Ln in C:\wamp\www\trial\last.php on line 13


HELP ME TO FIX THE ERROR :(

MarPlo
02-20-2012, 06:14 AM
Hi
In the form that sends data to that php script you should have fields with: name="Fn", and name="Ln" .

cercos
02-20-2012, 07:29 AM
or try:



if(!empty($POST)) {
$FirstName = $_POST['Fn'];
$LastName = $_POST['Ln'];
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum