...

View Full Version : loop is not working in php..........help me...



mds8000
08-04-2007, 08:13 PM
hi all,
code below is for inserting an image to database.....control is not entering into the "if" loop when the page is submitted :confused: ......i dont know why.....pls help me....

---------------------------


<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","sa");
mysql_select_db("signup");
$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">

<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>

------------------------------
CREATE TABLE binary_data (
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
description CHAR(50),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
);

-----------------------------
thanks in advance.............

PappaJohn
08-04-2007, 08:17 PM
First of all, please post your code between [code] tags or
tags - makes it easier to help you.

I don't see where you are obtaining the value for $submit, so I'm assuming it's supposed to be from the form.

Try changing:
[php]
if ($submit) {

to


if ($_POST['submit']) {

mds8000
08-04-2007, 08:33 PM
Warning: fread(): supplied argument is not a valid stream resource in C:\Program Files\Apache Group\Apache2\htdocs\ex.php on line 21

PappaJohn
08-04-2007, 10:26 PM
With the way your server is configured, you can not access any variable submitted by a form simply by using:


$form_data

For each such variable, you'll have to use the form:


$_POST['variable_name']


For more info - http://us2.php.net/manual/en/security.globals.php

abhay.dashy
08-06-2007, 06:28 AM
yes PappaJohn is right you have to use POST['variable name'] or GET['variable name'] depending upon method in form tag...

or u can use REQUEST['variable name'].

try this it should solve your problem.:thumbsup:

s_pradeep
08-06-2007, 07:42 AM
$data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'], "r"), filesize($_FILES['form_data']['tmp_name'])));



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum