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