Hey guys, I'm stuck in a weird situation. Heres what I have going on with my script. Please bare with me as this is really hard to explain. I created a table for username, password, and shop for "Shop Owners". I then created another table for username and password for "Normal Users". But when I'm registering for a shop owner, I added a code that would add an extra row for every new shop to "Normal users" . When filling out the registration form for "Normal Users", they have to click on the checkboxes of the shops they have shopped at. To get all the latest shops, I run this PHP code. <?php $result = mysql_query("SELECT * FROM shopowners"); while($row = mysql_fetch_array($result)) { echo "<input type='checkbox' name='" . $row['Shop'] . "' value='1' /> - " . $row['Shop']; echo "<br />"; } ?> PHP: Thats all well and nice but my problem is how would I go about inserting the values in the checkboxes to the "Normal Users" database. Because before, when creating the shop owners accounts, I made it so that everytime a new shop it added, it adds a row to the "Normal Users". Heres what I tried but it didn't work. $registerquerytwo = mysql_query("INSERT INTO normalusers (Username, Password, Name $result = mysql_query("SELECT * FROM shopowners"); while($row = mysql_fetch_array($result)) { echo "," . $row['Shop']; } ) VALUES ('".$usernametwo."', '".$passwordtwo."', '".$name."' $result = mysql_query("SELECT * FROM shopowners"); while($row = mysql_fetch_array($result)) { echo ",\'\".$" . $row['Shop'] . ".\"\'; } )"); PHP: If anyone has a clue about what I'm trying to do here, please help me out. I'd greatly appreciate it. Thanks,
Maybe you are trying to do something like this: $shopColumns = ""; $shopValues = ""; $result = mysql_query("SELECT Shop FROM shopowners"); while($row = mysql_fetch_assoc($result)) { $shopColumns .= $row['Shop'].","; $shopValues .= "'".($_POST[$row['Shop']]=="1"?$_POST[$row['Shop']]:0)."',"; } $shopColumns = substr($shopColumns,0,strlen($shopColumns)-1); // Remove last comma from $shopColumns. // $shopValues = substr($shopValues,0,strlen($shopValues)-1); // Remove last comma from $shopValues. // $registerquerytwo = mysql_query("INSERT INTO normalusers (Username, Password, Name, $shopColumns) VALUES ('$usernametwo', '$passwordtwo', '$name', $shopValues)"); PHP: