Jump to content

Error when editing rows @ database


miligraf

Recommended Posts

When i want to edit some rows from a PHP file named [b]edit.php[/b] i get this message:

[b]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 ''http://www.mydomain.com/images/50x50.gif', 'En este tutorial..[/b]

Those fields are the Image (varchar(255), not null) and Description (text, not null) at the table.
Link to comment
https://forums.phpfreaks.com/topic/8778-error-when-editing-rows-database/
Share on other sites

heres the php:

[code]<link rel="stylesheet" type="text/css" href="../../css.css" />
<?php
include ("../conbd.php");

if (!isset($_POST['submit']))
{
    if ((!isset($_GET['id']) || trim($_GET['id']) == ''))
    {
    die ('Missing record ID!');
    }
    
    $id = $_GET['id'];
    
    $query = "SELECT * FROM tutoriales WHERE id = '$id' ";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
    if (mysql_num_rows($result) > 0)
    {
    $row = mysql_fetch_row($result);
        $id = $row[0];
        $titulo = $row[1];
        $imagen = $row[2];
        $descripcion = $row[4];
        $enlace = $row[5];
        $autor = $row[6];
    ?>
    <span class='style20 Estilo3'>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <h2>Editar Tutorial #<?php echo $id; ?></h2>
    <table width="75%"  border="0">
      <tr class="Estilo3">
        <th scope="col"><div align="left"><strong>
          <input type="hidden" name="id" value="<?php echo $id; ?>">
  Titulo</strong></div></th>
        <th scope="col"><div align="right">
          <input value="<?php echo stripslashes($titulo); ?>" name="titulo" type="text" size="100">
        </div></th>
      </tr>
      <tr class="Estilo3">
        <td><div align="left"><strong>Imagen</strong></div></td>
        <td><div align="right">
          <input value="<?php echo stripslashes($imagen); ?>" name="imagen" type="text" size="100">
        </div></td>
      </tr>
      <tr class="Estilo3">
        <td><div align="left"><strong>Descripcion</strong></div></td>
        <td><div align="right">
          <textarea name="descripcion" cols="75" rows="5"><?php echo stripslashes($descripcion); ?></textarea>
        </div></td>
      </tr>
      <tr class="Estilo3">
        <td><div align="left"><strong>Enlace</strong></div></td>
        <td><div align="right">
          <input name="enlace" type="text" value="<?php echo stripslashes($enlace); ?>" size="100">
        </div></td>
      </tr>
      <tr class="Estilo3">
        <td><div align="left"><strong>Autor</strong></div></td>
        <td><div align="right">
          <input value="<?php echo stripslashes($autor); ?>" name="autor" type="text" size="100">
        </div></td>
      </tr>
    </table>
    <h2>    
    <input name="submit" type="Submit" value="Cambiar">
    <input type="reset" value="Cancelar">
    </h2>
    </form>
    </span>
    <?php
    }
    else
    {
    echo 'Tutorial no encontrado!';
    }
}
else
{
$query = "UPDATE tutoriales SET name = '".mysql_real_escape_string($titulo)."', '".mysql_real_escape_string($imagen)."', '".mysql_real_escape_string($descripcion)."', '".mysql_real_escape_string($enlace)."', '".mysql_real_escape_string($autor)."', WHERE id = '$id' ";
$result = mysql_query($query)or die(mysql_error());
echo 'Tutorial editado exitosamente, <a href="index.php">regresar</a>.';
}
mysql_close($connection);
?>[/code]
You're not telling it what to set. You only did with "name".

[code]$query = "UPDATE tutoriales SET name = '".mysql_real_escape_string($titulo)."', something1 = '".mysql_real_escape_string($imagen)."', something2 = '".mysql_real_escape_string($descripcion)."', something3 = '".mysql_real_escape_string($enlace)."', something4 = '".mysql_real_escape_string($autor)."', WHERE id = '$id' ";[/code]
Right now i changed it to this:

[code]$query = "UPDATE tutoriales SET name =  titulo = '".mysql_real_escape_string($titulo)."', imagen = '".mysql_real_escape_string($imagen)."', descripcion = '".mysql_real_escape_string($descripcion)."', enlace = '".mysql_real_escape_string($enlace)."', autor = '".mysql_real_escape_string($autor)."' WHERE id = '$id' ";[/code]

But i get this: [b]Unknown column 'name' in 'field list'[/b]

Archived

This topic is now archived and is closed to further replies.

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