0

Hi guyz ,
PHP newbie and this piece is givin me a hard time please Help, have indicated the source of the error with a comment

    <?php
    ob_start();
     include("dataaccess.php"); ?>
    <?php 

    $strAction = "list";
        $num = "";
        $strTable = "";
        $strkey = "";


        if(!empty($_POST))
        {
        if (trim($strTable) == "" )
        {
            if ($_POST["tablename"] <> "")
                $strTable = $_POST["tablename"];
        }

        if (trim($strkey) == "" )
            $strkey = $_POST["key"];
        }

        dbConnect();
        $result = mysql_query("Select * from " . $strTable . mysql_error());//this is the error source

        if (!$result)
        {
            die('Invalid formation of Select query in editInsertExec: ' . mysql_error());
        }

        $columns = mysql_num_fields($result);

        $sqlQuery = "INSERT INTO " . $strTable . " (";
        for ($i = 0; $i <= mysql_num_fields($result); $i++) 
        {      
                 if ( mysql_field_name($result, $i) <> $strkey)
                 {  
                 $sqlQuery = $sqlQuery . mysql_field_name($result, $i);
                 if ($i < mysql_num_fields($result)-1)
                    $sqlQuery = $sqlQuery . ", ";       
                }   
        }

        $sqlQuery = $sqlQuery . ") VALUES (" ;

        for ($i = 0; $i <= mysql_num_fields($result); $i++) 
        {   
             if ( mysql_field_name($result, $i) <> $strkey)
                 {
                    $sqlQuery = $sqlQuery . "'" .$_POST[mysql_field_name($result, $i)] . "'" ;
                    if ($i < mysql_num_fields($result)-1)
                            $sqlQuery = $sqlQuery . ", ";
                }
        }



        $sqlQuery = $sqlQuery . ")";

        $sqlQuery = str_replace("''", "", $sqlQuery);

        echo $sqlQuery;
        $result = mysql_query($sqlQuery . mysql_error());

        if (!$result)
        {
            die('Invalid formation of Insert query in editInsertExec: ' . mysql_error());
        }

        mysql_close();

    header("Location: list.php?tablename=".$strTable."&action=list&key=".$strkey);
    ob_end_flush() ;    
    ?>

Quoted Text Here

    <?php
    ob_start();
     include("dataaccess.php"); ?>
    <?php 

    $strAction = "list";
        $num = "";
        $strTable = "";
        $strkey = "";


        if(!empty($_POST))
        {
        if (trim($strTable) == "" )
        {
            if ($_POST["tablename"] <> "")
                $strTable = $_POST["tablename"];
        }

        if (trim($strkey) == "" )
            $strkey = $_POST["key"];
        }

        dbConnect();
        $result = mysql_query("Select * from " . $strTable . mysql_error());

        if (!$result)
        {
            die('Invalid formation of Select query in editInsertExec: ' . mysql_error());
        }

        $columns = mysql_num_fields($result);

        $sqlQuery = "INSERT INTO " . $strTable . " (";
        for ($i = 0; $i <= mysql_num_fields($result); $i++) 
        {      
                 if ( mysql_field_name($result, $i) <> $strkey)
                 {  
                 $sqlQuery = $sqlQuery . mysql_field_name($result, $i);
                 if ($i < mysql_num_fields($result)-1)
                    $sqlQuery = $sqlQuery . ", ";       
                }   
        }

        $sqlQuery = $sqlQuery . ") VALUES (" ;

        for ($i = 0; $i <= mysql_num_fields($result); $i++) 
        {   
             if ( mysql_field_name($result, $i) <> $strkey)
                 {
                    $sqlQuery = $sqlQuery . "'" .$_POST[mysql_field_name($result, $i)] . "'" ;
                    if ($i < mysql_num_fields($result)-1)
                            $sqlQuery = $sqlQuery . ", ";
                }
        }



        $sqlQuery = $sqlQuery . ")";

        $sqlQuery = str_replace("''", "", $sqlQuery);

        echo $sqlQuery;
        $result = mysql_query($sqlQuery . mysql_error());

        if (!$result)
        {
            die('Invalid formation of Insert query in editInsertExec: ' . mysql_error());
        }

        mysql_close();

    header("Location: list.php?tablename=".$strTable."&action=list&key=".$strkey);
    ob_end_flush() ;    
    ?>

Edited by janguyo: Had missed out error source

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by pritaeas
0

$result = mysql_query("Select * from " . $strTable . mysql_error());//this is the error source

Should be:

$result = mysql_query("Select * from " . $strTable) or die(mysql_error());
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.