Jump to content

Tick Box, select and update database.


rainemaida

Recommended Posts

Ok, I am trying to change the value in table with a tick box. If the tick box is selected it changes the value in the field to 'y' and if it is not selected it changes the field to 'n'.

 

First of all I need to bring back the current state of the field and then I need to be able to update it from 'y' to 'n' as many times as I want.

 

<?

// Get the ID of the chosen thing and store it in a variable
$id = $_GET['id'];

// If the submit button is pressed, execute the update code
if (isset($_POST['Submit']))
{
// Store the new values inserted into the form in variables
$u_email=$_POST['uemail'];
$u_mobile=$_POST['umobile'];
$u_sEmail=$_POST['usubscribedEmail'];
$u_sMobile=$_POST['usubscribedMobile'];

// Store the update query string in a variable
     $update="UPDATE user SET email='$u_email', mobile='$u_mobile', subscribedEmail='$u_sEmail', subscribedMobile='$u_sMobile' WHERE userID='$id'";

// Execute the query on the database
$updated = mysql_query($update);

if($updated)
{
	// Output a confirmation message telling the user that the update was successful
	echo 'Record Updated';
}
else
{
	// Output error message if the update was not executed successfully
	echo 'Error, Update not successful';
}

}

// Store the query string to select the chosen things details from the table
$query="SELECT * FROM user WHERE userID='$id'";

// Execute the query on the database
$result = mysql_query($query);

echo "<p class='leftmargin'><font face='arial'><a href='coursedocumentsstudent.php'>Course Documents ></a> Preferences</p>";
echo "<img src='images/seperator.jpg' width='100%' height='20'>";

// Store the results in an array and print them in a clear format
while ($value = mysql_fetch_array($result))
{
// Display the form with the returned data in it
	echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" >';
echo '<table width="90%" align="center">';
echo '<tr><td><b>E-Mail Settings</b><br></td></tr>';
echo '<tr><td><font color="black" size="2px" face="arial">E-Mail Address:</td><td> <input type="text" name="uemail" value="'.$value[4].'" /></td></tr></table>';
echo '<br><img src="images/seperator.jpg" width="100%" height="20"><br>';
echo '<table width="90%" align="center">';
echo '<tr><td><b>Mobile Phone Settings</b><br></td></tr>';
echo '<tr><td><font color="black" size="2px" face="arial">Mobile Number:</td><td> <input type="text" name="umobile" value="'.$value[5].'" /></td></tr><br></table>';
echo '<p align="right"><input type="Submit" value="Update" name="Submit" /></form>';

}

 

There's my code and I need to add a checkbox with name="usubscribedEmail" and I guess it's the value of this tick box that I'm after.

 

Cheers,

Steve

Link to comment
https://forums.phpfreaks.com/topic/45397-tick-box-select-and-update-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.