varun7952 Posted February 18, 2012 Share Posted February 18, 2012 hi i m new to php there is two basic script i m testing on my localhost but it gives me error "( ! ) Notice: Undefined index: video in C:\wamp\www\Boysjoys\video\upload.php on line 4" "( ! ) Notice: Undefined index: video in C:\wamp\www\Boysjoys\video\upload.php on line 16" "( ! ) Notice: Undefined index: video in C:\wamp\www\Boysjoys\video\upload.php on line 27" i cant find where is the real problem is ##########FORM########### <form name="upload" action="upload.php" method="POST" enctype="multipart/form-data"> <input type="file" name="video"> <input type="submit" value="UPLOAD"> </form> #########FORM############ #########PHP############# <?php // This is the directory where images will be saved $path="uploaded/"; $path=$path.basename($_FILES["video"]["name"]); //This gets all the other information from the form $video=$_FILES["video"]["name"]; //connect to database $con=mysql_connect("localhost","root","") or die (mysql_error()); //SELECTING THE DATABASE mysql_select_db("admin_bj",$con) or die(mysql_error()); //write information to the database mysql_query("INSERT INTO 'video'(video) VALUES('$video')"); //write file to server if(move_uploaded_file($_FILES["video"]["tmp_name"],$path)) { // execute if all is ok echo "the file " . basename( $_FILES['uploadedfile']['name']). "has been uploaded and your information has been added to the server"; } else { //GIVES AND ERROR IF ITS NOT OK echo "Sorry,there was a problem in uploading."; } ?> #########PHP############# Quote Link to comment Share on other sites More sharing options...
thePhpLady Posted February 18, 2012 Share Posted February 18, 2012 Hi there, Try to add this: if (isset($_POST['action'])) { This should set the variable. Hope it helps Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 18, 2012 Author Share Posted February 18, 2012 Hi there, Try to add this: if (isset($_POST['action'])) { This should set the variable. Hope it helps thanks but this also not helping its still showing the same error Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2012 Share Posted February 18, 2012 At what point do you get these error notices? Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 18, 2012 Author Share Posted February 18, 2012 At what point do you get these error notices? soon after submitting the form Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2012 Share Posted February 18, 2012 Add this to your script, immediately after the opening <?php tag so you can see what the form is actually sending. echo '-----POST-----<br><pre>'; print_r($_POST); echo '</pre>-----FILES-----<br><pre>'; print_r($_FILES); echo </pre>'; Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 18, 2012 Author Share Posted February 18, 2012 Add this to your script, immediately after the opening <?php tag so you can see what the form is actually sending. echo '-----POST-----<br><pre>'; print_r($_POST); echo '</pre>-----FILES-----<br><pre>'; print_r($_FILES); echo </pre>'; ok i did ths also ths will mk array bt this return a blank array nothing else bt with same error Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2012 Share Posted February 18, 2012 Even after selecting a file and clicking submit? Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 19, 2012 Author Share Posted February 19, 2012 Even after selecting a file and clicking submit? yes after selecting a file nd cliking submit button form is a different page and it action attribute set to upload.php where alll the php thing is placed Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted February 19, 2012 Share Posted February 19, 2012 video needs to be array in the form <input type="file" name="video[]"> Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 19, 2012 Author Share Posted February 19, 2012 video needs to be array in the form <input type="file" name="video[]"> this is not helping in anyway Quote Link to comment Share on other sites More sharing options...
Drummin Posted February 19, 2012 Share Posted February 19, 2012 Sure you have directory "uploaded" in same path or relationship to the file upload.php? Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 19, 2012 Author Share Posted February 19, 2012 Sure you have directory "uploaded" in same path or relationship to the file upload.php? yes directory is there also Quote Link to comment Share on other sites More sharing options...
Drummin Posted February 19, 2012 Share Posted February 19, 2012 Does changing these to single quotes make a difference? $path=$path.basename($_FILES['video']['name']); //This gets all the other information from the form $video=$_FILES['video']['name']; I can't get code to fail. Seems to be working fine. Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 19, 2012 Author Share Posted February 19, 2012 Does changing these to single quotes make a difference? $path=$path.basename($_FILES['video']['name']); //This gets all the other information from the form $video=$_FILES['video']['name']; I can't get code to fail. Seems to be working fine. i already tried this can ne1 try ths at thr own localhost Quote Link to comment Share on other sites More sharing options...
Drummin Posted February 19, 2012 Share Posted February 19, 2012 One more try. <?php // This is the directory where images will be saved if (isset($_FILES['video'])){ $path="uploaded/"; $path=$path.basename($_FILES["video"]["name"]); //This gets all the other information from the form $video=$_FILES["video"]["name"]; //connect to database $con=mysql_connect("localhost","root","") or die (mysql_error()); //SELECTING THE DATABASE mysql_select_db("admin_bj",$con) or die(mysql_error()); //write information to the database mysql_query("INSERT INTO `video`(video) VALUES('$video')"); //write file to server if(move_uploaded_file($_FILES["video"]["tmp_name"], $path)) { // execute if all is ok echo "the file " . basename( $_FILES['video']['name']). "has been uploaded and your information has been added to the server"; } else { //GIVES AND ERROR IF ITS NOT OK echo "Sorry,there was a problem in uploading."; } }//if (isset($_FILES['video'])){ ?> Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 19, 2012 Author Share Posted February 19, 2012 One more try. <?php // This is the directory where images will be saved if (isset($_FILES['video'])){ $path="uploaded/"; $path=$path.basename($_FILES["video"]["name"]); //This gets all the other information from the form $video=$_FILES["video"]["name"]; //connect to database $con=mysql_connect("localhost","root","") or die (mysql_error()); //SELECTING THE DATABASE mysql_select_db("admin_bj",$con) or die(mysql_error()); //write information to the database mysql_query("INSERT INTO `video`(video) VALUES('$video')"); //write file to server if(move_uploaded_file($_FILES["video"]["tmp_name"], $path)) { // execute if all is ok echo "the file " . basename( $_FILES['video']['name']). "has been uploaded and your information has been added to the server"; } else { //GIVES AND ERROR IF ITS NOT OK echo "Sorry,there was a problem in uploading."; } }//if (isset($_FILES['video'])){ ?> i tried isset function before but this time itsnot showing any error but its return a blank page without uploading anyway thanks for ur effort Quote Link to comment Share on other sites More sharing options...
Drummin Posted February 19, 2012 Share Posted February 19, 2012 Does print_r($_FILES); show you anything? Are you getting [error] => 0 ? if (isset($_FILES['video'])){ print_r($_FILES); //etc... Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 19, 2012 Author Share Posted February 19, 2012 no its not shwng nethng at all Quote Link to comment Share on other sites More sharing options...
Drummin Posted February 19, 2012 Share Posted February 19, 2012 How about if you surround print_r($_FILES); with <pre></pre> tags? The fact that you are not seeing $_FILES AT ALL is strange. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2012 Share Posted February 19, 2012 Add this to your script, immediately after the opening <?php tag so you can see what the form is actually sending. echo '-----POST-----<br><pre>'; print_r($_POST); echo '</pre>-----FILES-----<br><pre>'; print_r($_FILES); echo </pre>'; Where did you put this code? Post the file you edited, with this code added to it. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 19, 2012 Share Posted February 19, 2012 A) What size file are you uploading? B) What does a phpinfo statement show for the post_max_size setting? C) What does a phpinfo statement show for the file_uploads setting? Quote Link to comment Share on other sites More sharing options...
varun7952 Posted February 19, 2012 Author Share Posted February 19, 2012 thx alot to Drummin for helping me and PFMaBiSmAd for reminding me abt phpinfo now its wrking thyx alot guys 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.