473,416 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Need help with $_POST

I've just started messing around with PHP and believe it or not its extremely frustrating haha. Anyway, I wanted to make a simple input form that would display the info after submitting it...

The script is a simple html script, which calls a php script passing
it the variables which it got by the forms:

**************HTML doc. named "insert.htm"************************

<html>
<head>
<title>HTML Form</title>
</head>
<body>
<form ACTION="script1.php" METHOD=POST>
First Name<input TYPE=TEXT NAME="FirstName" SIZE=20><br>
Last Name <input TYPE=TEXT NAME="LastName" SIZE=20><br>
E-mail Address <input TYPE=TEXT NAME="Email" SIZE=60><br>
Comments <textarea NAME="Comments" ROWS=5 COLS=40></textarea><br>
<input TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
</form>

</body>
</html>



***************************PHP script named "script1.php"**********************

<HTML>
<HEAD>
<TITLE>Form Results</title>
<BODY>

<?
$FirstName = $_POST["FirstName"];
$LastName = $_POST["LastName"];
$Email = $_POST["Email"];
$Comments = $_POST["Comments"];
?>


<?php
/* This page receives and handles the data generated by "insert.html".
*/
print "Your first name is $_POST["FirstName"].<BR>\n";
[color=blue]
print "Your last name is $_POST["LastName"].<BR>\n";
[color=blue]
print "Your E-mail is $_POST["Email"].<BR>\n";
[color=blue]
print "This is what you had to say:<BR>\n$_POST["Comments"]<BR>\n";
[color=blue]
?>



</BODY>
</HTML>




I keep getting this error :


Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/grademyc/public_html/script1.php on line 17


with line 17 being
print "Your first name is $_POST["FirstName"].<BR>\n";
[color=blue]



i'm new to all this so i'm sure i've made mistakes somewhere...
please help...thanks!
Nov 30 '06 #1
9 1999
Try this code in your line 17
<br>I think it is because you did not concat:
print "Your first name is". $_POST["FirstName"]."<BR>\n";

If any other error occurred please write me
Nov 30 '06 #2
sorry about that, I figured it out last night...REALLY LATE NIGHT!...unfortunately the script isn't putting anything into the MySql database though....it just keeps putting blank entries in the table...any thoughts?

my code to connect to the database is as follows:


****************************************PHP******* *************************************

<?
$DBhost = "localhost";
$DBuser = "grademyc_me";
$DBpass = "********";
$DBName = "grademyc_users";
$table = "details";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$sqlquery = "INSERT INTO $table VALUES('$Name')";

$results = mysql_query($sqlquery);

mysql_close();

?>


************************************************** ***********************************

every time i try to update the database through my form is just creates a blank entry which is really annoying...i can obviously update the database via phpMyadmin, but that doesn't help me.....Thanks!
Danny
Nov 30 '06 #3
sorry about that, I figured it out last night...REALLY LATE NIGHT!...unfortunately the script isn't putting anything into the MySql database though....it just keeps putting blank entries in the table...any thoughts?

my code to connect to the database is as follows:


****************************************PHP******* *************************************

<?
$DBhost = "localhost";
$DBuser = "grademyc_me";
$DBpass = "********";
$DBName = "grademyc_users";
$table = "details";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$sqlquery = "INSERT INTO $table VALUES('$Name')";

$results = mysql_query($sqlquery);

mysql_close();

?>


************************************************** ***********************************

every time i try to update the database through my form is just creates a blank entry which is really annoying...i can obviously update the database via phpMyadmin, but that doesn't help me.....Thanks!
Danny
Hi ..
Try using the Insert statement with the table column name like ..

[PHP]$sqlquery = "INSERT INTO $table ('column_name_1','column_name_2', ..etc)VALUES('$value_1, $value_2', ..etc)";[/PHP]

Hope this will work ...good luck !
Nov 30 '06 #4
chesko
1
Hello I think tha you'll better use an echo and to use simple cotes for your variable from POST :

Expand|Select|Wrap|Line Numbers
  1. print "Your first name is $_POST["FirstName"].<BR>\n";
  2. [color=blue]  
  3.  
becomes
Expand|Select|Wrap|Line Numbers
  1. echo "Your first name is $_POST['FirstName'].<BR>\n";
  2.  
or

Expand|Select|Wrap|Line Numbers
  1. echo 'Your first name is '.$_POST['FirstName'].'<BR>\n';
bye

Chesko
Nov 30 '06 #5
ronverdonk
4,258 Expert 4TB
lovinlazio9: please read the Posting Guidelines at the top of this forum before you post anything else in this forum!

Especially the part about enclosing posted code within php, code or html tags!

Ronald :cool:
Nov 30 '06 #6
moishy
104 100+
What was the point of doing this:

$FirstName = $_POST['FirstName'];

If you're anyways gonna call the $_POST

print $_POST['FirstName'];

And not

print $FirstName;
Dec 1 '06 #7
To continue on from moishy's thought, (onto my own thought)
Sometimes when I used $_POST['name'] and then again later, it would show up blank. I was like it was erasing it. This was not consistent though, which really threw me for a spin, but it has only happened to me personally with IE 7.newest out.
Dec 1 '06 #8
kd8con
4
I think I would agree about the variable use rather than using POST. I always save the POSTed data to a variable as I know this will stick and it is easier to type as well.

I also think the echo is better than the print - but I don't have a clue why - I think it is just a personal preference.

Steve
Dec 2 '06 #9
ronverdonk
4,258 Expert 4TB
What was the point of doing this:

$FirstName = $_POST['FirstName'];

If you're anyways gonna call the $_POST

print $_POST['FirstName'];

And not

print $FirstName;
I hope you don't really use the $_POST in that way, moishy! You must have an endless trust in your fellow human beings. Ever heard of cross-site scripting?
You should always sanitize your outside data, especially the $_GET and $_POST arrays. They are the main source for XSS attacks.

Ronald :cool:
Dec 2 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tiernan | last post by:
Hey everybody. I'm verry new to PHP and MYSQL and have been working on a form that when it is submitted stores the information into a mysql database. The main problem is that i'm trying to finish...
5
by: Jerry Polyak | last post by:
Can someone give me a pointer, please. I am getting the following errors: Notice: Undefined index: sender_name in c:\program files\apache group\apache\htdocs\allinone_form.php on line 12 ...
9
by: Don Seckler | last post by:
I am trying to set up a PHP web page so I can enter data into a database. I created a form: <form action="admin_news_insert_processor.php" method="post" name="frm_Insert_News"...
1
by: JaNE | last post by:
Hello, I have made my cms... and is working, but have some, let me say "bugs"... And I don't know all reasons, please allow me slightly longer and most probably confusing post (that "confusing" is...
2
by: Jeffrey D Moncrieff | last post by:
I am trying to create a data base for colleting date for my research project. I have run in to a couple of problems and I need it fast ASAP I need it to be able to add data and edit them and view...
6
by: admin | last post by:
Hi, I have a mysql box that has a private network ip. The old developer was running our web server on this machine but the company since retired the box and it is in a closet, still running, but...
11
by: shror | last post by:
Hi every body, Please I need your help solving my php mail() function problem that the code is appearing in the view source and I dont know whats the problem where I am using another page tto test...
8
by: punitshrivastava | last post by:
Hi to All. I am Punit .I am back with new question .Please help me. I want to create one enquiry form in php.for this I code it: form code: <form name="enquiry" method="post" ...
2
by: Baldaris | last post by:
Hi I am using Xampp , Php 5.2.6 and phpedit for wiriting code. i am trying to add the content's from user form and then add then into the data base. It check's if submit is clicked or not ,...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.