Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 09-29-2004, 02:14 PM   #1
Registered: Jan 2004
Location: Hyderabad , India
Distribution: RHL 9
Posts: 42

Rep: Reputation: 15
PHP:Unable to post variables from html form to mysql database

hello experts,

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


Following is the code ...

<TITLE> email entry form </TITLE>

<P>plz fil the form </P>

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

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




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


//$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("your info has been recorded");


Old 09-29-2004, 03:01 PM   #2
Senior Member
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Turn register globals back off. If you have register globals set then you can access your post variables using regular syntax ie: $foo_var but it is not secure or advised. Instead turn register globals off and access your vars thusly: $_POST['foo_var'] as you appear to be doing already.

There are also several typos in your code, I am not sure if that is the code you are running or just typos introduced when posting here but....

try this:
mysql_connect("localhost","root") or die("Failure on db connection");
$query = "INSERT INTO sample SET
    $name = $_POST['givename'],
    $address = $_POST['givenaddress']";
$result = mysql_query($query) or die("Unable to record your info");
print("your info has been recorded");
As you can see...there are no quotes around the post variable, otherwise the literal value "$_POST['whatever']" will be used, or perhaps just an error.

I am also unsure of this line:
I don't think that php will interpolate this variable as Perl would. Try this:
print("result:" . $result);

Good luck.

Last edited by bulliver; 09-29-2004 at 03:04 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML Form for a postgresql database Evan P. Linux - Software 1 02-12-2007 07:43 AM
PHP and HTML Form Post Savahn Programming 12 06-30-2004 03:15 PM
Post information not coming through PHP form. m3kgt Programming 5 04-02-2004 01:42 PM
willing to pay $$$ PHP / Javascript multiple paged form; carrying over variables micro_sucks General 1 12-26-2003 09:37 AM
Problems with php 4.2.1 form-data and hidden variables coea77 Programming 1 10-10-2002 03:24 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration