Jump to content


Photo

Error when editing rows @ database


  • Please log in to reply
7 replies to this topic

#1 miligraf

miligraf
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 30 April 2006 - 09:34 PM

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

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....mages/50x50.gif' 'En este tutorial..

Those fields are the Image (varchar(255), not null) and Description (text, not null) at the table.

#2 freshrod

freshrod
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 01 May 2006 - 12:12 AM

If you could post exactly what those lines in the MySQL table say, or the PHP code where the query is, I might be able to help you better.
Nothing is foolproof to a talented fool.

#3 miligraf

miligraf
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 01 May 2006 - 06:12 AM

heres the php:

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


#4 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 01 May 2006 - 06:41 AM

You're not telling it what to set. You only did with "name".

$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' ";

PHP is my friend (=

#5 miligraf

miligraf
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 01 May 2006 - 06:58 PM

Thx! but now i get this message:

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 = '17'' at line 1

:S

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 01 May 2006 - 07:20 PM

Remove the comma before the "WHERE"

Ken

#7 miligraf

miligraf
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 01 May 2006 - 07:34 PM

Right now i changed it to this:

$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' ";

But i get this: Unknown column 'name' in 'field list'

#8 miligraf

miligraf
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 02 May 2006 - 08:12 PM

*bump*




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users