sql query error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepaks85
    New Member
    • Aug 2006
    • 114

    sql query error

    Dear Friends,

    I don't know I am not able to run this query. I am able to insert records but I don't know why I am not able to select and display the records....Plea se help me.......

    [PHP]<?php

    $hostname="mysq l3.secureserver .net";
    $username="mydb ";
    $password="mypa ssword";
    $dbname="mydb";

    mysql_connect($ hostname,$usern ame, $password) OR DIE ("Unable to connect to database! Please try again later.");
    mysql_select_db ($dbname);

    $numfiles = $_POST['numfiles'];

    $queryIns = ("INSERT INTO numfile(numfile ) values('$numfil es')");

    if(!@mysql_quer y ($queryIns)) {
    echo mysql_error();
    }
    else{

    $querySel = "SELECT * from numfile where id = (SELECT MAX(id) from numfile)"; // I am facing problem in this query
    $result = mysql_query($qu erySel);
    if($result)
    {
    while($row = mysql_fetch_arr ay($result)){

    echo "maximum id is : ".$row['numfile'];

    }
    }
    else
    {
    echo "no records selected";
    }

    }

    ?>[/PHP]




    Thanks
    Deepak
    Last edited by deepaks85; May 8 '07, 07:12 PM. Reason: wrong script
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Originally posted by deepaks85
    [PHP]
    $numfiles = $_POST['numfiles'];
    [/PHP]
    As a sidenote, this should at least be:
    [PHP]
    $numfiles = addslashes($_PO ST['numfiles']);
    [/PHP]

    You don't want to know what might happen if $_POST['numfiles'] happens to contain "'; DROP TABLE `numfile`;".

    Originally posted by deepaks85
    [PHP]
    $querySel = "SELECT * from numfile where id = (SELECT MAX(id) from numfile)"; // I am facing problem in this query
    [/PHP]
    Try:

    Code:
    SELECT * FROM `numfile` ORDER BY `id` DESC LIMIT 1;
    It's also faster ;)

    Comment

    Working...