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.
// 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.';
//$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.';
$sql = 'INSERT INTO `$database`.`Emp_Details` (
VALUES (".$title." , ".$fname." , ".$mdname.", ".$lname.", ".$res_add.", ".$res_tel.", ".$mobile.", ".$email.")';
echo'User information saved successfully.';
echo'Error: We encountered an error while inserting the new record.';
I would like to get the sum of all the fields in columns. where columns are dynamic even the rows are dynamic.
Hi here in my table the user can add column's dynamically, so i won't be knowing the columns name to raw code initially as $row['SUM(price)']. Hence I need a query which can pull by itself all the column values
Hello masters of web developing. I have an average experience in C# and I like to know that how much does it take to be a great developer in PHP by considering that I put my time on this 24/7. Why I didn't choose ASP.NET is that I think it is much time consuming than learning PHP and I like to work with current famous CMSes like Wordpress and Drupal.
// First we execute our common code to connection to the database and start the session
// At the top of the page we check to see whether the user is logged in or not
// If they are not, we redirect them to the login page.
// Remember that this die statement is absolutely critical. Without it,
// people can view your members-only content without logging in.
die("Redirecting to login.php");
?><html><body><linkrel="icon"type="image/gif"href="favicon.gif"/><?php include("header.php"); ?><divid="main-box"><ul><liclass="buttons"><?php
TEXT BOX WITH A LINE FROM **TEXT.txt** SHOULD APPEAR HERE AFTER USER CLICKS BUTTONS
<input type="button" name="account" value="Get Your Account" onclick="#" />
I want it so when the user clicks the button, a text box appears and displays ONE line from the text file and when they view it, it deletes it from the text file.
So after the user clicks the button it displays "Eddie" line to them and then deletes it after the user sees it so that the next line "Apples" would then become the first line.
If you don't understand my question then please let me know and I will try to explain further. Thank you.
I have a table fetched using ajax, according to the choice made from my dropdown menu. In the table I have some input fields. I need to save my inputs in the table while submitting it.
If I check the source code of the page I cannot find the table fields to post using $_post since ajax is used. I am really new to ajax. Can anybody please tell me how I can submit these table input values in PHP?