Page 1 of 1

how do I get this form to modify my images and data?

Posted: Thu Aug 30, 2007 5:11 pm
by cybergirl
Here's the page, and this is the problem. It doens't modify anything, moreoever I'm looking to have more images and data in this form to modify. please help!

I want to put more stuff into it too such as:

data:
tourid, company, feature_num, category, description,
images:
tourimage01, tourimage02, tourimage03, tourimage04, tourimage05, tourimage01thumb, tourimage02thumb, tourimage03thumb, tourimage04thumb, tourimage05thumb, logo

everything you see above except tourid, is a field in the form. That's what I want.


Code: Select all

<?php
include 'config.php';
include 'opendb.php';
?>

<?php

// make sure the image id is present
if (!isset($_GET['tourid'])) {
      echo "Tour id is not defined";
} else {
      
      // get the image id
      $tourid = $_GET['tourid'];

      if (isset($_POST[''])) {
            $company  = $_POST[''];
            $description   = $_POST['description'];
            
            if ($_FILES['images']['tmp_name'] != '') {
                  $images = uploadImage('image', TOUR_IMG_DIR);
            
                  if ($images['image'] == '' && $images['tourimage01thumb'] == '') {
                        echo "Error uploading file";
                        exit;
                  }

                  $image     = "'" . $images['tourimage01'] . "'";
                  $thumbnail = "'" . $images['tourimage01thumb'] . "'";

                  $sql  = "SELECT *
                               FROM tours
                               WHERE tourid = $tourid";
                  
                  $result = mysql_query($sql) or die('Error, get image info failed. ' . mysql_error());
                  $row = mysql_fetch_assoc($result);
                  unlink(TOUR_IMG_DIR . $row['tourimage01']);
                  unlink(TOUR_IMG_DIR . $row['tourimage01thumb']);
            } else {
                  // the old image is not replaced
                  $image     = "tourimage01";
                  $thumbnail = "tourimage01thumb";
            }

                  
            $sql = "UPDATE tours
                        SET tourid = $tourid,
                              company = '$company',
                              description = '$description',
                              tourimage01 = $image,
                              tourimage01thumb = $thumbnail,
                            WHERE tourid = $tourid";
                              
      mysql_query($sql) or die('Error, update image failed : ' . mysql_error());                    
            
            echo "<script>window.location.href='tours.php?page=image-detail&tourid=$tourid';</script>";
      } else {

            
            $sql  = "SELECT tourid, company, description, tourimage01, tourimage01thumb
                         FROM tours
                         WHERE tourid = $tourid";
            
            $result = mysql_query($sql) or die('Error, get image info failed. ' . mysql_error());
            
            if (mysql_num_rows($result) == 0) {
                  // can't find an image with that id
            ?>
<link href="touradmin.css" rel="stylesheet" type="text/css" />

<p align="center">Image not found. Click <a href="tours.php?page=list-image">here</a>
    to go to the image list</p>
<?php      
            } else {      
                  $image = mysql_fetch_assoc($result);      
      
            
?>
<form action="" method="post" enctype="multipart/form-data" name="frmAlbum" id="frmAlbum">
    <table width="100%" border="0" cellpadding="2" cellspacing="1" class="table_grey">
       
        <tr>
            <th width="150">Image Title</th>
            <td width="80"> <input name="company" type="text" id="company" value="<?php echo $image['company']; ?>" size="40" maxlength="64"></td>
        </tr>
        <tr>
            <th width="150">Description</th>
            <td> <textarea name="mtxDesc" cols="50" rows="10" id="mtxDesc"><?php echo htmlspecialchars($image['description']); ?></textarea>            </td>
        </tr>
        <tr>
            <th width="150">Image</th>
            <td><?php if ($image['tourimage01thumb'] != '') { ; ?>
              <a href="javascript:viewLargeImage('<?php echo $image['tourimage01']; ?>')"><img src="view-image.php?type=thumbnail&name=<?php echo $image['tourimage01thumb']; ?>" border="0" /></a><br />
                    
                  
                  
              <?php } ?>
          <input name="image" type="file" class="box" id="images2"></td>
        </tr>
        <tr>
            <td width="150">&nbsp;</td>
            <td> <input name="btnModify" type="submit" class="box" id="btnModify" value="Modify Image">
                <input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();">            </td>
        </tr>
    </table>
</form>
<?php
            }
      }
}

