Updating database wont work...

Paste Your code(s) here, and state your problem.

Updating database wont work...

Postby trigger » Wed Sep 11, 2013 2:38 pm

Hello. I have a website associated with my IRC channel, and I am trying to get a database update feature working. I have html data from a form, as follows:

Code: Select all
   <td><input type="checkbox" name="check[]" value="one"></td>
   <td><input type="checkbox" name="check[]" value="two"></td>
   <td><input type="checkbox" name="check[]" value="three"></td>
   <td><input type="checkbox" name="check[]" value="four"></td>   

This gets passed to the php processor as an array just fine. What I am trying to do, is find out if the userid is already in the database table, and if it is, then to go thru the array and update the fields for each filed checked. If the checkbox is null, then enter a "no", if its checked, then enter a "yes".

However, if the userid is not in that table, then I want it to insert the userid and the apropriate fields into the table. The names of the check boxes correlate with the names of the fileds in the table. Here is the code so far..

Code: Select all
include 'config.php';
$userid = $_SESSION['userid'];

if(!empty($_POST['check'])) {

   $query1 = "SELECT `userid` FROM `interests` WHERE `userid`= '$userid '";
   $result = mysql_query($query1);
   while($row = mysql_fetch_array($result, MYSQL_ASSOC))
       foreach($_POST['check'] as $check) {
          if($check != "yes") {
             echo 'CHECK = NULL </br>';
             } else {
             echo 'CHECK = '.$check. '</br>';
         $query = "UPDATE interests SET $choice=$change WHERE userid='$userid'";

echo 'Your interests have been updated into the database, and those files will now</br>';
echo 'begin showing up in the files area on your files sections.';

It is not working yet. Can anyone see where I might need to be heading or doing something differently?

Posts: 2
Joined: Sun Sep 08, 2013 4:24 pm
Authnick: trigger

Return to PHP Help

Who is online

Users browsing this forum: No registered users and 0 guests