Page 1 of 1

Product Problem!

Posted: Tue Aug 10, 2004 9:28 pm
by Joe
I am having a problem in my script where I am posting values from the previous form. The problem is when the administrator adds a new product it uses ALTER to add a new column to the database but I am finding it hard to adjust to my query. For example if two products were in the database table the $string variable would look like:

Code: Select all

$string = "'$fullname','$value','$value'";
$string is used as the actual main query. Like:

Code: Select all

$nextsql = "INSERT INTO dbproductsinline VALUES(".$string.")";
The problem is if the admin adds a new product the query has to detect that the new column exists. For example the original query would then become:

Code: Select all

$string = "'$fullname','$value','$value','$value'";
The other problem is determining which data has to be passed. The above examples uses $value for each element which only posts one value and spaws each column. The main code go's like:

Code: Select all

$sql1 = "SELECT * FROM dbproducts";
$result = mysql_query($sql1) or die(mysql_error());

while (true)
{
 $row = mysql_fetch_assoc($result);
 if ($row == false) break;
 $val = $row['product'];
 $val1 = str_replace(" ","-",$val);

 $value = $_POST[$val1];
 $string = "'$fullname','$value','$value'";
}

$nextsql = "INSERT INTO dbproductsinline VALUES(".$string.")";
mysql_query($nextsql) or die(mysql_error());
I apologise for the bad explination, any help appreciated though!


Regards


Joe 8)

Posted: Tue Aug 10, 2004 10:27 pm
by hawleyjr
You really need to be using database normalization for this. Check out the links I posted in this topic.

viewtopic.php?t=24609&highlight=normalization