SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is the problem????

    Hello again

    I have the following code

    PHP Code:
    if(isset($_GET['id']))
    {
        $query = "SELECT id, nombre_of, contenido ".
                 "FROM oficinas ".
                 "WHERE id = '{$_GET['id']}'";
        $result = mysql_query($query) or die('Error : ' . mysql_error());
        list($id, $nombre_of, $contenido) = mysql_fetch_array($result, MYSQL_NUM);
        
        $contenido = htmlspecialchars($contenido);

    else if(isset($_POST['nombre_of']))
    {
        $id      = $_POST['id'];
        $nombre_of   = $_POST['nombre_of'];
        $contenido = $_POST['contenido'];
        
        if(!get_magic_quotes_gpc())
        {
            $nombre_of   = addslashes($nombre_of);
            $contenido = addslashes($contenido);
        }
        
        // update the article in the database
        $query = "UPDATE oficinas ".
                 "SET nombre_of = '$nombre_of', contenido = '$contenido' ".
                 "WHERE id = '$id'";
        mysql_query($query) or die('Error : ' . mysql_error());

        // then remove the cached file
        $cacheDir  = dirname(__FILE__) . '/cache/';
        $cacheFile = $cacheDir . '_' . $_GET['id'] . '.html';
        
        @unlink($cacheFile);
        
        // and remove the index.html too because the file list
        // is changed
        @unlink($cacheDir . 'index.html');
            
        echo "<p align='center'>Article updated</p>";
        
        // now we will display $nombre_of & $contenido
        // so strip out any slashes
        $nombre_of   = stripslashes($nombre_of);
        $contenido = stripslashes($contenido);
    }

    include 'library/closedb.php';
    ?>
    <form method="post" action="edit.php">
    <input type="hidden" name="id" value="<?=$id;?>">
      <table width="700" border="0" cellpadding="2" cellspacing="1" class="box" align="center">
        <tr> 
          <td width="100">Nombre Oficina</td>
          <td><input name="nombre_of" type="text" class="box" id="nombre_of" value="<?=$nombre_of;?>"></td>
        </tr>
        <tr> 
          <td width="100">Contenido</td>
          <td><textarea name="contenido" cols="50" rows="10" class="box" id="contenido"><?=$contenido;?></textarea></td>
        </tr>
        <tr> 
          <td width="100">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="2" align="center"><input name="update" type="submit" class="box" id="update" value="Update Article"></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    The problem is that the article comes out updated

    PHP Code:
    echo "<p align='center'>Article updated</p>"
    but, is not updated

    Help me please

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,192
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    if

    That echo is inside the
    PHP Code:
    else if(isset($_POST['nombre_of']))

    so it will show if that condition is met.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but is not updated
    If I check the contents, continue all =

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,192
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    query

    Try
    PHP Code:
        // update the article in the database
        
    $query "UPDATE oficinas ".
                 
    "SET nombre_of = '$nombre_of', contenido = '$contenido' ".
                 
    "WHERE id = '$id'";
    echo 
    $query;
        
    mysql_query($query) or die('Error : ' mysql_error()); 
    To see if the query is what you think it should be.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, I will try

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2007
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is the updating going threw a form?>


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
  •