Product Problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Product Problem!

Post 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)
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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
Post Reply