5 Replies - 1325 Views - Last Post: 20 November 2008 - 11:34 AM Rate Topic: -----

#1 Ghost rider  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 158
  • Joined: 29-October 08

Not display the message after upload image file

Posted 20 November 2008 - 06:02 AM

Help please. The script is upoading sucessfully image files into database, but it's not showing any message such as:

Your files is successfully store in database


or

The file is bigger than the allowed size please resize


This the script

<?php
if ($_POST['Submit']) {

if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
//print_r($_FILES);
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test");
$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size']));

$query = sprintf("INSERT INTO image(Image, FileType) VALUES('%s', '%s')", $photo, $_FILES['file']['type']);
if (mysql_query($query)) {
$messages[] = "Your files is successfully store in database"; 
} else {
$messages[]= mysql_error();
}
} 
else {
$messages[]="The file is bigger than the allowed size please resize";
}
}
?>
<html>
<head>
<title>Add Image</title>
</head> 
<body>
<? 
if (isset($messages)) { 
foreach ($messages as $message) {
print $message. "<br>";
} 
}
?>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="file">
<input type="hidden" name="MAX_FILE_SIZE" value="96000">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html> 


Is This A Good Question/Topic? 0
  • +

Replies To: Not display the message after upload image file

#2 Hary  Icon User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 427
  • Joined: 23-September 08

Re: Not display the message after upload image file

Posted 20 November 2008 - 06:13 AM

You have PHP errors of, as you cannot do $messages[]=, if messagges is empty. It resutls in a warning and a non-set $messages.

Before you do it the first time, do: $messages = array(). However, $messages is now set, so you have to change isset($messages) to count($messages) >1
Was This Post Helpful? 0
  • +
  • -

#3 Ghost rider  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 158
  • Joined: 29-October 08

Re: Not display the message after upload image file

Posted 20 November 2008 - 07:41 AM

View PostHary, on 20 Nov, 2008 - 05:13 AM, said:

You have PHP errors of, as you cannot do $messages[]=, if messagges is empty. It resutls in a warning and a non-set $messages.

Before you do it the first time, do: $messages = array(). However, $messages is now set, so you have to change isset($messages) to count($messages) >1


I apolosized for forget to use word thank. That why I'm thanking you for your time and I do apprecciated for your help.

I did tried to do what you said but I'm getting this error.

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\addPhoto.php on line 14


could let me know where I should put this particular code on script

$messages[]=array


I placed it like this on script

if (mysql_query($query)) {
$messages = array()

Was This Post Helpful? 0
  • +
  • -

#4 Hary  Icon User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 427
  • Joined: 23-September 08

Re: Not display the message after upload image file

Posted 20 November 2008 - 07:49 AM

You forgot the ; after the =array()

furthermore, now you only create an array in $message if the query is correcy. You always need to create a (empty) array, otherwise you cannot add a new element to it (which is what [] does)

Like this, it should work:
<?php
if ($_POST['Submit']) {

if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
//print_r($_FILES);
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test");
$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size']));

$query = sprintf("INSERT INTO image(Image, FileType) VALUES('%s', '%s')", $photo, $_FILES['file']['type']);
$messages = array();
if (mysql_query($query)) {
$messages[] = "Your files is successfully store in database";
} else {
$messages[]= mysql_error();
}
}
else {
$messages[]="The file is bigger than the allowed size please resize";
}
}
?>
<html>
<head>
<title>Add Image</title>
</head>
<body>
<?
if (count($messages) > 0) {
foreach ($messages as $message) {
print $message. "<br>";
}
}
?>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="file">
<input type="hidden" name="MAX_FILE_SIZE" value="96000">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html> 


This post has been edited by Hary: 20 November 2008 - 07:52 AM

Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2993
  • View blog
  • Posts: 10,347
  • Joined: 08-August 08

Re: Not display the message after upload image file

Posted 20 November 2008 - 08:02 AM

Let's try to get the grammar straight too:
"Your files have been successfully stored in the database."
or
"Your files were successfully stored in the database."
or
"Your file was successfully stored in the database."
but not
"Your files is successfully store in database"

Paying attention to details is important in any language, including both PHP and English.

This post has been edited by CTphpnwb: 20 November 2008 - 08:06 AM

Was This Post Helpful? 0
  • +
  • -

#6 Ghost rider  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 158
  • Joined: 29-October 08

Re: Not display the message after upload image file

Posted 20 November 2008 - 11:34 AM

View PostHary, on 20 Nov, 2008 - 06:49 AM, said:

You forgot the ; after the =array()

furthermore, now you only create an array in $message if the query is correcy. You always need to create a (empty) array, otherwise you cannot add a new element to it (which is what [] does)

Like this, it should work:
<?php
if ($_POST['Submit']) {

if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
//print_r($_FILES);
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test");
$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size']));

$query = sprintf("INSERT INTO image(Image, FileType) VALUES('%s', '%s')", $photo, $_FILES['file']['type']);
$messages = array();
if (mysql_query($query)) {
$messages[] = "Your files is successfully store in database";
} else {
$messages[]= mysql_error();
}
}
else {
$messages[]="The file is bigger than the allowed size please resize";
}
}
?>
<html>
<head>
<title>Add Image</title>
</head>
<body>
<?
if (count($messages) > 0) {
foreach ($messages as $message) {
print $message. "<br>";
}
}
?>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="file">
<input type="hidden" name="MAX_FILE_SIZE" value="96000">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html> 



It works and I appreciated for your help. Thanks
I'm trying to figure, how to create the script that I'll be able to view the images after been loaded into the database. Just the same concept when we post how messages in forum. Have you got some guidance about it! Thanks in advance.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1