?>

Posted: Thu Aug 30, 2007 7:59 pm
by califdon

Code: Select all

$sql = "UPDATE tours
                        SET tourid = $tourid,
                              company = '$company',
                              description = '$description',
                              tourimage01 = $image,
                              tourimage01thumb = $thumbnail,
                            WHERE tourid = $tourid";
You're asking it to find a record where the tourid column is equal to your variable $tourid, then update it, setting the tourid to the same value?? That's pretty bizarre.

What are you trying to do, update an existing record or insert a new record?

I take it you are not seeing an error, in which case the SQL is not generating an error, so it's probably simply not finding an existing record with that value in tourid.

Posted: Thu Aug 30, 2007 9:22 pm
by cybergirl
OK SO WHAT'S THE CORRECT WAY? I can't sort out all of this, it's just way too much stuff to understand. I understand coldfusion, I understand SQL and I know XHTML and css, but php, for some reason it's like it never sinks in no matter how many books I read. But trying to make me think, I have no idea. Really I just don't know this language no matter how hard I try. All I know is I got this stupid deadline, tommorrow, and I wa forced into using php, and I'm fumbling around like a blind person. I have no idea. So what am I supposed to write them to make it modify that particular tourid?

Posted: Thu Aug 30, 2007 9:22 pm
by cybergirl
I'm trying to update and existing record.

Posted: Thu Aug 30, 2007 9:36 pm
by CoderGoblin
OK it late here but ... try changing $_POST[''] to $_POST['company'].

Also there is nothing wrong when you have problems like this to enter debug line(s). Example: After all sql variable lines simple echo the $sql. Just remember to remove them when you have things working. Then you can check if you are getting what you think you are getting. If you don't seem to be getting the correct $_POST values traying printing using var_dump($_POST) or print_r($_POST).

Posted: Fri Aug 31, 2007 9:58 am
by cybergirl
Hi I tried that change but it isn't working. I think there is something missing in this script, such as a file that has a javascript that deletes or modifies it or else a php script, because when I looked at the other pages, the action= goes no where on those as well, and the demo they had on the site didn't modify or delete anything either. I tried writing to that person who posted it, but I really don't have time. How can I make a script that deletes of modifies it?

I'll correct whatever errors are left after but as long as it deletes on the listing page, and on the tour-modify it actually updates it, I'm fine. What I mean is, once it works, I will then post it for people to fuss over the parts that aren't perfected and take in all their advice, but for now I relaly just want it to delete and modify. I didn't post the tour-listings yet and I will, after I get this one right, because it's more critical.

I have to get all this done, in a couple of hours. And that's the deadline. After that, I don't know what I'll say except, I told you I didn't program in php! And then I might not get any more jobs. The fact is, I'm good at all the things I SAID I offer, and the client just ignored me when I said that. So, really don't look at me like I would normally do this.

I think I WILL take a course, because reading all these books I even have OLD php books I've read and I just don't get how to apply it. It just looks like tons of functions, and little blurbs on what each does, and then maybe one example (that I'll never use) and then no where does it show you how to do what I wanted!

however, when I learned Coldfusion, I actually cam up with ideas myself, and I know I was amongst one of the first people to do it that way. I did a who DJ site with links tha actually all went to either REal media or winamp, I created my own server, I had it showing the songs as they played live on the webpage, I had CD's I could sell and payment proceses, and all of this working and all I read was one book, the one by Ben forta! I did that a long time ago too, before there were any dj site, like DI.FM my friend is a lead programmer at. And he knows php really well but has NO time to answer my questions.

So I figured out a LOT, but for php, it's like I'm a total dum dum, it just DOESN'T sink in.

Treat me like I'm stupid because I really am stupid with php. Thanks. I don't get it, I need each and every tidbit explained I don't get half of it, I have to re-ask over again until it's clear. I really am stupid with php, and I need to figure this out.

Thanks for hearing me out, and my total desperation here.