mercredi 30 décembre 2015

How to store multiple checkbox value in one column database?

I want to store checkbox value to one column info database and set it NULL for table user

Here is my code for checkbox:

<tr valign="top">
<td class="label">How did you hear about our journal?</td>
<td class="value">
<input type="checkbox" name="Info[]" id="Info" value="Advertisement"/> <label for="Info">Advertisement</label><br />
<input type="checkbox" name="Info[]" id="Info" value="Colleagues" /> <label for="Info">Colleagues</label><br />
<input type="checkbox" name="Info[]" id="Info" value="Conferences" /> <label for="Info">Conferences</label><br />
<input type="checkbox" name="Info[]" id="Info" value="Friends" /> <label for="Info">Friends</label><br />
<input type="checkbox" name="Info[]" id="Info" value="Journal Website" /> <label for="Info">Journal Website</label><br />
<input type="checkbox" name="Info[]" id="Info" value="News" /> <label for="Info">News</label><br />
<input type="checkbox" name="Info[]" id="Info" value="Search Engine"/> <label for="Info">Search Engine</label><br />
<input type="checkbox" name="Info[]" id="Info" value="Twitter" /> <label for="Info">Twitter</label><br />
<input type="checkbox" name="Info[]" id="Info" value="Others"/> <label for="Info">Others</label><br />

</td>
</tr>

output

and code to store checkbox value:

/**
 * Get info.
 * @return string
 */
function getInfo() {
    return $this->getData('Info');
}

/**
 * Set Info
 * @param $Info string
 */
function setInfo($Info) {
    $checkbox = implode(",",$this->setData('Info', $Info));
    return $checkbox;
}

/**
 * Internal function to return a User object from a row.
 * @param $row array
 * @return User
 */
function &_returnUserFromRow(&$row) {
    $user = new User();
    $user->setInfo($row['Info']);
    return $user;
}

/**
 * Insert a new user.
 * @param $user User
 */
function insertUser(&$user) {

    $this->update( sprintf('INSERT INTO users
                          (Info)
                          VALUES (?)',

                          array( $user->getInfo() )
                          );

    return $user->getId();
}

and it is return null on database.

null

Is there any steps missing/mistake in my code because I can't figure it out. Please help. Thanks.




Aucun commentaire:

Enregistrer un commentaire