Error PHP MySQL

Discussion in 'Programming' started by altadosis, Jan 27, 2012.

  1. #1
    Hi, im new here, but this is the first time in this forum, i will appreciate all the help for all, so, this is my issue:


    Im a webmaster, but im not a programmer, so, a friend that he know all about mysql php and other stuff i ask for a help to my own website, so he did all i required, but he is now out the country and he never come back, i lost contact with him, so, now im need some explains and help with this:


    My website need a form, i already create a table with all the id's i need. But, when i opend the code, i no need anymore upload a file, to be more specific, my section in my site need a TITLE, DESCRIPTION and LINK, all tree are text field.


    But, i have problems with this code because have some requires, that i dont know how to remove them cuz when i try, the form doesn't work.


    So this is what i need:


    1.- Remove Required Strings
    2.- File Upload


    And thats it: So, This is the code:


    -------------------------------------------------------------


    <?php
    include('connect.php');


    if(isset($_GET['id_not']) && $_GET['id_not'] != "")
    {
    $del = mysql_query("SELECT * FROM videos WHERE id={$_GET['id_not']} ")or die(mysql_error());
    $res = mysql_fetch_array($del);

    if(is_file('img_admin/videos/'.$res['file']))
    {
    unlink('img_admin/videos/'.$res['file']);
    }

    $borrar = mysql_query("DELETE FROM videos WHERE id=".$_GET['id_not']);
    }




    if(isset($_POST['insert']) && $_POST['insert'] != "")
    {
    if(isset($_POST['link']) && $_POST['link'] != "")
    {
    if($_FILES['div0']['tmp_name']!="")
    {

    if($_FILES)
    {
    $tamano = $_FILES['div0']['size'];

    $tipo = $_FILES['div0']['type'];

    $archivo = $_FILES['div0']['name'];

    $prefijo = substr(md5(uniqid(rand())),0,6);

    $file = $prefijo."_".$archivo;

    $folder = "img_admin/videos/".$file;

    if (copy($_FILES['div0']['tmp_name'],$folder))
    {
    $SQL= utf8_decode("INSERT INTO videos VALUES('','".$_POST['titulo']."','".$_POST['texto']."','".$file."','".$_POST['link']."')");


    $res = mysql_query($SQL) or die(mysql_error());
    }
    else
    {
    echo"<script>alert('NO SUBIO EL ARCHIVO');</script>";
    }

    }//end Files

    }
    else
    {
    echo"<script>alert('EL CAMPO DE LA IMAGEN VIENE VACIO');</script>";
    }


    }
    else
    {
    echo"<script>alert('DEBES COLOCAR EL EMBED DEL VIDEO');</script>";
    }
    }
    ?>


    <div id="form_not_up">
    <p>MIDE 300 x 155, LA IMAGEN<br />
    DEBE SER EXACTA EN SU TAMAÑO. </p>
    <form action="menu.php?int=videos" method="post" name="files" id="files" enctype="multipart/form-data">
    <input name="insert" type="hidden" value="true" />
    <br />
    <p>
    TITULO <br />
    <input type="text" name="titulo" id="titulo" style="width:500px;" />
    <p>
    <p>
    DESCRIPCION <br />
    <input type="text" name="texto" id="texto" cols="62" rows="8" style="width:500px;"></textarea>
    <p>
    <div id ="campo">
    <input type="file" name="div0" id="div0" />
    </div>
    <br />
    <p>
    EMBED VIDEO <br />
    <input type="text" name="link" id="link" style="width:500px;" />
    <p>
    <div style="padding-bottom:30px; padding-top:10px;">
    <input name="subir" type="submit" id="subir" value="PUBLICAR" />
    </div>
    </form>
    </div>
    <div id="cont_reg" style="overflow:hidden;">
    <?php
    $res_not = mysql_query("SELECT * FROM videos")or die(mysql_error());
    while($resBan = mysql_fetch_array($res_not))
    {
    echo "
    <div style='float:left: width:120px; margin-right:10px;'>
    <div style='width:120px;'><img src='http://img.youtube.com/vi/".$resBan['texto']."/default.jpg' /></div>
    <div class='texto_not' style='width:120px;'>
    <a class='texto_not' style='width:120px;' href='menu.php?int=videos&id_not=".$resBan['id']."' onclick=\"return confirm('Borrar&aacute;".utf8_encode($resBan['titulo'])."')\">
    Borrar Archivo >>
    </a>
    </div>
    </div>
    ";


    }
    ?>
    </div>


    -------------------------------------------------------------


    Please Help me with this i will appreciate, thanks!


    Remember, im just need:


    1.- Remove Required Strings
    2.- File Upload
     
    altadosis, Jan 27, 2012 IP
  2. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    It seems to be doing all that already! I can see the file upload part for sure.

    if it doesnt work check and make sure the directory img_admin/videos is writable.
     
    iama_gamer, Jan 27, 2012 IP
  3. altadosis

    altadosis Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ---------------------------

    Hi, thanks for the response, but my question was... how i can remove the file upload part without affect all the code?

    and the other question was, how i can remove the strings like echo"<script>alert('EL CAMPO DE LA IMAGEN VIENE VACIO');</script>"; and the other alerts, by the way, how this alerts works? how the order of the fields required???

    thanks!!
     
    altadosis, Jan 28, 2012 IP
  4. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    You can safely remove the echo strings. They are just used to alert the user through a alertbox.

    And i do not understand by what you mean by remove file uploaded part. The whole code seems to only be to either upload or delete a file.
     
    iama_gamer, Jan 29, 2012 IP
  5. altadosis

    altadosis Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ----------------

    Yes, you are correct, thanks for all the help, but please remember i dont know about databases and php things, please, give me a hand, im just want to insert to the data base 3 fields, titulo, desc and embed.

    Im already trying with this code:

    <?php
    include('connect.php');
    ?>


    <div id="form_not_up">
    <p>MIDE 300 x 155, LA IMAGEN<br />
    DEBE SER EXACTA EN SU TAMAÑO. </p>
    <form action="video_app.php" method="post">
    <br />
    <p>
    TITULO <br />
    <input type="text" name="titulo" id="titulo" style="width:500px;" />
    <p>
    <p>
    DESCRIPCION <br />
    <input type="text" name="desc" id="desc" cols="15" rows="8" style="width:500px;"></textarea>
    <p>
    EMBED VIDEO <br />
    <input type="text" name="embed" id="embed" style="width:500px;" />
    <p>
    <div style="padding-bottom:30px; padding-top:10px;">
    <input name="subir" type="submit" id="subir" value="PUBLICAR" />
    </div>
    </form>
    </div>


    <div id="cont_reg" style="overflow:hidden;">
    <?php
    $res_not = mysql_query("SELECT * FROM videos")or die(mysql_error());
    while($resBan = mysql_fetch_array($res_not))
    {
    echo "
    <div style='float:left: width:120px; margin-right:10px;'>
    <div style='width:120px;'><img src='http://img.youtube.com/vi/".$resBan['desc']."/default.jpg' /></div>
    <div class='texto_not' style='width:120px;'>
    <a class='texto_not' style='width:120px;' href='menu.php?int=videos&id_not=".$resBan['id']."' onclick=\"return confirm('Borrar&aacute;".utf8_encode($resBan['desc'])."')\">
    Borrar Archivo >>
    </a>
    </div>
    </div>
    ";


    }
    ?>
    </div>


    And then it connect to video_app.php

    and this is the code:


    <?php


    include('connect.php');


    $id=rand(0,4);
    $titulo=$_POST['titulo'];
    $desc=$_POST['desc'];
    $embed=$_POST['embed'];


    $insertar= mysql_query ("INSERT INTO videos VALUES('".$id."',
    '".$titulo."',
    '".$desc."',
    '".$embed."',)", $link);


    if ($insertar)
    {
    echo "Insertado con Exito";

    }
    else
    {
    echo "Insertado Fallido";
    }
    ?>

    -----------------------------

    THIS IS MY DATA BASE:

    CREATE TABLE IF NOT EXISTS `videos` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `titulo` text CHARACTER SET utf8 COLLATE utf8_spanish_ci NOT NULL,
    `desc` text CHARACTER SET utf8 COLLATE utf8_spanish_ci NOT NULL,
    `embed` text CHARACTER SET utf8 COLLATE utf8_spanish_ci NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=35 ;

    -------------------------------

    AND THIS IS MY CONNECT.PHP FILE

    <?php
    /*$host = 'localhost';
    $user = 'root';
    $password = 'root';
    $db = '*****sis';
    */

    $host = 'localhost';
    $user = '*****_userGrl';
    $password = '*****';
    $db = '*****_admin';



    //conectamos
    $link = mysql_connect($host, $user, $password) or die("ERROR AL CONECTARSE: ".mysql_error());

    mysql_select_db($db, $link);

    ?>

    -------------------------------

    But when i try to insert by the form, give me the error INSERTADO FALLIDO, means Insert Failed, can you please help me, what im doing grong?
     
    Last edited: Jan 29, 2012
    altadosis, Jan 29, 2012 IP
  6. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Put this line :
    echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
    Code (markup):
    after
    
    else
    {
    echo "Insertado Fallido";
    
    Code (markup):
    before the } and run it. That will give the error and you can debug from there.
     
    iama_gamer, Jan 29, 2012 IP
  7. altadosis

    altadosis Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7

    It saids the next legend "1064: 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 ')' at line 4"

    Any idea? thanks!
     
    altadosis, Jan 29, 2012 IP
  8. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #8
    Ah i see there is an extra comma after embed in the query. Rewrite the query of the form INSERT INTO videos(column1,column2,columns3) Values ('val1','val2','val3');
     
    iama_gamer, Jan 29, 2012 IP