Jump to content

Recommended Posts

??? hii<

 

I started leaning php recently, and am having a go at making an editable database which runs through MySQL. At this point, I have a problem with recognising or storing a value that is (hopefully) sent via a checked checkbox.. I assume that checked is one return value and unchecked is another, but using the print_r function, the return value from a checked checkbox is simply "" null and nothing and its making me very sad :(

 

Is there something stupidly simple that I've tripped over?

Thanks you very much in advance..

 

orb

 

P.S. The form sends all inputs to a form called amendjob.php - and this php is currently simply has enabled the code:

 

print_r($_POST);

Link to comment
https://forums.phpfreaks.com/topic/71519-solved-nub-q/
Share on other sites

Well the form code is like this:

 

<form name="input" action="amendjob.php" method="post">
<input type="hidden" name="id" value="<?php echo $_GET['id'] ?>">
Priority:
<select name="priority" value="<?php echo $queryrow['Priority']; ?>">
<option value="">Not Set</option>

<?php
//$queryrow['Priority']=2;
for ($i=0; $i<=5; $i++){
echo "<option ";
if ($queryrow['Priority']==$i) {echo "selected=\"selected\" ";}
echo "value=\"".$i."\">".$i."</option>\n";
}
?>
</select>
<br>
IT Staff:
<input type="text" name="itstaff" size="20" value="<?php echo $queryrow['IT Staff']; ?>">
<br>
Started:
<input type="checkbox" name="started" size="8" value="<?php echo $queryrow['Started']; ?>">
<br>
Finished:
<input type="checkbox" name="finished" size="8" value="<?php echo $queryrow['Finished']; ?>">
<br>
Complete: 
<input type="checkbox" name="complete" value="Car" value="<?php echo $queryrow['Complete']; ?>" />
<br>
Hold: 
<input type="checkbox" name="hold" value="Car" value="<?php echo $queryrow['Hold']; ?>" />
<br>
On hold since:<br>
<input type="text" name="onholdsince" size="8" value="<?php echo $queryrow['On hold since']; ?>">
<br>
Notes:<br>
<textarea rows="10" cols="30" name="notes" value="<?php echo $queryrow['Notes']; ?>">
</textarea>
<br>Time Spent:<br>
<input type="text" name="sumofduration" size="8" value="<?php echo $queryrow['Sum of duration']; ?>">
<br>
<br><br><b>Update fields:<br></b><input align="center" type="submit" value="Update" >
</form>

 

Obviously, all this does is send the fields to amendjob.php, while displaying the contents of the database (if there are any values there) on this page which is workonjob.php.

Link to comment
https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360079
Share on other sites

Unfortunately, I haven't actually used check boxes before, so I don't know what to expect.  I do see a couple of errors, though.

 


Started:
<input type="checkbox" name="started" size="8" value="<?php echo $queryrow['Started']; ?>">
<br>
Finished:
<input type="checkbox" name="finished" size="8" value="<?php echo $queryrow['Finished']; ?>">
<br>
Complete: 
<input type="checkbox" name="complete" value="Car" value="<?php echo $queryrow['Complete']; ?>" />
<br>
Hold: 
<input type="checkbox" name="hold" value="Car" value="<?php echo $queryrow['Hold']; ?>" />
<br>

 

On the complete and hold check boxes, you have two value attributes.

 

For testing, try changing all the value attributes to a static value.  Also, where you're trying to set the value attribute to a piece of data from the database, I think you may want to use the checked attribute instead.

Link to comment
https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360106
Share on other sites

Okay, I did some fiddling around.

 

Save this as test.php, and play around with it.  See if it answers your questions.

 

<html>

<head>
<title>
This is a test page
</title>

</head>

<body>

<form action="test.php" method="GET">
  One: <input type="checkbox" name="one" checked value="j0" />
  Two: <input type="checkbox" name="two" value="foo" />
  <input type="submit" name="submit" value="submit" />
</form>

<pre>
<?php
print_r($_GET);
?>
</pre>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360116
Share on other sites

Try this.

 

Started:
<input type="checkbox" name="started" value="started" <?= $queryrow['Started'] ? 'checked' : '' ?> />
<br>
Finished:
<input type="checkbox" name="finished" value="finished" <?= $queryrow['Finished'] ? 'checked' : '' ?> />
<br>
Complete: 
<input type="checkbox" name="complete" value="complete" <?= $queryrow['Complete'] ? 'checked' : '' ?> />
<br>
Hold: 
<input type="checkbox" name="hold" value="hold" <?= $queryrow['Hold'] ? 'checked' : '' ?> />
<br>

Link to comment
https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360123
Share on other sites

Try this.

 

Started:
<input type="checkbox" name="started" value="started" <?= $queryrow['Started'] ? 'checked' : '' ?> />
<br>
Finished:
<input type="checkbox" name="finished" value="finished" <?= $queryrow['Finished'] ? 'checked' : '' ?> />
<br>
Complete: 
<input type="checkbox" name="complete" value="complete" <?= $queryrow['Complete'] ? 'checked' : '' ?> />
<br>
Hold: 
<input type="checkbox" name="hold" value="hold" <?= $queryrow['Hold'] ? 'checked' : '' ?> />
<br>

 

Thanks for this, I think this will work for showing the stored value, although can't check because can't track the value to put into the database.

Arg, :(

 

You'd think the form would send the value as a 1 or 0...

Link to comment
https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360141
Share on other sites

Do you mean it is odd that the values are not printing?

Please could you also add why you think adding a name to the submit input is a good idea? Is it so that an additional reference could be used? It is definetly the case that not any of the values inputted are stored in the database.. haha ;]

 

Thanks for your time though ^^ Much appreciated!

Link to comment
https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360155
Share on other sites

Yes, it's odd that nothing is printing.  I thought it was possible that it could have been a version problem, and you were using $POST instead of $_HTTP_POST_VARS, but that wouldn't be an issue in PHP 5.

 

Here's what generally happens when submitting data from a form.  You've got several inputs in a form.

 

<input type="sometype" name="input_name" value="input_value">

 

When these are submitted, they should populate either the $_GET array or $_POST array depending on the method attribute in the form tag.  The name attribute will be the index in the array, and the value attribute will be the value stored in that index.  Even an submit button should do this.  If not even the value of the submit button is being passed, then there's probably something wrong with PHP, and not your code.

 

Also, on the page that is supposed to be receiving the data, print out both th $_GET array and the $_POST array.

 

I have to admit, I'm kind of grasping at straws here.

 

Something to remember, if you have this input

 

<input type="checkbox" name="foo" value="bar">

 

If the checkbox is not checked, the form will not pass a "foo" element at all.  If the check box is checked, an element "foo" will be passed with the value "bar".

Link to comment
https://forums.phpfreaks.com/topic/71519-solved-nub-q/#findComment-360165
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.