Page 1 of 1

Checkboxes don't work. Mupltiple.

Posted: Wed Feb 08, 2006 12:56 am
by kaisellgren

Code: Select all

<?php
include ("../config/settingsload.php");
include ("../config/config.php");
include ("../config/message.php");

$shostname = $_POST["shostname"];

$link = mysql_connect("$host","$username","$password");
mysql_select_db($database,$link);

$result = mysql_query("SELECT * FROM hosts WHERE hostname = '$shostname'");
$row = mysql_fetch_array($result);

$hostname = $row[0];
$cobranded = $row[35];
$oldhostname = $hostname;
$hosturl = $row[1];
$space = $row[2];
$bandwidth = $row[3];
$filesizelimit = $row[4];
$upload = $row[5];
$forcedads = $row[6];
$interests = $row[7];
$yourads = $row[8];
$dbs = $row[9];
$yoururl = $row[10];
$backups = $row[11];
$inactivitylimit = $row[12];
$additional = $row[13];
$cronjobs = $row[14];
$multipleaccounts = $row[15];
$statistics = $row[16];
$ssl = $row[17];
$realaudio = $row[18];
$realvideo = $row[19];
$htaccess = $row[20];
$passwordprotectedfiles = $row[21];
$customerrorpages = $row[22];
$pop3 = $row[23];
$webmail = $row[24];
$forwarding = $row[25];
$frontpagextensions = $row[26];
$cgiperl = $row[27];
$asp = $row[28];
$php = $row[29];
$ssi = $row[30];
$isml = $row[31];
$cpp = $row[32];
$python = $row[33];
$java = $row[34];
?>

...

<tr><td width="160" class="text" valign="top">Scripting:</td><td class="text">
<input type="checkbox" <?php if ($frontpagextensions == 'yes') echo 'checked="checked"' ?> name="frontpagextensions" value="yes" class="text">FrontPage Extensions<br />
<input type="checkbox" <?php if ($cgiperl == 'yes') echo 'checked="checked"' ?> name="cgiperl" value="yes" class="text">CGI / PERL<br />
<input type="checkbox" <?php if ($asp == 'yes') echo 'checked="checked"' ?> name="asp" value="yes" class="text">ASP<br />
<input type="checkbox" <?php if ($php == 'yes') echo 'checked="checked"' ?> name="php" value="yes" class="text">PHP<br />
<input type="checkbox" <?php if ($ssi == 'yes') echo 'checked="checked"' ?> name="ssi" value="yes" class="text">SSI<br />
<input type="checkbox" <?php if ($isml == 'yes') echo 'checked="checked"' ?> name="isml" value="yes" class="text">ISML<br />
<input type="checkbox" <?php if ($cpp == 'yes') echo 'checked="checked"' ?> name="cpp" value="yes" class="text">C / C++<br />
<input type="checkbox" <?php if ($python == 'yes') echo 'checked="checked"' ?> name="python" value="yes" class="text">Python<br />
<input type="checkbox" <?php if ($java == 'yes') echo 'checked="checked"' ?> name="java" value="yes" class="text">Java<br />
</td></tr> ...
I displays a checkboxes checked if they should be, but the real problem is that it won't send the checked boxes again.

Code: Select all

$frontpagextensions = $_POST['frontpagextensions'];
$cgiperl = $_POST['cgiperl'];
$asp = $_POST['asp'];
$php = $_POST['php'];
$ssi = $_POST['ssi'];
$isml = $_POST['isml'];
$cpp = $_POST['cpp'];
$python = $_POST['python'];
$java = $_POST['java'];
$hosturl = $_POST['hosturl'];

$link = mysql_connect("$host","$username","$password") or die("Error: Could not connect to $host using $username and $password"); 
mysql_select_db("$database") or die("Error: Could not select database $database! ".mysql_error());

