By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

PHP:Unable to post variables from html form to mysql database

P: n/a
hello experts,
Plz dont treat this as another newbie query , i did my homework but
still getting nowhere :( :( :(

Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD).Unable to
post data from html form to php file(connecting to mysql database and
inserting into a table) .
This seemingly simple problem is making me go mad !!! I googled
extensively and already tried the following

I enabled " register_globals = On " .... in /etc/php.ini and
also took used _$POST syntax.

wot could be the problem .... is it the case that /etc/php.ini file is
not being read .... how do i know whether this is the default location
for php.ini?
Where can i find the PHPRC environment variable (the variable
responsible for the php.ini default location)

Is the problem something else .....?

Plz help me out experts!!!!

Thx Adv

Regards,
Sammista.

Following is the code ...

form.html
---------
<HTML>
<HEAD>
<TITLE> email entry form </TITLE>
</HEAD>
<BODY>

<P>plz fil the form </P>

<FORM METHOD="POST" ACTON="form-handler.php">

NAME: <BR>
<INPUT TYPE=TEXT NAME="givename" SIZE=25> <BR>
AGE: <br>
<INPUT TYPE=TEXT NAME="givenaddress" SIZE=25> <BR>

<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
form-handler.php
-----------------
<HTML>
<HEAD>
<TITLE> EMAIL FORM HANDLER </TITLE>
</HEAD>

<BODY>

<?
mysql_connect("localhost","root") or die("Failure on db connection");

mysql_select_db("mydb");

//$query = " insert into sample(name,address)
values(_$POST['givename'],_$POST['givenaddress'])";
$query = " INSERT INTO sample SET
name = '_$POST[givename]',
address = '_$POST[givenaddress]' ";

$result = mysql_query($query) or die("Unable to record your info");
print("result:$result");
print("your info has been recorded");

?>

</body>
</html>
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
jf
_$POST ???

$_POST !!

or if it isn't the problem try in a file info.php:
<?php phpinfo(); ?>
On 29 Sep 2004 12:23:12 -0700
sa*******@gmail.com (sammmista) wrote:
hello experts,
Plz dont treat this as another newbie query , i did my homework but
still getting nowhere :( :( :(

Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD).Unable to
post data from html form to php file(connecting to mysql database and
inserting into a table) .
This seemingly simple problem is making me go mad !!! I googled
extensively and already tried the following

I enabled " register_globals = On " .... in /etc/php.ini and
also took used _$POST syntax.

wot could be the problem .... is it the case that /etc/php.ini file is
not being read .... how do i know whether this is the default location
for php.ini?
Where can i find the PHPRC environment variable (the variable
responsible for the php.ini default location)

Is the problem something else .....?

Plz help me out experts!!!!

Thx Adv

Regards,
Sammista.

Following is the code ...

form.html
---------
<HTML>
<HEAD>
<TITLE> email entry form </TITLE>
</HEAD>
<BODY>

<P>plz fil the form </P>

<FORM METHOD="POST" ACTON="form-handler.php">

NAME: <BR>
<INPUT TYPE=TEXT NAME="givename" SIZE=25> <BR>
AGE: <br>
<INPUT TYPE=TEXT NAME="givenaddress" SIZE=25> <BR>

<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
form-handler.php
-----------------
<HTML>
<HEAD>
<TITLE> EMAIL FORM HANDLER </TITLE>
</HEAD>

<BODY>

<?
mysql_connect("localhost","root") or die("Failure on db connection");

mysql_select_db("mydb");

//$query = " insert into sample(name,address)
values(_$POST['givename'],_$POST['givenaddress'])";
$query = " INSERT INTO sample SET
name = '_$POST[givename]',
address = '_$POST[givenaddress]' ";

$result = mysql_query($query) or die("Unable to record your info");
print("result:$result");
print("your info has been recorded");

?>

</body>
</html>

Jul 17 '05 #2

P: n/a
sammmista wrote:
hello experts,
Plz dont treat this as another newbie query , i did my homework but
still getting nowhere :( :( :(

Trying to learn PHP on Fedora core 1 (PHP 4.3,MySQL,HTTPD).Unable to
post data from html form to php file(connecting to mysql database and
inserting into a table) .
This seemingly simple problem is making me go mad !!! I googled
extensively and already tried the following

I enabled " register_globals = On " .... in /etc/php.ini and
also took used _$POST syntax.

<snip>

1.
it is NOT _$POST but $_POST!

2.
to check if your ini is used try the command phpinfo(); you can see your
settings then - if you change something it should be there too.

3.
try to turn error reporting on when developing scripts. do this by
starting your script with something like
<?php
error_reporting(E_ALL);

that might put out a lot of notices too but helps writing clean code.

4.
to find out where php looks for his ini just turn to the manual. i
prefer using the directive in the apache httpd.conf

PHPIniDir "/your/path"

regards
sh

--
"The goal of Computer Science is to build something that will last at
least until we've finished building it." -- unknown
Jul 17 '05 #3

P: n/a
sammmista wrote:
I enabled " register_globals = On " .... in /etc/php.ini and
also took used _$POST syntax.
Famous last words: "I don't know how to deactivate this time bomb. I
better press every button I see."
wot could be the problem .... is it the case that /etc/php.ini file is
not being read .... how do i know whether this is the default location
for php.ini?
<?php phpinfo(); ?>
Where can i find the PHPRC environment variable (the variable
responsible for the php.ini default location)
Somewhere in the source code.
Is the problem something else .....?
Yes, it is.
<FORM METHOD="POST" ACTON="form-handler.php">
"ACTON" should be "action".
<?
You don't want to start this block with "<?". Use "<?php".
$query = " INSERT INTO sample SET
name = '_$POST[givename]',
address = '_$POST[givenaddress]' ";
Ouch!

Look up the syntax for INSERT and use $_POST instead of _$POST. If you
go to your php.ini and set your error_reporting to E_ALL, you might be
able to find some of those errors by yourself.
$result = mysql_query($query) or die("Unable to record your info");


Not very friendly, eh? Have a look at mysql_error().

Regards,
Matthias
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.