Darkwoods Posted October 9, 2008 Share Posted October 9, 2008 im trying to make an edit page for my uploaded files the problem is i cant make it to work on uploading the file if anyone of you who can just have look on my codes and see where the problem is it would be great <?php include "inc/header.php"; $id = $_GET['id']; if(isset($_POST['submit'])) { //global variables $name = $_POST['name']; $pic = $_POST['photo']; $result = mysql_query("UPDATE changeimage SET name='$name', photo='$pic' WHERE id='$id' ",$connect); echo "<b>Your post have been added successfully"; //This is the directory where images will be saved $target = "uploads/"; $target = $target . basename( $_FILES['photo']['name']); //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } } elseif($id) { $result = mysql_query("SELECT * FROM changeimage WHERE id='$id' ",$connect); while($row = mysql_fetch_assoc($result)) { $name = $row["name"]; $pic = $row["photo"]; ?> <br> <h3>::Edit News</h3> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="id" value="<?php echo $row['id']?>"> <table border="0" cellspacing="4" cellpadding="4"> <tr> <td>Select Category:</td> </tr> <tr> <td>Title:</td> <td><input name="name" size="40" maxlength="255" value="<?php echo $name; ?>"></td> </tr> <tr> <td>Content:</td> <td>Photo: <input type="file" name="photo"><br> </td> </tr> <tr> <td colspan="3" class="submit"><input type="submit" name="submit" value="Submit"></td> </tr> </table> <?php } //end of while loop }//end else include "inc/footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/ Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Are there errors? If you don't have them turned on put: ini_set ("display_errors", "1"); error_reporting(E_ALL); At the top. What's the output? Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661134 Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 no error... the upload is just not working the codes are probably wrong!! Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661146 Share on other sites More sharing options...
Maq Posted October 9, 2008 Share Posted October 9, 2008 Check this tutorial out: Tizag Upload Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661151 Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 Check this tutorial out: Tizag Upload not really what i want as i already have done this... im trying to make an edit page for the uploaded file i have done a database with id, name, filename, but the thing is i cant get it to upload on the edit page... but on the adding page it is working just fine it is sendig data to the database and uploading as it should Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661175 Share on other sites More sharing options...
DeanWhitehouse Posted October 9, 2008 Share Posted October 9, 2008 Where is your attempt at error checking? Echo the vars, check if they are correct, add error_reporting(E_ALL); to the top of the page Please even try and fix it your self Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661186 Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 Where is your attempt at error checking? Echo the vars, check if they are correct, add error_reporting(E_ALL); to the top of the page Please even try and fix it your self i got this wierd error when i added your code Not Found The requested URL /admin/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>/home/464ghf/public_html/admin/image-edit.php</b> on line <b>42</b><br /> was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. and trust me i have been trying to fix it for 2 days now :/ Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661207 Share on other sites More sharing options...
BillyBoB Posted October 9, 2008 Share Posted October 9, 2008 The requested URL /admin/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>/home/464ghf/public_html/admin/image-edit.php</b> on line <b>42</b><br /> was not found on this server. PHP_SELF isn't a variable built in php.... You mean $_SERVER['PHP_SELF'] Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661218 Share on other sites More sharing options...
DeanWhitehouse Posted October 9, 2008 Share Posted October 9, 2008 Try removing that elseif statement. Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661227 Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 ok i fixed the $_SERVER['PHP_SELF'] code :-X and removed elseif (id i got this error when uploading.. Notice: Undefined index: id in /home/kufasoft/public_html/admin/image-edit.php on line 6 Notice: Undefined index: photo in /home/kufasoft/public_html/admin/image-edit.php on line 13 Notice: Undefined index: photo in /home/kufasoft/public_html/admin/image-edit.php on line 20 Notice: Undefined index: photo in /home/kufasoft/public_html/admin/image-edit.php on line 23 edit-image.php <?php include "inc/header.php"; error_reporting(E_ALL); $id = $_GET['id']; if(isset($_POST['submit'])) { //global variables $name = $_POST['name']; $pic=($_FILES['photo']['name']); $result = mysql_query("UPDATE changeimage SET name='$name', photo='$pic' WHERE id='$id' ",$connect); //This is the directory where images will be saved $target = "uploads/"; $target = $target . basename( $_FILES['photo']['name']); //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } } $result = mysql_query("SELECT * FROM changeimage WHERE id='$id' ",$connect); while($row = mysql_fetch_assoc($result)) { $name = $row["name"]; $pic = $row["photo"]; ?> <br> <h3>::Edit News</h3> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <input type="hidden" name="id" value="<?php echo $row['id']?>"> <table border="0" cellspacing="4" cellpadding="4"> <tr> <td>Select Category:</td> </tr> <tr> <td>Title:</td> <td><input name="name" size="40" maxlength="255" value="<?php echo $name; ?>"></td> </tr> <tr> <td>Content:</td> <td>Photo: <input type="file" name="photo"><br> </td> </tr> <tr> <td colspan="3" class="submit"><input type="submit" name="submit" value="Submit"></td> </tr> </table> <?php } //end of while loop include "inc/footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661238 Share on other sites More sharing options...
DeanWhitehouse Posted October 9, 2008 Share Posted October 9, 2008 They mean that the variable or whatever is undefiened, e.g. $var = ''; echo $va;//is undefined Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661244 Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 They mean that the variable or whatever is undefiened, e.g. $var = ''; echo $va;//is undefined i just noticed that this was missing from the form enctype="multipart/form-data" now the problem is on 6 and on 27 the file is uploading to the dir now but the database is not getting the filename! any idea? Notice: Undefined index: id in /home/kufasoft/public_html/admin/image-edit.php on line 6 Notice: Undefined index: uploadedfile in /home/kufasoft/public_html/admin/image-edit.php on line 27 The file has been uploaded, and your information has been added to the directory Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661262 Share on other sites More sharing options...
DeanWhitehouse Posted October 9, 2008 Share Posted October 9, 2008 $id isnt defined, make sure it is. Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661270 Share on other sites More sharing options...
BillyBoB Posted October 9, 2008 Share Posted October 9, 2008 Blade its not $id that isn't defined its $_GET['id']. In your form is it something like: <form method="POST" action="page.php?id=#"></form> Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661279 Share on other sites More sharing options...
DeanWhitehouse Posted October 9, 2008 Share Posted October 9, 2008 yes, and if you read it $id = $_GET['id']; There fore it would be $id = ; And it would in result be undefined. But when i wrote it, i thought he should of realised what i meant. Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661280 Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 Blade its not $id that isn't defined its $_GET['id']. In your form is it something like: <form method="POST" action="page.php?id=#"></form> yeah i did realize it when u told me action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $row['id']?> but still got one error Notice: Undefined index: uploadedfile in /home/myuser/public_html/admin/image-edit.php on line 27 The file has been uploaded, and your information has been added to the directory Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661285 Share on other sites More sharing options...
DeanWhitehouse Posted October 9, 2008 Share Posted October 9, 2008 I have explained what the error means. Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661294 Share on other sites More sharing options...
BillyBoB Posted October 9, 2008 Share Posted October 9, 2008 Why does your variable in the Files change from photo to uploadedfile??? $_FILES['uploadedfile']['name'] is on line 27. Probably should be $_FILES['photo']['name'] Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661296 Share on other sites More sharing options...
Darkwoods Posted October 9, 2008 Author Share Posted October 9, 2008 THANK YOU maybe i should buy PHP book and start learning thanks all again TC Quote Link to comment https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/#findComment-661304 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.