emediastudios Posted November 13, 2007 Share Posted November 13, 2007 I get this error Notice: Undefined variable: count in C:\Program Files\Apache Group\Apache2\htdocs\Prepare2win\admin\upload_news.php on line 42 In my code below <?php require_once('../Connections/p2w.php'); error_reporting(E_ALL); //This is the directory where images will be saved $target = "../news/"; //This gets all the other information from the form $headline=$_POST['headline']; $contents=$_POST['contents']; $photo1=($_FILES['photo1']['name']); $photo2=($_FILES['photo2']['name']); $photo3=($_FILES['photo3']['name']); $title1=$_POST['title1']; $title2=$_POST['title2']; $title3=$_POST['title3']; $link=$_POST['link']; //Writes the photo to the server for ($x=1;$x<=3;$x++){ $photo ='photo'.$x; $target = "../news/" . basename( $_FILES[$photo]['name']); if (($_FILES[$photo]["type"] == "image/gif") || ($_FILES[$photo]["type"] == "image/png") || ($_FILES[$photo]["type"] == "image/jpeg") || ($_FILES[$photo]["type"] == "image/pjpeg") && ($_FILES[$photo]["size"] < 1000000)){ if(move_uploaded_file($_FILES[$photo]['tmp_name'], $target)){ //Tells you if its all ok echo "Success."; $photo=""; } } else { //Gives and error if its not ++$count; } } if ($count > 0){ ///////////////////////line 42////////////////// echo $count .'failed to upload '; } else { //Writes the information to the database $host="localhost"; // Host name $username="root"; // Mysql username $password="5050888202"; // Mysql password $db_name="preparetowin"; // Database name $tbl_name="news"; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query("INSERT INTO `news` VALUES (NULL,'$headline','$contents','$photo1','$photo2','$photo3','$title1','$title2','$title3','$link')") ; print "<meta http-equiv=\"refresh\" content=\"0;URL=news_added_successfully.php\">"; } ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 13, 2007 Share Posted November 13, 2007 and what is line 42?? Quote Link to comment Share on other sites More sharing options...
bwochinski Posted November 13, 2007 Share Posted November 13, 2007 Initialize the variable before your for-loop. $count = 0; // <<========== Add this //Writes the photo to the server for ($x=1;$x<=3;$x++){ (Edit: clarified addition) Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 13, 2007 Share Posted November 13, 2007 what do you mean itialize $x=1 means $x = 1 its intialized Quote Link to comment Share on other sites More sharing options...
emediastudios Posted November 13, 2007 Author Share Posted November 13, 2007 sorry but still getting errors, how would i add that to my code? thanks 4 the help guys. Quote Link to comment Share on other sites More sharing options...
bwochinski Posted November 13, 2007 Share Posted November 13, 2007 I tried to clarify my previous post after cooldude posted... You just need to add: $count = 0; At the top where you set up the rest of your variables before you start the for loop. You're getting an error because if all the uploads in your script are successfull, $count is never incremented, so when you test for " if ($count > 0) ", it doesn't like the comparison of " if ( NULL > 0 ) ". Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 13, 2007 Share Posted November 13, 2007 I tried to clarify my previous post after cooldude posted... You just need to add: $count = 0; At the top where you set up the rest of your variables before you start the for loop. You're getting an error because if all the uploads in your script are successfull, $count is never incremented, so when you test for " if ($count > 0) ", it doesn't like the comparison of " if ( NULL > 0 ) ". this wont cause an error if(NULL >0) this is valid even if you have null values it will still compare the two but try also to initialize your variable maybe its a version issue of php Quote Link to comment Share on other sites More sharing options...
emediastudios Posted November 13, 2007 Author Share Posted November 13, 2007 Thanks, that did the trick. :) Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 13, 2007 Share Posted November 13, 2007 null == 0 //true null === 0 // false Quote Link to comment Share on other sites More sharing options...
bwochinski Posted November 13, 2007 Share Posted November 13, 2007 Yeah teng's right, so never mind my earlier attempt at an explanation. Can't really say why what I recommended worked. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.