mysql_query("UPDATE hosts SET  
hostname = '$hostname',
hosturl = '$hosturl',
space = '$space',
bandwidth = '$bandwidth',
filesizelimit = '$filesizelimit',
upload = '$upload',
forcedads = '$forcedads',
interests = '$interests',
yourads = '$yourads',
dbs = '$dbs',
yoururl = '$yoururl',
backups = '$backups',
inactivitylimit = '$inactivitylimit',
additional = '$additional',
cronjobs = '$cronjobs',
multipleaccounts = '$multipleaccounts',
statistics = '$statistics',
sslsupport = '$ssl',
realaudio = '$realaudio',
realvideo = '$realvideo',
htaccess = '$htaccess',
passwordprotectedfiles = '$passwordprotectedfiles',
customerrorpages = '$customerrorpages',
popthree = '$pop3',
webmail = '$webmail',
forwarding = '$forwarding',
frontpagextensions = '$frontpagextensions',
cgiperl = '$cgiperl',
aspsupport = '$asp',
phpsupport = '$php',
ssisupport = '$ssi',
ismlsupport = '$isml',
cppsupport = '$cpp',
pythonsupport = '$python',
javasupport = '$java',
cobranded = '$cobranded' WHERE hostname = '$oldhostname'") or die("Could not update hosts! ".mysql_error());
Now, if I check the new values, the checkboxes ain't checked anymore :S

PROBLEM: FIRST.HTML IS THE FORM WITH CHECKBOXES. SECOND.PHP SHOWS THE CHECKBOX VALUES (IS CHECKED OR NOT) AND SENDS IT AGAIN TO THIRD.PHP, BUT THIRD.PHP DOES NOT SHOW THE CHECKBOX VALUES RIGHT ANYMORE. WHAT'S THE PROBLEM?

I can submit checkbox values right but if I submit then through two pages I can't ?

Posted: Wed Feb 08, 2006 1:15 am
by feyd
the posted code snippets don't seem to really match up with what you are describing (which did not require caps, mind you :? )

Posted: Wed Feb 08, 2006 2:32 am
by Christopher
When you say "SENDS IT AGAIN TO THIRD.PHP," how is this done? If it is a redirect then the $_POST values will be lost.

Posted: Wed Feb 08, 2006 2:55 am
by kaisellgren
The first html file has the forms with checkboxes.
The second php file takes the values through $_POST and sends the values again using the $_POST to third.php.

That's what I mean.

I have a "update details" form. So the user can change their details and update.

Posted: Wed Feb 08, 2006 2:57 am
by kaisellgren
This won't work either...

index2.php

Code: Select all

<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body topmargin="0" leftmargin="0">
<table border="0" cellpadding="0" cellspacing="0"><tr><td background="../images/configure.gif" width="32" height="32"></td><td width="8"></td><td class="text">Update Host</td></tr></table>

<form action="index3.php" method="post">
<table width="90%" cellspacing="0" cellpadding="2" border="1" bgcolor="#E9F6FC" bordercolor="#21B142" style="border-collapse: collapse">
<tr>
<td class="text"><table width="95%" height="100%">

<tr><td width="160" class="text" valign="top">Select the Host to Update:</td><td>
<input type="checkbox" name="pete" value="yes">JEAAAA
<input type="checkbox" name="pets" value="no">JEAAAA
</td></tr>

<tr><td></td><td>
<input type="submit" name="save" value="Update Host" class="text">
</td></tr>
</table>
</td></tr></table>
</form>
<br /><br />
</body>
</html>
index3.php

Code: Select all

<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body topmargin="0" leftmargin="0">
<table border="0" cellpadding="0" cellspacing="0"><tr><td background="../images/configure.gif" width="32" height="32"></td><td width="8"></td><td class="text">Update Host</td></tr></table>
<?php

$word = $_POST["pete"];
echo "WORD: $word<br />";
if ($word == "yes")
 echo "checked";
else
 echo "NOT YES";
$word = $_POST["pets"];
echo "<br /><br />WORD: $word<br />";
if ($word == "yes")
 echo "checked";
else
 echo "NOT YES";

?>
<br /><br />
</body>
</html>
Those scripts won't work properly. Sometimes it works and sometimes it does not.

Posted: Wed Feb 08, 2006 3:32 am
by feyd
from the posted snippets, I don't see it not working. Can you tell us what you consider not working?

Posted: Wed Feb 08, 2006 5:10 am
by kaisellgren
Try yourself my last post scripts. Make a html file and php script. THE CHECKBOX 1 WAS CHECKED, BUT WHEN I PRESSED UPDATE HOST BUTTON, THE NEW PAGE DID NOT DISPLAY TEXT: CHECKED ? It just displayed not checked.

Here is a picture, I hope you know what I want to make the script do:

[img=http://img228.imageshack.us/img228/982/picture14fp.th.jpg]

[img=http://img206.imageshack.us/img206/2756/picture25ux.th.jpg]

Posted: Wed Feb 08, 2006 6:27 am
by phpScott
copy and pasted your second set of examples and i received what I thought I would be looking for.

Posted: Wed Feb 08, 2006 7:23 am
by kaisellgren
Okay. I am using a CMS, Content Management System.
I have problem with it and I do not know how to fix it. I have made a video about it:
http://www.uploadready.com/v/4253971/clip0003.avi.html

I hope you understand now...

Posted: Wed Feb 08, 2006 8:09 am
by RobertGonzalez
Don't know if helps much but PHP recognizes checkboxes as either empty or 'On' (notice the capital "O"). When you do your comparisons make sure you are checking for the field name set to 'On'. This might help a little bit.

Another question... is your second step not passing the checkboxes to the third step or is one of the pages not getting information from the database?

Posted: Wed Feb 08, 2006 8:11 am
by Benjamin
Is your mysql update query failing?

Why don't you use mysql_fetch_assoc instead of row?

Are register globals on? If not are you using $CheckBoxValue = $_POST['PostedVariableName']?

Have you tried to echo output at each step in the application to debug it?

Have you double checked your MySQL Query?

Posted: Wed Feb 08, 2006 3:25 pm
by raghavan20
I would like to say a few things..
1. you are not checking at the first.html page whether a result is valid and it contains rows in it...
2. do you have error_reporting set for notices?
3. you should be using TRUE or FALSE instead of YES and NO
4. I do not really see here how you pass information from the second page to the third page...
try to print the POST variables at each page so that you know whether form elements' values are passed properly...if you are not passing POST variables from second HTML page to third HTML page by using hidden values and SUBMIT button then you can do a simple redirect and by storing all POST variables as SESSION variables so that you can pass it on to any page...