Hi.
I have a big problem that I do not know how to solve. I have a form used to insert some data into MYSQL .The database contains some products and the price for every product, a field for products status, another field where is inserted the date when the product is inserted into database, and a field that use auto_increment and will generate a unique value for each product.I want to attach to my form a text field where is inserted the number of how many rows to create in the database with the same product and price. My php code is :
Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
function Basic()
{
require("database.php");
require("configa.php");
require_once("validator.php");
$TableID = $_GET['table_id'];
//print("<h3 align=center>Adding Records to $TableNames[$TableID]</h3>");
print("<table align=center class=Table>");
$Fields = explode("@", $Tables[$TableID]);
echo '<form action="add.php" method="POST">';
$date = date("Y-m-d");
$MappedTable = GetMappedTables($TableID);
print("<tr class=TableAltRow>");
print("<td>product</td><td>");echo '<input type="text" name="';print(product);echo '"></td>';
print("<tr class=TableAltRow>");
print("<td>price</td><td>");echo '<input type="text" name="';print(price);echo '"></td>';
print("");echo '<input type="hidden" name="';print(date);echo '" value="';print($adaugat);echo '"></td>';
print("<tr class=TableAltRow><td><input type=submit name=action value=Add></td><td> </td></tr>");
print("<input type=hidden name=table_id value=$TableID>");
print("</form>");
};
function Add()
{
require("database.php");
require("configa.php");
require("validator.php");
?>
<link rel="stylesheet" type="text/css" href="Colorful.css" />
<?php
$TableID = $_POST['table_id'];
$Fields = explode("@", $Tables[$TableID]);
$QUERY = "insert into `$TableNames[$TableID]`(";
$FieldCounter = 0;
foreach($Fields as $Field)
{
$FieldCounter++;
$QUERY .= "`".$Field."`";
if($FieldCounter < sizeof($Fields))
{
$QUERY .= ", ";
}
else
{
$QUERY .= ") values(";
};
};
$FieldCounter = 0;
foreach($Fields as $Field)
{
$FieldCounter++;
if(Validate($TableID, $Field, $_POST[$Field]) == "false")
{
if($Field != GetMapping($TableID,$Field))
{
$Temp = GetMapping($TableID, $Field);
$Mapped = explode(".", $Temp);
$Key = $Field;
if(!FieldExists("`$Mapped[0]`.`$Field`"))
{
$Key = GetCorrectKey($Mapped[0],$Field);
$qry = "select * from `$Mapped[0]` where `$Mapped[1]`='$_POST[$Field]'";
}
else
{
$qry = "select * from `$Mapped[0]` where `$Mapped[1]`='$_POST[$Field]'";
};
$Result = mysql_query($qry);
$Raw = mysql_fetch_array($Result);
$Key = trim($Key);
$QUERY .= "'".$Raw[$Key]."'";
}
else
{
$TMP = explode(" ", $Field);
if($TMP[1] != "")
{
$Field = str_replace(" ", "_", $Field);
};
$QUERY .= "'".$_POST[$Field]."'";
};
}
else
{
die("The value $_POST[$Field] at $Field in table $TableName[$TableID] is not accepted");
};
if($FieldCounter < sizeof($Fields))
{
$QUERY .= ", ";
}
else
{
$QUERY .= ")";
};
};
// print($QUERY);
mysql_unbuffered_query($QUERY);
if(!mysql_error())
{
print("<H3 align=center>Added Successfully</H3>");
}
else
{
print("<H3 aclign=center>Addition failed : ".mysql_error()."</H3>");
};
echo '<p align=center><a href="main.php?table_id=';print($TableID);echo'">Home</a></p>';
};
if($_POST['table_id'] == "" && $_GET['table_id'] != "")
{
Basic();
}
elseif($_POST['table_id'] != "")
{
Add();
};
?>
I really appreciate any help.