While inserting data from a form into a database i am getting error in the below code only. The error displayed is : ( ! ) Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting ']' -
$sql= "INSERT INTO Persons (FirstName,LastName,Age) VALUES('$_POST[FirstName ]','$_POST[LastName]','$_POST[Age]')";
-
-
if (!mysqli_query($con,$sql))
-
{
-
die('Error: ' . mysqli_error($con));
-
}
-
echo "1 record added";
-
-
mysqli_close($con);
-
?>
-
what does the displayed error mean? what is the possible solution?
check this $_POST[FirstName ]'
should it be this $_POST[FirstName]' ?
8 1858 zmbd 5,501
Expert Mod 4TB
check this $_POST[FirstName ]'
should it be this $_POST[FirstName]' ?
The proposed solution does not work. The following error was displayed:
Database mi_db created successfullyTable persons created successfully
( ! ) Notice: Undefined index: FirstName in C:\wamp\www\insert.php on line 29
Call Stack
# Time Memory Function Location
1 0.0027 252088 {main}( ) ..\insert.php:0
( ! ) Notice: Undefined index: LastName in C:\wamp\www\insert.php on line 29
Call Stack
# Time Memory Function Location
1 0.0027 252088 {main}( ) ..\insert.php:0
( ! ) Notice: Undefined index: Age in C:\wamp\www\insert.php on line 29
Call Stack
# Time Memory Function Location
1 0.0027 252088 {main}( ) ..\insert.php:0
1 record added
Please suggest the possible solution...?
The proposed solution does not work.
it did work. you just hit the next problem the previous error was hiding (because it triggered a script exit first).
The next error being that the variable with those names were not passed to the PHP page.
So what is the solution to the above error?
The code is: -
-
<?php
-
// Connects to your Database
-
$con = mysqli_connect("localhost", "root", "mysql@777") or die(mysqli_error());
-
$db_selected = mysqli_select_db($con, 'mi_db');
-
if (!$db_selected)
-
{
-
die ('Can\'t use mi_db : ' . mysqli_error());
-
}
-
$sql= "INSERT INTO Persons (FirstName,LastName,Age) VALUES('$_POST[FirstName]','$_POST[LastName]','$_POST[Age]')";
-
-
if (!mysqli_query($con,$sql))
-
{
-
die('Error: ' . mysqli_error($con));
-
}
-
echo "1 record added";
-
-
mysqli_close($con);
-
?>
-
enclosed herewith the code of the above program.Please suggest in view of the above code possible solution of the same.
zmbd 5,501
Expert Mod 4TB
New Question, New Thread.
Respectfully, we ask that each thread contain only one question.
Please start a new thread and, if needed, you can include a link to this thread for context.
Thnx
Ok & Thanks
I have posted a new thread linked to this as :PHP script for inserting a form data to a database. Suggest Possible solution of the problem?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: c676228 |
last post by:
Hi all,
I think I have data type problem when I tried to insert data into sql server
200.
The erroe message is like this:
system.invalidcastexception
data type DFlage char(1) in sql 2000,
DMI...
|
by: Doc11 |
last post by:
I'm trying to allow users insert data into a database using the form view. But when I click the insert button I get this error:
Server Error in '/Customer Database' Application....
|
by: rahia307 |
last post by:
hi to all
i want to use Aajx in php and want to insert data into database. but i have no idea about it. if any one have idea for it please help me
|
by: SuvarnaChaudhari |
last post by:
Hi,Plz any one can tell me how to insert data in database through GridView,or there is no way,then plz tell me another way(I mean,should I use DetailView?but how?)
Thaknk You!
|
by: chathura86 |
last post by:
public void insertData(String sql)
{
if(conn != null)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn ; //setting the connection to sql command
...
|
by: bobbyze |
last post by:
how to insert data into database using php with OOP structure
|
by: ghjk |
last post by:
I want to insert web application data to mysql database. I'm using struts, jsp and hibernet.This is my action class.
public ActionForward execute(ActionMapping mapping, ActionForm form,
...
|
by: abisiva |
last post by:
Hi,
I am new for PHP OOP concept.
Pls give some example source code for "How to insert data using oops concept?" I want to improve my knowledge. pls any one help me....
I know below the basic...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |