PHP - Abbreviations In Textbox Checked Against An Array.
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 Similar TutorialsHi 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> Like Youtube; when submitting a video; You can insert words into a Textbox named Tags. Each space you leave is considered the start of a new word. How can I do this using PHP + MYSQL. Thanks! 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 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? 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? 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']; } This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=318750.0 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 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"] ?> 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 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 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=349419.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>"; ?> 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=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. 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. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=358408.0 <?php
require_once('upper.php'); require_once('LoginStatement.php'); require_once('database.php'); echo $error_msg=''; require_once('database.php'); $LoginId=$_COOKIE['LoginIdCookie']; $query="select * from registration where LoginId='$LoginId'"; $result=mysqli_query($dbc,$query); $row=mysqli_fetch_array($result); if(isset($_POST['submit'])) { $LoginId=mysqli_real_escape_string($dbc,trim($_POST['LoginId'])); $Name=mysqli_real_escape_string($dbc,trim($_POST['Name'])); $Age=mysqli_real_escape_string($dbc,trim($_POST['Age'])); $BloodGroup=mysqli_real_escape_string($dbc,trim($_POST['BloodGroup'])); if(!isset($_POST['Sex'])) { echo 'Please enter Sex<br>'; } else{ $Sex= mysqli_real_escape_string($dbc,trim($_POST['Sex'])); } $Qualification=mysqli_real_escape_string($dbc,trim($_POST['Qualification'])); $ContactNumber=mysqli_real_escape_string($dbc,trim($_POST['ContactNumber'])); $Email=mysqli_real_escape_string($dbc,trim($_POST['Email'])); $Address=mysqli_real_escape_string($dbc,trim($_POST['Address'])); $AboutYourself=mysqli_real_escape_string($dbc,trim($_POST['AboutYourself'])); //$countCheck=count($_POST['checkbox']); //echo $countCheck; //$checkbox=$_POST['checkbox']; //$countCheck=count($checkbox); if(empty($LoginId)){echo 'Please enter Login Id';} elseif(empty($Name)){echo 'Please enter Name';} elseif(empty($Age)){echo 'Please enter Age';} elseif(!isset($_POST['Sex'])){} elseif(empty($Qualification)){echo 'Please enter Qualification';} elseif(empty($ContactNumber)){echo 'Please enter Contact Number';} elseif(empty($Email)){echo 'Please enter Email';} elseif(empty($Address)){echo 'Please enter Address';} elseif(empty($AboutYourself)){echo 'Please enter About Yourself';} else { if(mysqli_num_rows($result)==0) { $checkbox=$_POST['checkbox']; $countCheck=count($_POST['checkbox']); $reg_id=' '; for($i=0;$i<$countCheck;$i++) { $reg_id=$reg_id.$checkbox[$i].','; } $query="UPDATE registration SET (LoginId,Name,Age,BloodGroup,Sex,Qualification,ContactNumber,Email,Address,AboutYourself,Activity)values ('$LoginId',SHA('$Password1'),'$Name','$Age','$BloodGroup','$Sex','$Qualification','$ContactNumber','$Email','$Address','$AboutYourself',',$reg_id')"; $result=mysqli_query($dbc,$query) or die("Not Connect"); echo ' Dear '.$Name.'.<br>Your request has been mailed to admin.<br>Your account is waiting for approval<br>'; $from= 'Elite Brigade'; $to='ankitp@rsquareonline.com'; $subject='New User Registration'; $message="Dear admin,\n\nA new user request for registration. Please check it out.\n\nRegards\nMicro"; mail($to,$subject,$message,'From:'.$from); //header('Location: index.php'); // header('Location: Registration.php'); } else { echo 'Dear '.$Name. ', <br> An account already exist with login-id<b> '.$LoginId.'</b> <br>Please try another login-id'; }} } ?> <html> <head> <script src="jquery-latest.js"></script> <script type="text/javascript" src="jquery-validate.js"></script> <style type="text/css"> * { font-family: Verdana; } label.error { color: white; padding-left: .5em; } p { clear: both; } .submit { margin-left: 12em; } em { font-weight: bold; padding-right: 1em; vertical-align: top; } </style> <script> $(document).ready(function(){ $("#commentForm").validate(); }); </script> </head> <body> <?php echo $error_msg; ?> <form action='<?php echo $_SERVER['PHP_SELF'];?>' id="commentForm" method='post'> <div class="registration_and_activity"> <table border="0" width="380"> <tr><td colspan="2"> <h3>Update Personal Details</h3></td></tr> <tr><td width="120"> <em>*</em>Enter Login id</td><td width="150"><input type='text' name='LoginId' minlength='4' value='<?php echo $row['LoginId']; ?>' /></td></tr> <tr><td width="120"> <em>*</em>Enter Name</td> <td><input type='text' name='Name' value='<?php echo $row['Name'];?>' /></td></tr> <tr><td> <em>*</em>Enter Age</td><HEAD> <SCRIPT language=Javascript> function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } </SCRIPT> </HEAD> <td><INPUT onkeypress='return isNumberKey(event)' type='text' name='Age' value='<?php echo $row['Age'];?>'/></td></tr> <tr><td> <em>*</em>Enter Blood</td><td><input type='text' name='BloodGroup' value='<?php echo $row['BloodGroup'];?>' /></td></tr> [B]<tr><td> <em>*</em>Enter Sex</td><td><input type='radio' name='Sex' style='width:16px; border:0;' value='Male' checked='<?php if($row['Sex']='Male') echo 'checked';?>'/>Male <input type='radio' name='Sex' checked='<?php if($row['Sex']='Female') echo 'checked';?>' style='width:16px; border:0;' 'value='Female' />Female</td></tr>[/B] <tr><td> <em>*</em>Enter Qualification</td><td><input type='text' name='Qualification' value='<?php echo $row['Qualification'];?>' /></td></tr> <tr><td> <em>*</em>Contact Number </td><td><input onkeypress='return isNumberKey(event)'type='text' name='ContactNumber' value='<?php echo $row['ContactNumber'];?>' /></td></tr> <tr><td> <em>*</em>Enter Email</td><td><input type='text' name='Email'class="email" value='<?php echo $row['Email'];?>' /></td></tr> <tr><td> <em>*</em>Enter Address</td><td><input type='text' name='Address' value='<?php echo $row['Address'];?>' /></td></tr> <tr ><td > <em>*</em>About Yourself </td></tr> <tr><td colspan="2"><textarea rows='10' cols='40' name='AboutYourself' /><?php echo $row['AboutYourself'];?></textarea></td></tr> <tr><td> <?php echo "<tr><td colspan='2' align='center'><input type='submit' value='Update' name='submit' style='background:url(./images/button_img2.png) no-repeat 10px 0px; width:100px; padding:3px 0 10px 0; color:#FEFBC4; border:0;'/></td></tr><br>"; echo " </td></tr></table> </div> </form> </body> </html>"; require_once('lower.php'); ?> Hi friends.......... In above code I want that In database if Sex=Male then Male radio button will be checked automatically and if Sex =Female then Female radio button will be checked. But it not works ........... please help me........... thanks in advance.......... |