Foro de elhacker.net

Programación => Bases de Datos => Mensaje iniciado por: Master_77777 en 8 Diciembre 2013, 22:07 pm



Título: El codigo no me agarra el if(mysql_query($insert_query))
Publicado por: Master_77777 en 8 Diciembre 2013, 22:07 pm
No se exacxtamente que pasa pero el codigo me deberia mandar el echo de 'succesfully Message' cuando guardo los datos. y no lo hace asi como tampoco me lo guarda en la base de datos y ya nno se que hacer. REvise el nombre de las filas en la base de datos y todo que podra ser? ahi les envio el codigo.


<!DOCTYPE html>
     <head>
        <meta charset="utf-8">

        <title>insert new posts</title>


     </head>

     <body>

        <form method="post" action="insert_post.php" enctype="multipart/form-data">
             <table width="600" align="center" border="10">

                <tr>
                   <td align="center" colspan="6" bgcolor="yellow"><h1>Insert new Post here</h1> </td>


                </tr>

                <tr>
                   <td>Post Title:</td>
                   <td><input type="text" name="title" size="30"></td>

                </tr>

                   <tr>
                   <td align="right">Post Author:</td>
                   <td><input type="text" name="author" size="30"></td>

                </tr>
                <tr>
                   <td align="right"> Post Keywords:</td>
                   <td><input type="text" name="keyword" size="30"></td>

                 </tr>
                 <tr>
                   <td align="right">Post Image:</td>
                   <td><input type="file" name="image"></td>

                 </tr>
                 <tr>
                   <td align="right">Post Content:</td>
                   <td><textarea name="content" cols="30" rows="15"> </textarea></td>

                 </tr>
                
                 <tr>
                   
                   <td align="center" colspan="6"><input type="submit" value="Publish Now" name="submit"></td>

                 </tr>

            </table>

         </form>
    </body>
    </html>


<?php

include("includes/conect.php");

if(isset($_POST['submit'])) {

    $post_title=$_POST['title'];
    $post_date=date('d-m-y');
    $post_author=$_POST['author'];
    $post_keywords=$_POST['keyword'];
    $post_content=$_POST['content'];
    $post_image=$_FILES['image'] ['name'];
     $image_tmp=$_FILES['image'] ['tmp_name'];


   if($post_title==''or $post_keywords==''or $post_content=='' or $post_author=='') {
 
    echo "<script>alert('any of the fields is empty')</script>";

     exit(); }
}else {

        move_uploaded_file($image_tmp,"../images/$post_image");

        $insert_query= "INSERT INTO posts (post_title,post_date,post_author,post_image,post_keywords,post_content)
         SVALUES ('$post_title',$post_date,'$post_author',$post_image, '$post_keywords', '$post_content)";
     
        if(mysql_query($insert_query))

           echo "<center><h1>Post Published Succcesfully!</h1></center>";
       
     }
?>

si hay  algun problema con el codigo hagammelo saber por favor



Título: Re: El codigo no me agarra el if(mysql_query($insert_query))
Publicado por: Shell Root en 9 Diciembre 2013, 06:02 am
Mira la query como está!
Código
  1. INSERT INTO posts (post_title, post_date, post_author, post_image, post_keywords, post_content) VALUES ('$post_title', $post_date, '$post_author', $post_image, '$post_keywords', '$post_content)
Falta una comilla simple al final de la variable $post_content, es decir,
Código
  1. INSERT INTO posts (post_title, post_date, post_author, post_image, post_keywords, post_content) VALUES ('$post_title', $post_date, '$post_author', $post_image, '$post_keywords', '$post_content');

Por otro lado, es VALUES, NO SVALUES.