Jump to content

Scripts for review


ecabrera

Recommended Posts

why is it that when i try to submit it tells me add a picture but i did added

 

<?php 
//decarling some variables
$msg = "";

//begin if
if($_POST['submitbtn']){

$author = mysql_real_escape_string($_POST['author']);
$date = mysql_real_escape_string($_POST['date']);
$picture = $_FILES['picture']['name'];
$ext = strtolower(substr($name,strpos($name,'.')+1));
$size = $_FILES['picture']['size'];
$maxsize = 200000;
$type = $_FILES['picture']['type'];
$tmp = $_FILES['picture']['tmp_name'];
$review = mysql_real_escape_string($_POST['review']);

$move = "uploads/";

if(isset($author) && !empty($author)){
	if(isset($date) && !empty($date)){
		if(isset($picture) && !empty($picture)){
			if($size <= $maxsize){
				if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png'){
					if(move_uploaded_file($tmp,$move.$name)){
						if(isset($review) && !empty($review)){
							$query = mysql_query(" INSERT INTO reviews ('',author,date,picture,review) VALUES ('',$author,$date,$picture,$review)");
						}else
							$msg = "Please write a review";
					}else
						$msg = "Error has happen try again later";
				}else
					$msg = "Image must be a jpg, jpeg, or png";
			}else
				$msg = "You must select a smaller image size";
		}else
			$msg = "Select a picture";
	}else
		$msg = "Please enter a date";
}else
	$msg = "Please fill in the Authors name";
}
//ending the if here
?>

Link to comment
https://forums.phpfreaks.com/topic/260724-scripts-for-review/
Share on other sites

I don't think this is your entire code...

I want to read the code, since I can't really test it in it's current condition, but my problem with this is that you tell me your script gives you a message that I can't see anywhere in your code. What exactly does it output to you, and do you output the $msg variable? I would like to know what string the $msg variable points to.

Link to comment
https://forums.phpfreaks.com/topic/260724-scripts-for-review/#findComment-1336303
Share on other sites

the $msg is when i did somethng wrong it just display the erros

 

<?php include "header.php";?>
<?php if($email){?>

<?php include "inc/nav.php"; ?>

<div id="righthomecontent">
<?php 
//decarling some variables
$msg = "";

//begin if
if($_POST['submitbtn']){

$author = mysql_real_escape_string($_POST['author']);
$date = mysql_real_escape_string($_POST['date']);
$review = mysql_real_escape_string($_POST['review']);
$picture = $_FILES['picture']['name'];
$ext = strtolower(substr($picture,strpos($picture,'.')+1));
$size = $_FILES['picture']['size'];
$maxsize = 200000;
$type = $_FILES['picture']['type'];
$tmp = $_FILES['picture']['tmp_name'];

$move = "uploads/";

if(isset($author) && !empty($author)){
	if(isset($date) && !empty($date)){
		if(isset($picture) && !empty($picture)){
			if($size <= $maxsize){
				if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png'){
					if(move_uploaded_file($tmp,$move.$picture)){
						if(isset($review) && !empty($review)){
							$query = mysql_query(" INSERT INTO reviews ('',author,date,picture,review) VALUES ('',$author,$date,$picture,$review)");
						}else
							$msg = "Please write a review";
					}else
						$msg = "Error has happen try again later";
				}else
					$msg = "Image must be a jpg, jpeg, or png";
			}else
				$msg = "You must select a smaller image size";
		}else
			$msg = "Select a picture";
	}else
		$msg = "Please enter a date";
}else
	$msg = "Please fill in the Authors name";
}
//ending the if here
?>
<form class="createreview" action="createreview.php" method="post">
<table>
<tr>
<td></td>
<td><?php echo $msg;?></td>
</tr>
<tr>
<td>Author:</td>
<td><input type="text" name="author" size="30"/></td>
</tr>
<tr>
<td>Date:</td>
<td><input type="text" name="date" /></td>
</tr>
<tr>
<td>Main Picture</td>
<td><input type="file" name="picture" /></td>
</tr>
<tr>
<td>Review:</td>
<td><textarea name="review" cols="75" rows="27"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submitbtn" /></td>
</tr>
</table>
</form>

</div>
<?php } else 
{
echo "<center><h1>PLEASE LOGIN</h1></center>";
}
?>
<?php include "footer.php";?>

