Click here to Skip to main content
15,890,717 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: How to install xampp or Lamp in Ubuntu 8 Pin
Mohibur Rashid30-Apr-13 17:19
professionalMohibur Rashid30-Apr-13 17:19 
GeneralRe: How to install xampp or Lamp in Ubuntu 8 Pin
Rony Sur2-Jul-13 0:09
professionalRony Sur2-Jul-13 0:09 
AnswerRe: How to install xampp or Lamp in Ubuntu 8 Pin
Tushar Guru8-Sep-14 22:17
Tushar Guru8-Sep-14 22:17 
QuestionHow to get data from the other website in php Pin
surendra4u20-Mar-13 1:04
surendra4u20-Mar-13 1:04 
AnswerRe: How to get data from the other website in php Pin
dusty_dex20-Mar-13 3:21
dusty_dex20-Mar-13 3:21 
QuestionIRDA without IR Pin
lukeer25-Feb-13 22:30
lukeer25-Feb-13 22:30 
AnswerRe: IRDA without IR Pin
Richard MacCutchan25-Feb-13 23:52
mveRichard MacCutchan25-Feb-13 23:52 
QuestionRecord insertion error in php Pin
maniedru7-Feb-13 0:59
maniedru7-Feb-13 0:59 
Hello,
I am pretty new to php and i am trying my hands on something little but i"m getting a persistent error.
I am trying to insert a record into the database but i keep getting the error saying the record wasn't inserted.
i checked the databse and there's really nothing there.

Below is the php code. Please let me know the error and guide me through the changes.

<?php 
//function submit(){
// Define database credentials
$host = 'localhost';
$user = 'admin';
$password = '12345';
$database = 'staff_db';
// Create db connection
$conn = mysql_connect($host,$user,$password) or die('Error: Could not connect to database - '.mysql_error());
// Once connected, we can select a database
mysql_select_db($database,$conn) or die('Error in selecting the database: '.mysql_error());

// Grab user input and sanitize 
$title = mysql_real_escape_string(filter_var(trim($_POST['Title']), FILTER_SANITIZE_STRING));
$fname = mysql_real_escape_string(filter_var(trim($_POST['FirstName']), FILTER_SANITIZE_STRING));
$mdname = mysql_real_escape_string(filter_var(trim($_POST['MiddleName']), FILTER_SANITIZE_STRING));
$lname = mysql_real_escape_string(filter_var(trim($_POST['LastName']), FILTER_SANITIZE_STRING));
$res_add = mysql_real_escape_string(filter_var(trim($_POST['Resid_Add']), FILTER_SANITIZE_STRING));
if(! $res_tel = mysql_real_escape_string(filter_var(trim($_POST['Resid_Tel']), FILTER_SANITIZE_NUMBER_INT)))
{
	echo 'Please enter a valid telephone number.';
	};
if(! $mobile = mysql_real_escape_string(filter_var(trim($_POST['Mobile']), FILTER_SANITIZE_NUMBER_INT)))
{
	echo 'Please enter a valid mobile number.';
	die();
	};
//$frmstaff_status = mysql_real_escape_string(filter_var(trim($_POST['frmStaff_Status']), FILTER_SANITIZE_STRING));

// Validate the user email
if(! $email = filter_var(trim($_POST['Email']), FILTER_VALIDATE_EMAIL))
{     
    echo 'Please enter a valid email.';
    die();
}

$sql = 'INSERT INTO `$database`.`Emp_Details` (
`Title` ,
`First_Name` , 
`Middle_Name`,
`Last_Name` ,
`Res_Add` ,
`Res_Tel` ,
`Mobile` ,
`Email` 
)
VALUES (".$title." , ".$fname." ,  ".$mdname.", ".$lname.", ".$res_add.", ".$res_tel.", ".$mobile.", ".$email.")';

if(mysql_query($sql))
{
    echo 'User information saved successfully.';
}else
{
    echo 'Error: We encountered an error while inserting the new record.';
}
mysql_close($conn);
//}

?>


Thanks.
AnswerRe: Record insertion error in php Pin
Graham Breach7-Feb-13 2:32
Graham Breach7-Feb-13 2:32 
GeneralRe: Record insertion error in php Pin
maniedru7-Feb-13 5:08
maniedru7-Feb-13 5:08 
GeneralRe: Record insertion error in php Pin
Graham Breach7-Feb-13 7:10
Graham Breach7-Feb-13 7:10 
GeneralRe: Record insertion error in php Pin
maniedru28-Feb-13 3:14
maniedru28-Feb-13 3:14 
Questionrevenue, tax and shipping not working in google analytics tracking code! how to do it working? Pin
Lê Đình Thanh Hải28-Jan-13 20:17
Lê Đình Thanh Hải28-Jan-13 20:17 
Questionsum of all the fields in columns. where columns are dynamic Pin
Indudhara28-Jan-13 3:22
Indudhara28-Jan-13 3:22 
AnswerRe: sum of all the fields in columns. where columns are dynamic Pin
Mohibur Rashid11-Mar-13 22:14
professionalMohibur Rashid11-Mar-13 22:14 
Questionhow to get a object according the name of class Pin
Keanu L18-Jan-13 16:31
Keanu L18-Jan-13 16:31 
AnswerRe: how to get a object according the name of class Pin
Graham Breach18-Jan-13 22:31
Graham Breach18-Jan-13 22:31 
GeneralRe: how to get a object according the name of class Pin
Keanu L6-Feb-13 1:28
Keanu L6-Feb-13 1:28 
QuestionHow much time does it take to be a great developer in PHP? Pin
atoi_powered17-Jan-13 13:34
atoi_powered17-Jan-13 13:34 
QuestionRe: How much time does it take to be a great developer in PHP? Pin
Richard MacCutchan17-Jan-13 23:19
mveRichard MacCutchan17-Jan-13 23:19 
AnswerRe: How much time does it take to be a great developer in PHP? Pin
Manfred Rudolf Bihy18-Jan-13 4:50
professionalManfred Rudolf Bihy18-Jan-13 4:50 
QuestionDispensing text from a text file Pin
John Smith8-Jan-13 19:56
John Smith8-Jan-13 19:56 
AnswerRe: Dispensing text from a text file Pin
Zamshed Farhan12-Jan-13 3:03
Zamshed Farhan12-Jan-13 3:03 
QuestionSubmitting an ajax fetched table Pin
AkkiMo2-Jan-13 4:03
AkkiMo2-Jan-13 4:03 
QuestionI have a trouble about query_insert(). Pin
陳建勳24-Dec-12 1:31
陳建勳24-Dec-12 1:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.