PHP - While Loop Works Till A Box Is Checked
I am creating a while loop puts a checkmark in a check box when two variables match. The code works till I place a checkmark in a check box. When that happens I get this error message :Fatal error: Uncaught Error: Call to a member function bind_param() on boolean. I can't figure out what is causing this to error out. This is the code that I am using <fieldset> <legend>Categories</legend> <?php $stmt2 = mysqli_query($db, 'SELECT catID, catTitle FROM blog_cats ORDER BY catTitle'); while($row2 = mysqli_fetch_assoc($stmt2)){ $stmt3 = $db->prepare('SELECT catID FROM blog_post_cats WHERE catID = ? AND postID = ?') ; $stmt3->bind_param("ii", $row2['catID'], $postID); $stmt3->execute(); $stmt3->bind_result($row3catID); $stmt3->fetch(); if($row3catID == $row2['catID']){ $checked = 'checked = "checked"'; } else { $checked = null; } echo '<input type="checkbox" name="catID[]" value="'.$row2['catID'].'" '.$checked.'>'.$row2['catTitle'].'<br />'; } ?> </fieldset> This is what the source looks like when using google chrome <fieldset> <legend>Categories</legend> <input type="checkbox" name="catID[]" value="2" >Development<br /><input type="checkbox" name="catID[]" value="9" >Earn Money From Home<br /><input type="checkbox" name="catID[]" value="1" checked = "checked">General<br /><br /> <b>Fatal error</b>: Uncaught Error: Call to a member function bind_param() on boolean in /storage/ssd2/059/12276059/public_html/admin/edit-post.php:141 Stack trace: #0 {main} thrown in <b>/storage/ssd2/059/12276059/public_html/admin/edit-post.php</b> on line <b>141</b><br /> The first two first two empty check boxes work just fine then the third is checked and after that the code stops working, I don't understand why. Similar Tutorialsi want to select * from table where date >= sunday whats the easiest way to get the date format for the last sunday? <?php include("classes/DomDocumentParser.php"); //this could be the problem it appears in the error file $alreadyCrawled() = array(); $crawling = array(); $startUrl = "https://imagimedia.co.za"; //Get variable from input $hnam = str_replace("http://", "", "$startUrl"); $hnam = str_replace("https://", "", "$hnam"); $hnam = str_replace("www.", "", "$hnam"); $hnam = substr($hnam, 0, -6); function createLink($src, $url) { $scheme = parse_url($url)["scheme"]; $host = parse_url($url)["host"]; if(substr($src, 0, 2) == "//") { $src = $scheme.":".$src; } else if(substr($src, 0, 1) == "/") { $src = $scheme."://".$host.$src; } else if(substr($src, 0, 2) == "./") { $src = $scheme."://".$host.dirname(parse_url($url)["path"]).substr($src, 1); } else if(substr($src, 0, 3) == "../") { $src = $scheme."://".$host."/".substr($src, 3); } else if (substr($src, 0, 4) != "http") { $src = $scheme."://".$host."/".$src; } return $src; } function followLinks($url) { global $hnam; global $alreadyCrawled; global $crawling; $parser = new DomDocumentParser($url); $linkList = $parser->getLinks(); foreach($linkList as $link) { $href = $link->getAttribute("href"); if(strpos($href, "#") !== false) { continue; } else if(substr($href, 0, 11) == "javascript:") { continue; } $href = createLink($href, $url); if(strpos($href, "$hnam") == false) { continue; } //this could be the problem if(!in_array($href, $alreadyCrawled)) { $alreadyCrawled[] = $href; $crawling[] = $href; //insert $href } echo $href."<br />"; } array_shift($crawling); foreach($crawling as $site) { followLinks($site); } } followLinks($startUrl); ?> include file <?php class DomDocumentParser { private $doc; public function __construct($url) { $options = array( 'http'=>array('method'=>"GET", 'header'=>"User-Agent: imagimediaBot/0.1\n") ); $context = stream_context_create($options); $this->doc = new DomDocument(); @$this->doc->loadHTML(file_get_contents($url, false, $context)); } public function getLinks() { return $this->doc->getElementsByTagName("a"); } } ?> Edited December 19, 2020 by guymclarenza added include file Hey.
So the issue I'm having is consecutive loops on semi-large arrays, over and over. Consider this array:
$firstArray = array( 'row1' => array( 'dates' => array( '2014-01-01' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-02' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-03' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-04' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-05' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-06' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-07' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), ) ), 'row2' => array( 'dates' => array( '2014-02-01' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-02' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-03' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-04' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-05' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-06' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-07' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-08' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-09' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), ) ) );Originally the data comes from ~2-3 database tables, of course. But to ilustrate the point, this is how the main array looks like. This array usually contains anywhere between 10-50 rows, each row containing at least 10 dates, with 10 key/values each. And after setting up all the data, it needs to be processed. Currently this is how a friend of mine did it.. $placeDataHere = array(); foreach($firstArray as $key => $dates) { foreach($dates as $date => $values) { foreach($values as $key => $value) { $placeDataHere['DV_' . $date]['SM_' . $key] = 'KS_' . $value; //Followed by another ~50-70 lines of processing the 3 loop's data.. ... ... .... .... .... .... .... .... } } }Obviously this isn't good practise, but we can't seem to figure out a better way of doing it, since both the data and the loops are horribly nested. This loop and setup of $firstArray is run anywhere between 10-20 times/request, due to amount of users we wish to process. So, the result is that this code can take up to over 2-3 minutes to complete, which isn't really optimal performance. In short my question is, are there any better methods of handling this with the data setup we currently have? i am having issues checking which value is checked in a form. here is my code for it: Code: [Select] <input type="radio" name="accountActivation" id="no" value="no" checked=" <? if (isset($register_errors)) { if (($_POST['accountActivation']) == "no") { echo "checked"; } } ?> " /> when i first open the page, no is checked. why is this, when there should be no errors, and the radio should not even be checked in the first place? How to write the code to get the count of the word "CHECKED" from a row? I tried this and it's not working. Please help. $query = mysql_query("SELECT field1, field2, field3, COUNT(CHECKED) as counter FROM db1 WHERE row_name = 'science'"); while($line = mysql_fetch_array($query)) { echo $query['counter']; } Hello all, The following script is used to query an array. (www.example.com/test.php?lev[]=MS&lev[]=College) Currently, it echos the values queried and simply lists them (echo "$lev (br />\n"). Is it possible to echo those values by keeping the checkbox in question checked instead? Code: [Select] <?php echo "<b>Levels <br /> />"; if(!empty($_GET['lev'])) foreach($_GET['lev'] as $lev){ echo "$lev <br />\n"; } ?> <form /> <input type="checkbox" name="lev[]" value="PreK" /><font class="sm">PreK</font> <input type="checkbox" name="lev[]" value="Elem" /><font class="sm">Elem</font> <input type="checkbox" name="lev[]" value="MS" /><font class="sm">MS</font> <input type="checkbox" name="lev[]" value="HS" /><font class="sm">HS</font> <input type="checkbox" name="lev[]" value="College" /><font class="sm">College</font> <input type="submit" value=" ..:: Submit ::.. " /> Thank you. ~Wayne Hi guys, I wonder if any if you could help me: I have created a login page with "remember me" function... The page will redirect either to Admin Page or User Page depends their 'level'. But when I logged in as Admin and checked the box "remember me" and close all the browser to see IF the "remember me" work. When I open a new browser - and go to the index page - it is okay, I can view the page.... but it redirect me to the USER page NOT Admin page. Does anyone know why this happens? What is the best way using php to see if a checkbox is checked or not. I see so many different options out there googling, that I am interested knowing the most robust method. Thanks This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=318750.0 hi all I have 3 checkboxes whose values are getting stored in the database with a comma separator. Code: [Select] <input name="color[]" type="checkbox" value="red" id="red" />red <input name="color[]" type="checkbox" value="blue" id="blue" />blue <input name="color[]" type="checkbox" value="green" id="green" />green values getting stored with comma separator Code: [Select] red, blue, green now i want to show the checkboxes as "checked" to show the customer as which colors they chose lasttime when they submitted the form. How can i make it possible ? If it is possible without the comma separator then i can remove the comma. vineet I am using the following piece of code to open a new window when a checkbox is checked... <INPUT type="checkbox" name="name" value="YES" onClick="window.open('/somepage.php?do=something&id=<?php echo $SOMEID["id"] ?>','','width=600,height=350,left=100,top=100,screenX=100,screenY=100')"> The page opens ok when the checkbox is ticked (checked). PROBLEM: The page opens again if the checkbox is un-ticked (un-checked). I just want to open the page if the checkbox is ticked only but not sure how to do this? OTHER INFO: Seperate checkboxes are dynamically created on the page for each id=<?php echo $SOMEID["id"] ?> Hi: How do I check to see if a checkbox has not been checked? Would the same rules apply to a radiobutton? This is what I have: Code: [Select] <input name="status[1]" id="approved" value="<?php echo $_POST['approved'] ?>" type="checkbox" /> <label for="approved">Approved</label> Code: [Select] if (isset($_POST['status[1]'])): $errMsg['status[1]'] = "Must select a status."; endif; I tested it out, but it just prints the error message even if I have checked it Hi all, I have been trying to figure this out for a few days already and can't seem to figure it out. I want to display a few images with a checkbox next to it so I can delete multiple images at once when I press the delete button. My problem is that I can't seem to figure out how to check if the checkbox is checked. if I uncheck one of them and click the delete button it deletes one from the array but I don't know which one was unchecked. For example if I uncheck the second one the array shows: Array ( => on [1] => on ) but I don't know which of the three was unchecked? Here is the code I have been testing with: Code: [Select] <?php // if submit button is clicked if(isset($_POST['submit'])) { // do delete function(); } // display deletethis[] array if (isset($_POST['deletethis'])) { echo "<pre>"; print_r ($_POST['deletethis']); echo "</pre>"; } $separate = array("http://funnypicturesimages.com/images/image/funny-dog-pictures.jpg", "http://1.bp.blogspot.com/-35wQMpYtNZc/TXWNx8y2xCI/AAAAAAAB_2o/9vZYNfWrGn8/s400/funny_demotivational_posters_01.jpg", "http://3.bp.blogspot.com/-TFnzZ8zFtgg/TXWNpodBkGI/AAAAAAAB_2Q/O_fOOSqFM6w/s400/funny_demotivational_posters_04.jpg"); echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; // display each image from array foreach ($separate as $value) { echo "<img src=".$value.">"; if ($_POST['deletethis'] = "on") { $checked="checked"; } else { $checked=""; } if ($_POST['deletethis'] != "") { echo "checked"; } else{ echo "unchecked"; } // if checkbox currently checked display it checked else display unchecked if ($checked == "checked") { echo '<input type="checkbox" name="deletethis[]" checked="checked"/><br /><br />'; } else { echo '<input type="checkbox" name="deletethis[]"/><br /><br />'; } } ?> <center><input type="submit" name="submit" value="Delete Checked"></center> </form> while ($div=mysql_fetch_array($query4, MYSQL_ASSOC)) { //$div - shows all the entries $row22=mysql_fetch_array($query2, MYSQL_ASSOC); //row22 - shows all the entries that should be checked $name= array($div['date_id']); $datess=$row22['date_id']; if (in_array($datess, $name, true)) { echo '<input type="checkbox" value="' . $div[date_id] .'" checked>' . $div[date] . '</option>'; }else{ echo '<input type="checkbox" value="' . $div[date_id] .'">' . $div[date] . '</option>'; } 1. when echo $row22 shows only the entries that should be checked - working good 2. checkboxes show checked if only the first checkbox is selected or all 3 - if a combination is selected, it is all blank. Any ideas? Thank you This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=358408.0 Hey, I'm new to this stuff. But I'm calling a Table with a list of products, I want people to be able to compare the products they checked. what is the best way of doing this with the code below? I put "blah" for everything except for the compare table and calls. This code seemed to work the best for the look I wanted for it. They all call the checkbox from 'Compare' in the mysql table. Thanks! $result = mysql_query("SELECT * from Compare_Tool ORDER BY Blah ASC"); //Table starting tag and header cells echo "<table border='1'><tr><th>Compare</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th></tr>"; while($row = mysql_fetch_array($result)){ ?> <tr> <td align="center"><input name="checkbox[]" type="checkbox" Compare="checkbox[]" value="<? echo $row['Compare']; ?>"></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> </tr> <?php } echo "</table>"; ?> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=349419.0 Hello, I'm new to the forum so bare with me. I'm trying to take data entered into a text box on a form and have that data checked against an associative array. I've attached a .doc with some pictures showing how the data should be displayed. It's the checking part that I'm having trouble with. Any help would be appreciated Thanks This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=349419.0 <?php $goal = rand(1, 3); ?> <td><div align="left"> Goal</div></td> <td><label> <div align="center"> <input type="radio" name="goal_chk" id="radio2" value="1" <?php if($goal == "1") { echo "checked"; }?> /> </div> </label></td> <td><label> <div align="center"> <input name="goal_chk" type="radio" id="radio13" value="2" <?php if($goal == "2") { echo "checked"; }?> /> </div> </label></td> <td><label> <div align="center"> <input type="radio" name="goal_chk" id="radio23" value="3" <?php if($goal == "3") { echo "checked"; }?> /> </div> </label></td> </tr> i have a group of radio buttons whose value is checked randomly everytime you refresh the page, now that works fine, everytime you refresh the page the checked values moves randomly but the problem i have is getting the actual of a checked radio button. i have tried this... $goal_checked = $_POST['goal_chk']; echo $goal_checked; But nothing happens. Any ideas on how to make this possible. Thanks a lot you guys. |