Link to comment
https://forums.phpfreaks.com/topic/260724-scripts-for-review/#findComment-1336304
Share on other sites

the $msg is when i did somethng wrong it just display the erros

 

<?php include "header.php";?>
<?php if($email){?>

<?php include "inc/nav.php"; ?>

<div id="righthomecontent">
<?php 
//decarling some variables
$msg = "";

//begin if
if($_POST['submitbtn']){

$author = mysql_real_escape_string($_POST['author']);
$date = mysql_real_escape_string($_POST['date']);
$review = mysql_real_escape_string($_POST['review']);
$picture = $_FILES['picture']['name'];
$ext = strtolower(substr($picture,strpos($picture,'.')+1));
$size = $_FILES['picture']['size'];
$maxsize = 200000;
$type = $_FILES['picture']['type'];
$tmp = $_FILES['picture']['tmp_name'];

$move = "uploads/";

if(isset($author) && !empty($author)){
	if(isset($date) && !empty($date)){
		if(isset($picture) && !empty($picture)){
			if($size <= $maxsize){
				if($ext == 'jpg' || $ext == 'jpeg' || $ext == 'png'){
					if(move_uploaded_file($tmp,$move.$picture)){
						if(isset($review) && !empty($review)){
							$query = mysql_query(" INSERT INTO reviews ('',author,date,picture,review) VALUES ('',$author,$date,$picture,$review)");
						}else
							$msg = "Please write a review";
					}else
						$msg = "Error has happen try again later";
				}else
					$msg = "Image must be a jpg, jpeg, or png";
			}else
				$msg = "You must select a smaller image size";
		}else
			$msg = "Select a picture";
	}else
		$msg = "Please enter a date";
}else
	$msg = "Please fill in the Authors name";
}
//ending the if here
?>
<form class="createreview" action="createreview.php" method="post">
<table>
<tr>
<td></td>
<td><?php echo $msg;?></td>
</tr>
<tr>
<td>Author:</td>
<td><input type="text" name="author" size="30"/></td>
</tr>
<tr>
<td>Date:</td>
<td><input type="text" name="date" /></td>
</tr>
<tr>
<td>Main Picture</td>
<td><input type="file" name="picture" /></td>
</tr>
<tr>
<td>Review:</td>
<td><textarea name="review" cols="75" rows="27"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submitbtn" /></td>
</tr>
</table>
</form>

</div>
<?php } else 
{
echo "<center><h1>PLEASE LOGIN</h1></center>";
}
?>
<?php include "footer.php";?>

Okay, but what error does it give you? There is no error called "add a picture". So what does it say?

Link to comment
https://forums.phpfreaks.com/topic/260724-scripts-for-review/#findComment-1336308
Share on other sites

Please correct me anyone if I'm wrong, but I think if(!empty()) does the same as if(isset()) just with an additional check to see if the variable is an empty string or not. So I don't think you need both every time, just if(!empty()).

 

You should turn on error reporting. Your code has a notice on this line:

if($_POST['submitbtn']){

Notice: Undefined index: submitbtn

I would suggest you use this instead:

if(isset($_POST['submitbtn'])){

 

The next notice I get is when I try to submit the picture, and I get 4 of them. "Undefined index: picture".

They happen when I try to get the data using $_FILES['picture'].

I therefor try to check if it is set at all:

if(isset($_FILES['picture'])){

echo 'picture is set';

}else{

echo 'picture is not set';

}

And it seems it's not, because I get the error, picture is not set.

 

So then let's look at your HTML.

After looking at it a bit closer, I see you miss the enctype parameter in the form tag.

<form class="createreview" action="" method="post" enctype="multipart/form-data">

Adding it seems to do the trick when it comes to the actually allowing the $_FILES to be set.

Link to comment
https://forums.phpfreaks.com/topic/260724-scripts-for-review/#findComment-1336317
Share on other sites

I knew i forgot the enctype but i couldn't remember

 

but one last thing why does it keep saying  you must select a smaller image if the maxsize is $maxsize = 200000;

Probably because your file is larger than 200kB....

 

I believe there is a setting in the php.ini file as well, but I don't think that's what's causing the error. 200kB is pretty small, so I think the image you are trying to upload is larger.

Link to comment
https://forums.phpfreaks.com/topic/260724-scripts-for-review/#findComment-1336320
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.