Jump to content

Recommended Posts

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";
?>

Link to comment
https://forums.phpfreaks.com/topic/127751-solved-make-my-codes-cleaner/
Share on other sites

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

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 :/

 

 

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']

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";
?>

 

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

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 :P  :) 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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.