Hi,
I have two pieces of code, one calls the other and passes some information across.
I have a customisable table in the database that any user can create. The problem that I am receiving now is that I am using a foreach statement to loop through the table and drop the text fields on the page.
Then the separate inputs need to be transferred to the next page and inserted into the database as text into the relating field.
The code I already have, I feel is close but I am having errors as I will show.
Thanks in advance with your help with this, I've been on it hours so far and have run out of ideas!
<?php
$result = mysql_query("SHOW COLUMNS FROM <variable named table> WHERE Field NOT IN ('Column1','Column2')");
$count = 0;
while ($row=mysql_fetch_row($result)){
$cnt = 0;
foreach ($row as $item){
if ($cnt == 0){
$cnames[$count] = $item;
$cnt++;
$count++;
}
}
}
?>
<?php
$i = 0;
foreach($cnames as $c){
echo $c?> <input name="ProductValue[<?php echo $c;?>]" type="text"><br>
<?php $i++?>
<?php } ?>
<input name="Save" type="image" src="images/add.png" align="right">
<?php }
?>
The page that the above form leads to is:
$ProductValue = $_GET['ProductValue'];
<?php foreach($ProductValue as $name=>$value){
$query = "INSERT INTO <variable table name> (".$name.") VALUES ('".$value."')";
}
$result = @mysql_query($query, $connection)
or die ("Unable to perform query<br>$query");
header("Location: PRODUCTS.php");
exit();
The errors I am receiving are as follows:
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\SALESDOCK\AddProductForm.php on line 21
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\SALESDOCK\AddProductForm.php on line 34
Thankyou for looking at this