I am definitely a newbie. I am running through as many tutorials as I can, and have been working on the Binary Data + PHP + MySQL tutorial on this site. Very easy to follow...
However, I am running into a problem, and being a newbie don't know where to start looking for an answer.
I am using PHP 4.2.3, MySQL 3.23.51 on WIN 2000 Pro / IIS configuration. I have successfully created and tested various .php documents to my IE 6 browser, and have successfully tested creating a web page that pulls data from a mySQL database that I created-- so I know that at least that much is set up correctly.
However, now I am trying to "post" or "submit" data to the database a la the tutorial mentioned above (Binary Data + mySQL + PHP ) . So, following the tute, I created a binary_data database, table, and structure. No problem. Then I created my store.php file and placed the following code into the page:
<?php
// store.php3 - by Florian Dittmer <dittmer@gmx.net>
// Example php script to demonstrate the storing of binary files into
// an sql database. More information can be found at http://www.phpbuilder.com/
?>
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
// code that will be executed if the form has been submitted:
if ($submit) {
// connect to the database
// (you may have to adjust the hostname,username or password)
MYSQL_CONNECT("localhost","root","password");
mysql_select_db("binary_data");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// else show the form to submit new data:
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</BODY>
</HTML>
Ok, all good so far, right?
Well, when I test the php page, which I saved to my wwwroot directory, I get the following error message along with the form:
Notice: Undefined variable: submit in c:\inetpub\wwwroot\store.php on line 15
I am taking this to mean that the following line in my code is the problem:
if ($submit) {
as this is line 15 in my store.php file.
Can anyone point out to me what I might be missing, and / or doing wrong? Again, simple select statements, etc. seem to be working fine from my php pages. I am not an expert at forms, either- could I be missing something?
Thanks!
ecco