checkboxes and writing to mysql

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Mh_0
New php-forum User
New php-forum User
Posts: 11
Joined: Thu Nov 14, 2002 7:13 am
Location: UK
Contact:

checkboxes and writing to mysql

Postby Mh_0 » Fri Jan 24, 2003 1:11 am

here are some snippets from my code (which are the bits that deal with the problem) at the moment the values of the checkboxes won't change when I try to write them to the database, has anyone got any ideas please?

Thanks in advance

(ps, the bits of code are in order, I am using forms to reset the page etc)

if ($cruise) {$cruisecheck = 'Y';} else {$cruisecheck = 'N';};
if ($whatsnew) {$whatsnewcheck = 'Y';} else {$whatsnewcheck = 'N';};
if ($sme) {$smecheck = 'Y';} else {$smecheck = 'N';};
if ($users) {$userscheck = 'Y';} else {$userscheck = 'N';};
if ($usersname = 'Admin') {$cruise = 'Y'; $sme = 'Y'; $whatsnew = 'Y'; $users = 'Y';};

$sql = "INSERT INTO Passwords (usersname,Name,password,cruises,sme,users,whatsnew) VALUES ('$username','$name','$encrypted_pswd','$cruisecheck','$smecheck','$userscheck','$whatsnewcheck')";
$result = mysql_query($sql) or die("<b>Query Failed</b><br>\n".$sql."<br>\n".mysql_errno().": ".mysql_error());



if ($myrow[cruises] = 'Y') {echo"<input type='checkbox' value='cruise' name='cruise' align='MIDDLE' size = '10' method ='get' checked>Access to Cruise Admin<br>";}
else {echo"<input type='checkbox' value='cruise' name='cruise' align='MIDDLE' size = '10' method ='get' >Access to Cruise Admin<br>";};

if ($myrow[cruises] = 'Y') {echo"<input type='checkbox' value='sme' name='sme' align='MIDDLE' size = '10' method ='get' checked>Access to SME Admin<br>";}
else {echo"<input type='checkbox' value='sme' name='sme align='MIDDLE' size = '10' method ='get' >Access to SME Admin<br>";};

if ($myrow[cruises] = 'Y') {echo"<input type='checkbox' value='whatsnew' name='whatsnew' align='MIDDLE' size = '10' method ='get' checked>Access to Whats New Admin<br>";}
else {echo"<input type='checkbox' value='whatsnew' name='whatsnew' align='MIDDLE' size = '10' method ='get' >Access to Whats New Admin<br>";};

if ($myrow[cruises] = 'Y') {echo"<input type='checkbox' value='users' name='users' align='MIDDLE' size = '10' method ='get' checked>Access to User Admin<br>";}
else {echo"<input type='checkbox' value='users' name='users' align='MIDDLE' size = '10' method ='get' >Access to User Admin<br>";};

(there is no error message given...)

Papillon
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Jan 21, 2003 2:46 pm
Contact:

Postby Papillon » Fri Jan 24, 2003 2:25 am

if ($myrow[cruises] = 'Y') <--- aint it supposed to be == ?

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Sun Jan 26, 2003 12:35 pm

the same with if ($usersname = 'Admin')
Then when you type this:

Code: Select all

if ($myrow[cruises] = 'Y') {echo"<input type='checkbox' value='cruise' name='cruise' align='MIDDLE' size = '10' method ='get' checked>Access to Cruise Admin<br>";}
else {echo"<input type='checkbox' value='cruise' name='cruise' align='MIDDLE' size = '10' method ='get' >Access to Cruise Admin<br>";};

if ($myrow[cruises] = 'Y') {echo"<input type='checkbox' value='sme' name='sme' align='MIDDLE' size = '10' method ='get' checked>Access to SME Admin<br>";}
else {echo"<input type='checkbox' value='sme' name='sme align='MIDDLE' size = '10' method ='get' >Access to SME Admin<br>";};

if ($myrow[cruises] = 'Y') {echo"<input type='checkbox' value='whatsnew' name='whatsnew' align='MIDDLE' size = '10' method ='get' checked>Access to Whats New Admin<br>";}
else {echo"<input type='checkbox' value='whatsnew' name='whatsnew' align='MIDDLE' size = '10' method ='get' >Access to Whats New Admin<br>";};

if ($myrow[cruises] = 'Y') {echo"<input type='checkbox' value='users' name='users' align='MIDDLE' size = '10' method ='get' checked>Access to User Admin<br>";}
else {echo"<input type='checkbox' value='users' name='users' align='MIDDLE' size = '10' method ='get' >Access to User Admin<br>";};

It could be simplified with this:

Code: Select all

if ($myrow["cruises"] = 'Y') {
   echo"<input type='checkbox' value='cruise' name='cruise' align='MIDDLE' size = '10' method ='get' checked>Access to Cruise Admin<br>";
   echo"<input type='checkbox' value='sme' name='sme' align='MIDDLE' size = '10' method ='get' checked>Access to SME Admin<br>";
   echo"<input type='checkbox' value='whatsnew' name='whatsnew' align='MIDDLE' size = '10' method ='get' checked>Access to Whats New Admin<br>";
   echo"<input type='checkbox' value='users' name='users' align='MIDDLE' size = '10' method ='get' checked>Access to User Admin<br>";

}else {
   echo"<input type='checkbox' value='cruise' name='cruise' align='MIDDLE' size = '10' method ='get' >Access to Cruise Admin<br>";
   echo"<input type='checkbox' value='sme' name='sme align='MIDDLE' size = '10' method ='get' >Access to SME Admin<br>";
   echo"<input type='checkbox' value='whatsnew' name='whatsnew' align='MIDDLE' size = '10' method ='get' >Access to Whats New Admin<br>";
   echo"<input type='checkbox' value='users' name='users' align='MIDDLE' size = '10' method ='get' >Access to User Admin<br>";
}


if the error is still there will try to have another look at the code.
bye!


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron