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!
I'm currently trying to use a form to add data into a product table, the table is customisable which means I can rarely hard code the names of the attributes that I need the user to fill in.
$ProductValue = $_GET['ProductValue'];
$result = mysql_query("SHOW COLUMNS FROM ".$_SESSION['Username']."");
$count = 0;
while ($row=mysql_fetch_row($result)){
$cnt = 0;
foreach ($row as $item){
if ($cnt == 0){
$cnames[$count] = $item;
$cnt++;
$count++;
}
}
}
?>
<?php foreach($cnames as $c){
$query = "INSERT INTO <variable table name> (".$c.") VALUES ('$ProductValue')";
}
$result = @mysql_query($query, $connection)
or die ("Unable to perform query<br>$query");
header("Location: PRODUCTS.php");
exit();
?>
As you can probably tell by the code, as I am using a variable in a loop, only the last piece of data stored in the ProductValue variable is being saved to the database.
If someone could assist me in getting all of the data stored in the database I would be very grateful.