SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27

Thread: Edit Error

  1. #1
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Edit Error

    I have a page called editrides.php which edits rows in a database. I can click the edit link next to the name of the item on a page called rides.php and this shows the editrides.php page with a form and all values filled in so that they can be changed. I change them to what i need them to be and click submit and i get this error:

    Notice: Undefined index: id in c:\Sites\Single19\rctneil\webroot\future\editride.php on line 48

    Here is the code for editrides.php:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>ATM Ride CMS: Edit Ride</title>
    <meta http-equiv="content-type"
        content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <?php

    // connect to mysql 
    $dbcnx mysql_connect("-----""-----""-----"
           or die(
    mysql_error()); 

    // select db 
    $db mysql_select_db("rctneil"
          or die(
    mysql_error()); 

    if (isset(
    $_POST['name'])):
      
    // The ride's details have been updated.

      
    $ridename $_POST['ridename'];
      
    $titleimage $_POST['titleimage'];
      
    $pagesound $_POST['pagesound'];
      
    $ridereview $_POST['ridereview'];
      
    $id $_POST['id'];
      
    $sql "UPDATE atm_rides SET
          ridename='
    $ridename',
          titleimage='
    $titleimage',
          pagesound='
    $pagesound',
          ridereview='
    $ridereview'
              WHERE id='
    $id'";
      if (@
    mysql_query($sql)) {
        echo 
    '<p>Ride details updated.</p>';
      } else {
        echo 
    '<p>Error updating ride details: ' .
            
    mysql_error() . '</p>';
      }

    ?>

    <p><a href="rides.php">Return to rides list</a></p>

    <?php
    else: // Allow the user to edit the ride

      
    $id $_GET['id'];
      
    $ride = @mysql_query(
          
    "SELECT ridename, titleimage, pagesound, ridereview FROM atm_rides WHERE id='$id'");
      if (!
    $ride) {
        exit(
    '<p>Error fetching ride details: ' .
            
    mysql_error() . '</p>');
      }

      
    $ride mysql_fetch_array($ride);

      
    $ridename $ride['ridename'];
      
    $titleimage $ride['titleimage'];
      
    $pagesound $ride['pagesound'];
      
    $ridereview $ride['ridereview'];

      
    // Convert special characters for safe use
      // as HTML attributes.
      
    $ridename htmlspecialchars($ridename);
      
    $titleimage htmlspecialchars($titleimage);
      
    $pagesound htmlspecialchars($pagesound);
      
    $ridereview htmlspecialchars($ridereview);
      
      
    $ridename nl2br($ridename);
      
    $titleimage nl2br($titleimage);
      
    $pagesound nl2br($pagesound);
      
    $ridereview nl2br($ridereview);

    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <p>Edit the ride:</p>
      <label>Ride Name: 
      <input name="ridename" type="text" value="<?php echo $ridename?>" size="40" />
      </label><br />
      <label>Title Image Path: 
      <input name="titleimage" type="text" value="<?php echo $titleimage?>" size="40" />
      </label>
      <br />
      <label>Page Sound Path: 
      <input name="pagesound" type="text" value="<?php echo $pagesound?>" size="40" />
      </label>
      <br />
      <p> 
        <label>Ride Review: </label>
      </p>
      <p> 
        <label> 
        <textarea name="ridereview" cols="80" rows="20"><?php echo $ridereview?></textarea>
        </label>
      </p>
      <br />
    <input type="hidden" name="id" value="<?php echo $id?>" />
      <input type="submit" value="Submit Ride Changes" />
      </p>
    </form>

    <?php endif; ?>

    </body>
    </html>
    Thanks

    Neil

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can click the edit link next to the name of the item on a page called rides.php
    That link(s) doesn't look like it's passing id in, i.e the link(s) should look something like:

    editrides.php?id=7

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this variable does not exist

    $_GET['id'];


    make sure it is being passed via the query string. or if you want to receive it via method=post, then use the $_POST array

  4. #4
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The id is being passed from the rides.php page to editride.php as the data from the db table shows up in the text boxes ready to be edited. I can then edit the data and i recieve the error after i click the "Submit Rde Changes" button.

    Any idea?

    Thanks

    Neil

  5. #5
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please help

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Dump out the entire contents of the POST array to see if the variable is getting through
    PHP Code:
    if (isset($_POST['name'])): 
      
    // The ride's details have been updated.
     // dump it all....
    print_r($_POST);
    // etc ... 
    Also view the source of the page in your browser when you are editing the page tosee if the variable is there.

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just done all that and yes the variable is getting through. Any Ideas?

    Thanks

    Neil

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    add this bit....
    PHP Code:
    if(isset($_GET['id'])) :
      
    $id $_GET['id']; 
    and close the endif at the end
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like this?

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>ATM Ride CMS: Edit Ride</title>
    <meta http-equiv="content-type"
        content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <?php

    // connect to mysql 
    $dbcnx mysql_connect("-----""-----""-----"
           or die(
    mysql_error()); 

    // select db 
    $db mysql_select_db("rctneil"
          or die(
    mysql_error()); 

    if (isset(
    $_POST['name'])):
      
    // The ride's details have been updated.

      
    $ridename $_POST['ridename'];
      
    $titleimage $_POST['titleimage'];
      
    $pagesound $_POST['pagesound'];
      
    $ridereview $_POST['ridereview'];
      
    $gallerylink $_POST['gallerylink'];
      
    $catid $_POST['catid'];
      
    $area $_POST['area'];
      
    $duration $_POST['duration'];
      
    $slogan $_POST['slogan'];
      
    $manu $_POST['manu'];
      
      
    $id $_POST['id'];
      
    $sql "UPDATE atm_rides SET
          ridename='
    $ridename',
          titleimage='
    $titleimage',
          pagesound='
    $pagesound',
          ridereview='
    $ridereview',
          gallerylink='
    $gallerylink',
          catid='
    $catid',
          area='
    $area',
          duration='
    $duration',
          slogan='
    $slogan',
          manu='
    $manu',
          
              WHERE id='
    $id'";
      if (@
    mysql_query($sql)) {
        echo 
    '<p>Ride details updated.</p>';
      } else {
        echo 
    '<p>Error updating ride details: ' .
            
    mysql_error() . '</p>';
      }

    ?>

    <p><a href="rides.php">Return to rides list</a></p>

    <?php
    else: // Allow the user to edit the ride

    if(isset($_GET['id'])) : 
      
    $id $_GET['id']; 


      
    $ride = @mysql_query(
          
    "SELECT ridename, titleimage, pagesound, ridereview, gallerylink, catid, area, duration, slogan, manu FROM atm_rides WHERE id='$id'");
      if (!
    $ride) {
        exit(
    '<p>Error fetching ride details: ' .
            
    mysql_error() . '</p>');
      }

      
    $ride mysql_fetch_array($ride);

      
    $ridename $ride['ridename'];
      
    $titleimage $ride['titleimage'];
      
    $pagesound $ride['pagesound'];
      
    $ridereview $ride['ridereview'];
      
    $gallerylink $ride['gallerylink'];
      
    $catid $ride['catid'];
      
    $area $ride['area'];
      
    $duration $ride['duration'];
      
    $slogan $ride['slogan'];
      
    $manu $ride['manu'];

      
    // Convert special characters for safe use
      // as HTML attributes.
      
    $ridename htmlspecialchars($ridename);
      
    $titleimage htmlspecialchars($titleimage);
      
    $pagesound htmlspecialchars($pagesound);
      
    $ridereview htmlspecialchars($ridereview);
      
    $gallerylink htmlspecialchars($gallerylink);
      
    $catid htmlspecialchars($catid);
      
    $area htmlspecialchars($area);
      
    $duration htmlspecialchars($duration);
      
    $slogan htmlspecialchars($slogan);
      
    $manu htmlspecialchars($manu);
      
      
    $ridename nl2br($ridename);
      
    $titleimage nl2br($titleimage);
      
    $pagesound nl2br($pagesound);
      
    $ridereview nl2br($ridereview);
      
    $gallerylink nl2br($gallerylink);
      
    $catid nl2br($catid);
      
    $area nl2br($area);
      
    $duration nl2br($duration);
      
    $slogan nl2br($slogan);
      
    $manu nl2br($manu);

    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <p>Edit the ride:</p>
      <label>Ride Name: 
      <input name="ridename" type="text" value="<?php echo $ridename?>" size="40" />
      </label><br />
      <label>Title Image Path: 
      <input name="titleimage" type="text" value="<?php echo $titleimage?>" size="40" />
      </label>
      <br />
      <label>Page Sound Path: 
      <input name="pagesound" type="text" value="<?php echo $pagesound?>" size="40" />
      </label>
      <br />
      <p> 
        <label>Ride Review: </label>
      </p>
      <p> 
        <label> 
        <textarea name="ridereview" cols="80" rows="20"><?php echo $ridereview?></textarea>
        </label>
        <br />
        
        
        <label>Link to Photo Gallery: 
      <input name="gallerylink" type="text" value="<?php echo $gallerylink?>" size="40" />
      </label>
      <br />
      
          <label>Category Id: 
      <input name="catid" type="text" value="<?php echo $catid?>" size="40" />
      </label>
      <br />
      
      <label>Area in Park: 
      <input name="area" type="text" value="<?php echo $area?>" size="40" />
      </label>
      <br />
      
      <label>Ride Duration: 
      <input name="duration" type="text" value="<?php echo $duration?>" size="40" />
      </label>
      <br />
      
      <label>Ride Slogan: 
      <input name="slogan" type="text" value="<?php echo $slogan?>" size="40" />
      </label>
      <br />
      
      <label>Manufacturer: 
      <input name="manu" type="text" value="<?php echo $manu?>" size="40" />
      </label>
      <br />
        
      </p>
      <br />
    <input type="hidden" name="id" value="<?php echo $id?>" />
      <input type="submit" value="Submit Ride Changes" />
      </p>
    </form>

    <?php endif; ?>

    </body>
    </html>

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Yes, personally I have not used the else : syntax, I prefer the good old fashioned } else { braces!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It still does not work, has an error when clicking the edit link now!

    Parse error: parse error, unexpected $end in c:\Sites\Single19\rctneil\webroot\future\editride.php on line 175

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>ATM Ride CMS: Edit Ride</title> 
    <meta http-equiv="content-type" 
        content="text/html; charset=iso-8859-1" /> 
    </head> 
    <body> 
    <?php 

    // connect to mysql 
    $dbcnx mysql_connect("-----""-----""-----"
           or die(
    mysql_error()); 

    // select db 
    $db mysql_select_db("rctneil"
          or die(
    mysql_error()); 

    if (isset(
    $_POST['name'])) {
      
    // The ride's details have been updated. 

      
    $ridename $_POST['ridename']; 
      
    $titleimage $_POST['titleimage']; 
      
    $pagesound $_POST['pagesound']; 
      
    $ridereview $_POST['ridereview']; 
      
    $id $_POST['id']; 
      
    $sql "UPDATE atm_rides SET 
          ridename='
    $ridename', 
          titleimage='
    $titleimage', 
          pagesound='
    $pagesound', 
          ridereview='
    $ridereview
              WHERE id='
    $id'"
      if (@
    mysql_query($sql)) { 
        echo 
    '<p>Ride details updated.</p>'
      } else { 
        echo 
    '<p>Error updating ride details: ' 
            
    mysql_error() . '</p>'
      } 

    ?> 

    <p><a href="rides.php">Return to rides list</a></p> 

    <?php 
    } else{

    if(isset(
    $_GET['id'])) {
      
    $id $_GET['id']; 
      
    $ride = @mysql_query
          
    "SELECT ridename, titleimage, pagesound, ridereview FROM atm_rides WHERE id='$id'"); 
      if (!
    $ride) { 
        exit(
    '<p>Error fetching ride details: ' 
            
    mysql_error() . '</p>'); 
      } 

      
    $ride mysql_fetch_array($ride); 

      
    $ridename $ride['ridename']; 
      
    $titleimage $ride['titleimage']; 
      
    $pagesound $ride['pagesound']; 
      
    $ridereview $ride['ridereview']; 

      
    // Convert special characters for safe use 
      // as HTML attributes. 
      
    $ridename htmlspecialchars($ridename); 
      
    $titleimage htmlspecialchars($titleimage); 
      
    $pagesound htmlspecialchars($pagesound); 
      
    $ridereview htmlspecialchars($ridereview); 
       
      
    $ridename nl2br($ridename); 
      
    $titleimage nl2br($titleimage); 
      
    $pagesound nl2br($pagesound); 
      
    $ridereview nl2br($ridereview); 

    ?> 

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
      <p>Edit the ride:</p> 
      <label>Ride Name: 
      <input name="ridename" type="text" value="<?php echo $ridename?>" size="40" /> 
      </label><br /> 
      <label>Title Image Path: 
      <input name="titleimage" type="text" value="<?php echo $titleimage?>" size="40" /> 
      </label> 
      <br /> 
      <label>Page Sound Path: 
      <input name="pagesound" type="text" value="<?php echo $pagesound?>" size="40" /> 
      </label> 
      <br /> 
      <p> 
        <label>Ride Review: </label> 
      </p> 
      <p> 
        <label> 
        <textarea name="ridereview" cols="80" rows="20"><?php echo $ridereview?></textarea> 
        </label> 
      </p> 
      <br /> 
    <input type="hidden" name="id" value="<?php echo $id?>" /> 
      <input type="submit" value="Submit Ride Changes" /> 
      </p> 
    </form> 

    <?php # end if(isset))?> 
    <?php # end?> 

    </body> 
    </html>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the error i get now:

    Parse error: parse error, unexpected '}' in c:\Sites\Single19\rctneil\webroot\future\editride.php on line 171

    and can you check the updated code (hopefully it's right but i get the error above so somethings wrong):

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>ATM Ride CMS: Edit Ride</title>
    <meta http-equiv="content-type"
        content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <?php

    // connect to mysql 
    $dbcnx mysql_connect("-----""-----""-----"
           or die(
    mysql_error()); 

    // select db 
    $db mysql_select_db("rctneil"
          or die(
    mysql_error()); 

    if (isset(
    $_POST['name'])):
      
    // The ride's details have been updated.

      
    $ridename $_POST['ridename'];
      
    $titleimage $_POST['titleimage'];
      
    $pagesound $_POST['pagesound'];
      
    $ridereview $_POST['ridereview'];
      
    $gallerylink $_POST['gallerylink'];
      
    $catid $_POST['catid'];
      
    $area $_POST['area'];
      
    $duration $_POST['duration'];
      
    $slogan $_POST['slogan'];
      
    $manu $_POST['manu'];
      
      
    $id $_POST['id'];
      
    $sql "UPDATE atm_rides SET
          ridename='
    $ridename',
          titleimage='
    $titleimage',
          pagesound='
    $pagesound',
          ridereview='
    $ridereview',
          gallerylink='
    $gallerylink',
          catid='
    $catid',
          area='
    $area',
          duration='
    $duration',
          slogan='
    $slogan',
          manu='
    $manu',
          
              WHERE id='
    $id'";
      if (@
    mysql_query($sql)) {
        echo 
    '<p>Ride details updated.</p>';
      } else {
        echo 
    '<p>Error updating ride details: ' .
            
    mysql_error() . '</p>';
      }

    ?>

    <p><a href="rides.php">Return to rides list</a></p>

    <?php
    else: // Allow the user to edit the ride

    if(isset($_GET['id'])) : 
      
    $id $_GET['id']; 


      
    $ride = @mysql_query(
          
    "SELECT ridename, titleimage, pagesound, ridereview, gallerylink, catid, area, duration, slogan, manu FROM atm_rides WHERE id='$id'");
      if (!
    $ride) {
        exit(
    '<p>Error fetching ride details: ' .
            
    mysql_error() . '</p>');
      }

      
    $ride mysql_fetch_array($ride);

      
    $ridename $ride['ridename'];
      
    $titleimage $ride['titleimage'];
      
    $pagesound $ride['pagesound'];
      
    $ridereview $ride['ridereview'];
      
    $gallerylink $ride['gallerylink'];
      
    $catid $ride['catid'];
      
    $area $ride['area'];
      
    $duration $ride['duration'];
      
    $slogan $ride['slogan'];
      
    $manu $ride['manu'];

      
    // Convert special characters for safe use
      // as HTML attributes.
      
    $ridename htmlspecialchars($ridename);
      
    $titleimage htmlspecialchars($titleimage);
      
    $pagesound htmlspecialchars($pagesound);
      
    $ridereview htmlspecialchars($ridereview);
      
    $gallerylink htmlspecialchars($gallerylink);
      
    $catid htmlspecialchars($catid);
      
    $area htmlspecialchars($area);
      
    $duration htmlspecialchars($duration);
      
    $slogan htmlspecialchars($slogan);
      
    $manu htmlspecialchars($manu);
      
      
    $ridename nl2br($ridename);
      
    $titleimage nl2br($titleimage);
      
    $pagesound nl2br($pagesound);
      
    $ridereview nl2br($ridereview);
      
    $gallerylink nl2br($gallerylink);
      
    $catid nl2br($catid);
      
    $area nl2br($area);
      
    $duration nl2br($duration);
      
    $slogan nl2br($slogan);
      
    $manu nl2br($manu);

    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <p>Edit the ride:</p>
      <label>Ride Name: 
      <input name="ridename" type="text" value="<?php echo $ridename?>" size="40" />
      </label><br />
      <label>Title Image Path: 
      <input name="titleimage" type="text" value="<?php echo $titleimage?>" size="40" />
      </label>
      <br />
      <label>Page Sound Path: 
      <input name="pagesound" type="text" value="<?php echo $pagesound?>" size="40" />
      </label>
      <br />
      <p> 
        <label>Ride Review: </label>
      </p>
      <p> 
        <label> 
        <textarea name="ridereview" cols="80" rows="20"><?php echo $ridereview?></textarea>
        </label>
        <br />
        
        
        <label>Link to Photo Gallery: 
      <input name="gallerylink" type="text" value="<?php echo $gallerylink?>" size="40" />
      </label>
      <br />
      
          <label>Category Id: 
      <input name="catid" type="text" value="<?php echo $catid?>" size="40" />
      </label>
      <br />
      
      <label>Area in Park: 
      <input name="area" type="text" value="<?php echo $area?>" size="40" />
      </label>
      <br />
      
      <label>Ride Duration: 
      <input name="duration" type="text" value="<?php echo $duration?>" size="40" />
      </label>
      <br />
      
      <label>Ride Slogan: 
      <input name="slogan" type="text" value="<?php echo $slogan?>" size="40" />
      </label>
      <br />
      
      <label>Manufacturer: 
      <input name="manu" type="text" value="<?php echo $manu?>" size="40" />
      </label>
      <br />
        
      </p>
      <br />
    <input type="hidden" name="id" value="<?php echo $id?>" />
      <input type="submit" value="Submit Ride Changes" />
      </p>
    </form>
    <?php # end if(isset))?> 
    <?php # end?> 


    </body>
    </html>

  14. #14
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    ahh, that's because you took part of the code and not all of it!
    The final two closing braces will only work if you have the corresponding opening ones in the code.

    Take the whole code from post#12 and see if it runs
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #15
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have just done that and when i click the submit ride changes button after editing in the text boxes. I get a blank page with nothing on it and nothing has been changed?

    Thanks

    Neil

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    morning,
    try
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>ATM Ride CMS: Edit Ride</title> 
    <meta http-equiv="content-type" 
        content="text/html; charset=iso-8859-1" /> 
    </head> 
    <body> 
    <?php 

    // connect to mysql 
    $dbcnx mysql_connect("-----""-----""-----"
           or die(
    mysql_error()); 

    // select db 
    $db mysql_select_db("rctneil"
          or die(
    mysql_error()); 

    if (isset(
    $_POST['name'])){
      
    // The ride's details have been updated. 

      
    $ridename $_POST['ridename']; 
      
    $titleimage $_POST['titleimage']; 
      
    $pagesound $_POST['pagesound']; 
      
    $ridereview $_POST['ridereview']; 
      
    $gallerylink $_POST['gallerylink']; 
      
    $catid $_POST['catid']; 
      
    $area $_POST['area']; 
      
    $duration $_POST['duration']; 
      
    $slogan $_POST['slogan']; 
      
    $manu $_POST['manu']; 
       
      
    $id $_POST['id']; 
      
    $sql "UPDATE atm_rides SET 
          ridename='
    $ridename', 
          titleimage='
    $titleimage', 
          pagesound='
    $pagesound', 
          ridereview='
    $ridereview', 
          gallerylink='
    $gallerylink', 
          catid='
    $catid', 
          area='
    $area', 
          duration='
    $duration', 
          slogan='
    $slogan', 
          manu='
    $manu', 
           
              WHERE id='
    $id'"
      if (@
    mysql_query($sql)) { 
        echo 
    '<p>Ride details updated.</p>'
      } else { 
        echo 
    '<p>Error updating ride details: ' 
            
    mysql_error() . '</p>'
      } 
    ?> 

    <p><a href="rides.php">Return to rides list</a></p> 
    <?php // end if isset POST ?>

    <?php 
     
    // Allow the user to edit the ride 

    if(isset($_GET['id'])) {
      
    $id $_GET['id']; 


      
    $ride = @mysql_query
          
    "SELECT ridename, titleimage, pagesound, ridereview, gallerylink, catid, area, duration, slogan, manu FROM atm_rides WHERE id='$id'"); 
      if (!
    $ride) { 
        exit(
    '<p>Error fetching ride details: ' 
            
    mysql_error() . '</p>'); 
      } 

      
    $ride mysql_fetch_array($ride); 

      
    $ridename $ride['ridename']; 
      
    $titleimage $ride['titleimage']; 
      
    $pagesound $ride['pagesound']; 
      
    $ridereview $ride['ridereview']; 
      
    $gallerylink $ride['gallerylink']; 
      
    $catid $ride['catid']; 
      
    $area $ride['area']; 
      
    $duration $ride['duration']; 
      
    $slogan $ride['slogan']; 
      
    $manu $ride['manu']; 

      
    // Convert special characters for safe use 
      // as HTML attributes. 
      
    $ridename htmlspecialchars($ridename); 
      
    $titleimage htmlspecialchars($titleimage); 
      
    $pagesound htmlspecialchars($pagesound); 
      
    $ridereview htmlspecialchars($ridereview); 
      
    $gallerylink htmlspecialchars($gallerylink); 
      
    $catid htmlspecialchars($catid); 
      
    $area htmlspecialchars($area); 
      
    $duration htmlspecialchars($duration); 
      
    $slogan htmlspecialchars($slogan); 
      
    $manu htmlspecialchars($manu); 
       
      
    $ridename nl2br($ridename); 
      
    $titleimage nl2br($titleimage); 
      
    $pagesound nl2br($pagesound); 
      
    $ridereview nl2br($ridereview); 
      
    $gallerylink nl2br($gallerylink); 
      
    $catid nl2br($catid); 
      
    $area nl2br($area); 
      
    $duration nl2br($duration); 
      
    $slogan nl2br($slogan); 
      
    $manu nl2br($manu); 

    ?> 

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
      <p>Edit the ride:</p> 
      <label>Ride Name: 
      <input name="ridename" type="text" value="<?php echo $ridename?>" size="40" /> 
      </label><br /> 
      <label>Title Image Path: 
      <input name="titleimage" type="text" value="<?php echo $titleimage?>" size="40" /> 
      </label> 
      <br /> 
      <label>Page Sound Path: 
      <input name="pagesound" type="text" value="<?php echo $pagesound?>" size="40" /> 
      </label> 
      <br /> 
      <p> 
        <label>Ride Review: </label> 
      </p> 
      <p> 
        <label> 
        <textarea name="ridereview" cols="80" rows="20"><?php echo $ridereview?></textarea> 
        </label> 
        <br /> 
         
         
        <label>Link to Photo Gallery: 
      <input name="gallerylink" type="text" value="<?php echo $gallerylink?>" size="40" /> 
      </label> 
      <br /> 
       
          <label>Category Id: 
      <input name="catid" type="text" value="<?php echo $catid?>" size="40" /> 
      </label> 
      <br /> 
       
      <label>Area in Park: 
      <input name="area" type="text" value="<?php echo $area?>" size="40" /> 
      </label> 
      <br /> 
       
      <label>Ride Duration: 
      <input name="duration" type="text" value="<?php echo $duration?>" size="40" /> 
      </label> 
      <br /> 
       
      <label>Ride Slogan: 
      <input name="slogan" type="text" value="<?php echo $slogan?>" size="40" /> 
      </label> 
      <br /> 
       
      <label>Manufacturer: 
      <input name="manu" type="text" value="<?php echo $manu?>" size="40" /> 
      </label> 
      <br /> 
         
      </p> 
      <br /> 
    <input type="hidden" name="id" value="<?php echo $id?>" /> 
      <input type="submit" value="Submit Ride Changes" /> 
      </p> 
    </form> 

    <?php ?> 

    </body> 
    </html>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Morning!

    I tried that new code and still takes me to a blank page?

    Thanks

    Neil

  18. #18
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any Thoughts?

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    OK, you know when it's one of those blindingly obvious things....
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>ATM Ride CMS: Edit Ride</title> 
    <meta http-equiv="content-type" 
        content="text/html; charset=iso-8859-1" /> 
    </head> 
    <body> 
    <?php 

    // connect to mysql 
    $dbcnx mysql_connect("-----""-----""-----"
           or die(
    mysql_error()); 

    // select db 
    $db mysql_select_db("rctneil"
          or die(
    mysql_error()); 

    if (isset(
    $_POST['id'])){ 
      
    // The ride's details have been updated. 

      
    $ridename $_POST['ridename']; 
      
    $titleimage $_POST['titleimage']; 
      
    $pagesound $_POST['pagesound']; 
      
    $ridereview $_POST['ridereview']; 
      
    $gallerylink $_POST['gallerylink']; 
      
    $catid $_POST['catid']; 
      
    $area $_POST['area']; 
      
    $duration $_POST['duration']; 
      
    $slogan $_POST['slogan']; 
      
    $manu $_POST['manu']; 
        
      
    $id $_POST['id']; 
      
    $sql "UPDATE atm_rides SET 
          ridename='
    $ridename', 
          titleimage='
    $titleimage', 
          pagesound='
    $pagesound', 
          ridereview='
    $ridereview', 
          gallerylink='
    $gallerylink', 
          catid='
    $catid', 
          area='
    $area', 
          duration='
    $duration', 
          slogan='
    $slogan', 
          manu='
    $manu', 
            
              WHERE id='
    $id'"
      if (@
    mysql_query($sql)) { 
        echo 
    '<p>Ride details updated.</p>'
      } else { 
        echo 
    '<p>Error updating ride details: ' 
            
    mysql_error() . '</p>'
      } 
    ?> 

    <p><a href="rides.php">Return to rides list</a></p> 
    <?php // end if isset POST ?> 

    <?php 
    // Allow the user to edit the ride 

    if(isset($_GET['id'])) { 
      
    $id $_GET['id']; 


      
    $ride = @mysql_query
          
    "SELECT ridename, titleimage, pagesound, ridereview, gallerylink, catid, area, duration, slogan, manu FROM atm_rides WHERE id='$id'"); 
      if (!
    $ride) { 
        exit(
    '<p>Error fetching ride details: ' 
            
    mysql_error() . '</p>'); 
      } 

      
    $ride mysql_fetch_array($ride); 

      
    $ridename $ride['ridename']; 
      
    $titleimage $ride['titleimage']; 
      
    $pagesound $ride['pagesound']; 
      
    $ridereview $ride['ridereview']; 
      
    $gallerylink $ride['gallerylink']; 
      
    $catid $ride['catid']; 
      
    $area $ride['area']; 
      
    $duration $ride['duration']; 
      
    $slogan $ride['slogan']; 
      
    $manu $ride['manu']; 

      
    // Convert special characters for safe use 
      // as HTML attributes. 
      
    $ridename htmlspecialchars($ridename); 
      
    $titleimage htmlspecialchars($titleimage); 
      
    $pagesound htmlspecialchars($pagesound); 
      
    $ridereview htmlspecialchars($ridereview); 
      
    $gallerylink htmlspecialchars($gallerylink); 
      
    $catid htmlspecialchars($catid); 
      
    $area htmlspecialchars($area); 
      
    $duration htmlspecialchars($duration); 
      
    $slogan htmlspecialchars($slogan); 
      
    $manu htmlspecialchars($manu); 
        
      
    $ridename nl2br($ridename); 
      
    $titleimage nl2br($titleimage); 
      
    $pagesound nl2br($pagesound); 
      
    $ridereview nl2br($ridereview); 
      
    $gallerylink nl2br($gallerylink); 
      
    $catid nl2br($catid); 
      
    $area nl2br($area); 
      
    $duration nl2br($duration); 
      
    $slogan nl2br($slogan); 
      
    $manu nl2br($manu); 

    ?> 

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
      <p>Edit the ride:</p> 
      <label>Ride Name: 
      <input name="ridename" type="text" value="<?php echo $ridename?>" size="40" /> 
      </label><br /> 
      <label>Title Image Path: 
      <input name="titleimage" type="text" value="<?php echo $titleimage?>" size="40" /> 
      </label> 
      <br /> 
      <label>Page Sound Path: 
      <input name="pagesound" type="text" value="<?php echo $pagesound?>" size="40" /> 
      </label> 
      <br /> 
      <p> 
        <label>Ride Review: </label> 
      </p> 
      <p> 
        <label> 
        <textarea name="ridereview" cols="80" rows="20"><?php echo $ridereview?></textarea> 
        </label> 
        <br /> 
          
          
        <label>Link to Photo Gallery: 
      <input name="gallerylink" type="text" value="<?php echo $gallerylink?>" size="40" /> 
      </label> 
      <br /> 
        
          <label>Category Id: 
      <input name="catid" type="text" value="<?php echo $catid?>" size="40" /> 
      </label> 
      <br /> 
        
      <label>Area in Park: 
      <input name="area" type="text" value="<?php echo $area?>" size="40" /> 
      </label> 
      <br /> 
        
      <label>Ride Duration: 
      <input name="duration" type="text" value="<?php echo $duration?>" size="40" /> 
      </label> 
      <br /> 
        
      <label>Ride Slogan: 
      <input name="slogan" type="text" value="<?php echo $slogan?>" size="40" /> 
      </label> 
      <br /> 
        
      <label>Manufacturer: 
      <input name="manu" type="text" value="<?php echo $manu?>" size="40" /> 
      </label> 
      <br /> 
          
      </p> 
      <br /> 
    <input type="hidden" name="id" value="<?php echo $id?>" /> 
      <input type="submit" value="Submit Ride Changes" /> 
      </p> 
    </form> 

    <?php ?> 

    </body> 
    </html>
    If that works, I will tell you why!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  20. #20
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Getting this error now.

    Error updating ride details: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='7'' at line 13

  21. #21
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    OK, this believe it or not is a good sign!
    It means it has processed it but failed on the query
    PHP Code:
    manu='$manu'
             
              
    WHERE id='$id'"; 
    delete the , after manu='$manu'

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  22. #22
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    FANTASTIC - Thanks Spikez. Another quickie. How can i quickly and easily password protect files and folders in my webspace?

    Thanks

    Neil

  23. #23
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Glad that one is sorted!
    Just to let you know why for future reference....
    You had this line:
    PHP Code:
    if (isset($_POST['name'])){ 
    However, none of the form elements was called 'name' so therefore it was never set and so wasn't processing the form

    As for protecting things, for individual files you can use SESSIONS and for entire directories, use .htaccess.

    A quick search of this forum should yield more information than I can type here!

    Cheers

    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  24. #24
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Been having a mess with the editrides page and i have used the nl2br thing to make sure that when i type in a review of the ride in the box and press enter to get it into paragraphs, the page changes the new lines to be <br />'s. Now when i go back to the rides.php page and click the edit link, it adds another set of <br />'s and if i go back and click the edit link again it adds even more? Why?

  25. #25
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any idea on this? It's bugging me.

    Thanks

    Neil


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •