LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2003, 05:36 AM   #1
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Rep: Reputation: 30
Trouble recognising 'post' data in a php file


I'm trying to follow a tutorial to add image files as blobs to a mysql database.

The problem is that it doesn't seem to recognise the post '$action' variable is set (line 2), and loops to display the html code every time I hit 'submit'. Any ideas?

code (add.php)
_______________________________________________________

<?php
if ($action == "upload") {
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";
if (isset($binFile) && $binFile != "none") {
$data = addslashes(fread(fopen($binFile, "rb"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO tbl_Files ";
$sql .= "(description, bin_data, filename, filesize, filetype) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
$result = mysql_query($sql, $db);
mysql_free_result($result); // it's always nice to clean up!
echo "Thank you. The new file was successfully added to our database.<br><br>";
echo "<a href='main.php'>Continue</a>";
}
mysql_close();

} else {
?>
<HTML>
<BODY>
<FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
<INPUT TYPE="hidden" NAME="action" VALUE="upload">
<TABLE BORDER="1">
<TR>
<TD>Description: </TD>
<TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
</TR>
<TR>
<TD>File: </TD>
<TD><INPUT TYPE="file" NAME="binFile"></TD>
</TR>
<TR>
<TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<?php
}
?>
____________________________________________________________

The code came from this tutorial:
http://www.onlamp.com/pub/a/php/2000...php_mysql.html

I know my sql/php connections are ok...

Dave
 
Old 10-19-2003, 07:39 AM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Could it be having register gloabls set to off? Try changing the IF line to:
if ($_POST['action'] == "upload") {
 
Old 10-19-2003, 01:23 PM   #3
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
There are documented problems with HTTP POST in some versions of PHP. Make sure you are not running one of these versions cuz it won't work, period.

B.

http://www.php.net/
 
Old 10-19-2003, 03:49 PM   #4
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Original Poster
Rep: Reputation: 30
Thanks folks - the $_POST seems to be the cause. It still doesn't work fully, but it gets further than the post statement. I'll put in some echo statements and see how far I gwt in the morning. It's a bit hard to troubleshoot with Russell Crowe and the other Gladiators shouting on the TV in the background!

Once everything works for me, I'll post an article in LinuxQuestions that hopefully will help others...

Dave
 
Old 10-20-2003, 12:29 PM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You'll need to use:
$_POST['NAME']

subsituting NAME for your input field name troughtout your script.
 
  


Reply



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
PHP Question about POST data BrianK Programming 7 11-26-2005 01:33 PM
inserting the data thru php in a text file suchi_s Programming 5 02-02-2005 03:28 AM
file upload with php+libcurl via POST Cupacabra Linux - Software 0 01-12-2005 12:53 PM
php, apache, POST/GET data jhaiduce Linux - Software 0 12-17-2003 04:02 PM
php post data sql queries... bulliver Programming 2 01-03-2003 02:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:10 PM.

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