PHP - Checkboxes And Isset
Hey all,
I am fairly new in the php world and have set myself a challenge to create a display of a database. I have the database displaying what I want but now am trying to have a 'complete' field where if ticked it will delete that field from the db. The row ['complete'] line 30 is saved in the db as '0' when ticked I want this to change to a '1' and delete that line from the db. I have tried a few things but am getting a little bit lost. Any help would be much appreciate <?php $con = mysql_connect("Host","USER","PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("TABLE", $con); $result = mysql_query("SELECT * FROM Priority"); echo "<table border='1' width='100%'> <tr> <td width='5%'>Ticket Number</td> <td width='5%'>Order #</td> <td width='65%'>Ticket Info</td> <td width='15%'>Assigned by</td> <td width='5%'>Priority</td> <td width='10%'>Complete</td> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>#" . $row['ID'] . "</td>"; echo "<td>" . $row['OrderNumber'] . "</td>"; echo "<td>" . $row['TicketInfo'] . "</td>"; echo "<td>" . $row['Assignedby'] . "</td>"; echo "<td>" . $row['Priority'] . "</td>"; echo "<td><input type='checkbox' name='Check' value='Check' /></td>"; //the last row, where the checkbox is is actually a row called ['complete'] } if(isset($Check) && $Check != "") { mysql_query("UPDATE Priority SET Complete = '1' WHERE $row = 'ID'"); } echo "</table>"; mysql_close($con); ?> <?php $con = mysql_connect("HOST","USER","PASS"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_query("DELETE FROM Priority WHERE Complete='1'"); mysql_close($con); ?> Similar TutorialsHi, my PHP code currently outputs the results from a users search by querying a backend postgresql database. As result/row is retuned to the user i would like to be able to detect whether or not they have checked a checkbox at the end of each rown in which case multiple rows can then be deleted from the database upon the user clicking a 'delete multiple records' button. I have no problem in being able to display the checkboxes on the webpage but i am a little unsure as to how to refernce them and detect which ones the user has checked. Given my database stores hostnames/IP addresses would it be best to name each checkbox to reflect the hostname or name the value it returns when checked to reflect the hostname. Given the above and that I also store the results of a users search in a $_SESSION['hosts'][][] array how can I then tie the two together? Thanks for reading. why dose this not work <?php if(isset($_SESSION['SESS_ADMIN'])) $loc = ../admin/admin.php; else $loc= ../head/head.php"; ?> <form><INPUT TYPE="button" value="Main Menu" onClick="parent.location='<?php echo $loc; ?>'"></form> </body> </HTML> I believe that my problem is with the isset on line 7 and 39, but I do not know of anyway around it. Can someone enlighten me. <?php session_start(); if (isset($_GET['logout'])){ unset($_SESSION['logged_in']); } ?> <html> <head> <title>Add a New Car!</title> <?php if (isset($_POST['submit'])) { //print_r($_POST); $password = md5($_POST['password']); //echo'<p>'.$password.'</p>'; $username = ($_POST['username']); //echo'<p>'.$username.'</p>'; } $db = new PDO('sqlite:login.sqlite'); $login = 'SELECT * FROM login WHERE userid="'.$username.'" AND password="'.$password.'";'; //echo'<p>'.$login.'</p>'; $attempt = $db->query($login); foreach ($attempt as $row) { //print_r($row); $_SESSION['logged_in'] = $username; } ?> </head> <body> <?php if (!isset($_SESSION['logged_in'])){ ?> <form method="post" action="Db_login.php"> <p>Username:<br /><input type="text" name="username" /> </p> <p>Password:<br /><input type="password" name="password" /></p> <p><input type="submit" name="submit" value="Log In!" /></p> </form> <?php } else { ?> <?php if(isset($_POST['submit'])) { print_r($_POST); $make = ($_POST['make']); $model = ($_POST['model']); $year = ($_POST['year']); $fuel = ($_POST['fuel_type']); $vin = ($_POST['vin_number']); $reg = ($_POST['reg_number']); } $db = new PDO('sqlite:cars.sqlite'); $sqlCars = 'INSERT INTO cars ( ) VALUES("'.$make.'","'.$model.'","'.$year.'","'.$fuel.'","'.$vin.'","'.$reg.'");'; echo'<p>'.$sqlCars.'</p.>'; ?> <form method="post" action="Db_new_Cars.php" enctype="multipart/form-data"> <p>Make:<br /><input type="text" name="make" /> </p> <p>Model:<br /><input type="text" name="model" /></p> <p>Year:<br /><input type="text" name="year" /></p> <p>Fuel Type:<br /><input type="text" name="fuel_type" /></p> <p>Vin Number:<br /><input type="text" name="vin_number" /></p> <p>Reg Number:<br /><input type="text" name="reg_number" /></p> <p>Choose a image to upload:<br /> <input type="file" name="myfile"></input></p> <p><input type="submit" name="submit" value="Submit!" /></p> </form> <h1> Protected Content!</h1> <p>You are logged in as <em><?php echo $_SESSION['logged_in']; ?> </em></p> <p><a href="Db_login.php?logout=true">Log out!</a></p> <p><a href="New_Cars.php">Add a new car</a></p> <p><a href="Book_Out_Cars.php">Book out a car</a></p> <?php } ?> </body> </html> I want to get the COUNT of the fields (ArrayM11 - ArrayM19), which has the word "YES". The code isn't working. Appreciate any help. $Array1 = array(); for($j=0;$j<count($ArrayM1);++$j) { $result = array_count_values($ArrayM1[$j]); if (isset($result['YES'])) { $points1 = $result['YES']; } } guys this thing called isset() is bugging me.What is the difference in when you say Code: [Select] if(isset($_POST['name'])) and Code: [Select] if($_POST['name']) and Code: [Select] if(!$_POST['name']) and why would someone require a code such as Code: [Select] if($_POST['submit']=='Submit') And what is that code which tells you the user has entered something into the form Thanks People This is blowing my mind. I have this function and all I want it to do is check to make sure that the var $race is set and = '0'. The default value from the form is '0'. I also want it to check the value of race and if it is anything but the two listed , submit error. Yes I've tried to replace the || with &&.. Nothing works(Meaning that it will error when its not suppose to or it wont error when its suppose to).. Any ideas? Code: [Select] function check_Race ($race,$display_name,$member_id,$description,$ip) { //echo "This is the race". $race; //exit; if (isset($race) && $race ='0' && $race !== 'White' && $race !== 'Black'){ echo "This is an errror.!"; $t_error="19"; $member_id = $member_id; notify_Admin($t_error,$member_id,$ip); // logOut ($t_error); exit; } Hello all, i am hoping someone can help me. i have some code i have been working on and i am trying to add a 404 page if it cant find the page, i know it will be some sort of if statment, but with me been pretty much a noob at php i am stuck. heres the code that the page calls. Code: [Select] function get_content() { //Get page name from browser if none call it home $page = (isset($_GET['page'])) ? $_GET['page'] : 'home'; //Get The Page Content $sql = "SELECT * FROM content WHERE page = '$page'"; $res = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_assoc($res)){ //Show The Page Content echo '<h1>' . $row['title'] . '</h1>'; echo $row['body']; } } thanks all. Hi there, I'm inserting data into a mysql database. My submissions works fine, however when a part of the form is not filled out the php scripit crashes. How can I submit all data that is set and skip pieces that aren't filled out? For example I have a plant database which has an option to insert different types of common names for the plant. It's ok if they aren't all filled out. My code is as follows: Code: [Select] <?php //insert general plant data into db $queryplant="INSERT INTO actualplanttable (id, scientific, common1, common2, common3, family, genus, description, planting, growing, care, duration, reference) VALUES ('NULL', '$_POST[scientific]', '$_POST[common1]', '$_POST[common2]', '$_POST[common3]', '$_POST[family]', '$_POST[genus]', '$_POST[description]', '$_POST[planting]', '$_POST[growing]', '$_POST[care]','$_POST[duration]','$_POST[reference]')"; mysql_query($queryplant) or die ('Error updating actualplanttable'); //insert maintenance data into db $querymaintenance="INSERT INTO plantmaintenancelinktable (plant_id, maintenance_id) VALUES ('$inserted_id', '$_POST[maintenance]')"; mysql_query($querymaintenance) or die ('Error updating plantdurationtable'); ?> Should I be trying to work an isset function into this code? Any help would be greatly appreciated. Thanks! Bill... i Have two page login.php and verify.php In login.php user is entering Username and Password and in the action of the form i am writing verify.php. If verification is a success then i will start a session() Code: [Select] session_start(); $_SESSION['ls']="loggedin"; // ls stands for login status $_SESSION['id']=$row['id']; $_SESSION['user_name']=$row['user_name']; $_SESSION['email']=$row['email']; header('location : members.php'); die (" "); and will redirect them to members.php .... Everything is working fine... But in login.php i have written a code on the top... Code: [Select] <?php if(isset($_SESSION['ls']) && isset($_SESSION['id']) && isset($_SESSION['user_name']) && isset($_SESSION['email']) ) { header('location:members.php'); die(" "); } ?> I want if a session is started and if user will access login.php they will automatically go to members.php But this script is not working... Iam not getting whats the problem... also i m not getting any error login.php or anything CODE WRITTEN ON THE TOP OF members.php IS : Code: [Select] <?php session_start(); if(@$_SESSION['ls']!=="loggedin" ) // Checks if the person has done stage one (Registration.php) { header('Location: login.php'); //If they haven't done it, it sends them back. die (" "); } ?> Hi all I need to do a multiple if isset to get three variables from the URL. Here is my code for just one: if(isset($_GET['category'])) { $fetchproducts = mysql_query(" SELECT * FROM `products` WHERE category = '".$_GET['category']."'"); while($returnedProduct = mysql_fetch_array($fetchproducts)) { include('product-cell.php'); } How do I combine this to check what is the 'type' and 'colour' from the URL and fetch from the SQL accordingly? Many thanks for you help Pete Isn't this code redundant... if (isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == TRUE){ After all, if $SESSION['logged_in'] == TRUE then it is *obviously* set... Debbie I'm having a problem where when I click the "use" link it only displays my check message which is "Hey", but for some reason I have to click it again for my queries to work. Here's a pick: . Here's the code: Code: [Select] <?php if(isset($_SESSION['user'])){ include_once('connect.php'); $session = $_SESSION['user']; echo " <br/> <div class='profile-general-stats'> <table> <th>Item Name</th><th>Description</th><th>Use/Sell</th> "; $yo = "SELECT * FROM player_items WHERE Username = '$session' ORDER BY id ASC"; $check = mysql_query($yo) or die (mysql_error()); $num_of = mysql_num_rows($check); if($num_of > 0){ while ($is = mysql_fetch_array($check)){ $item_id = $is['id']; $item_name = $is['Name']; $item_type = $is['Type']; $item_value = $is['Value']; $item_description = $is['Description']; $item_sell_value = $is['Sell_Price']; echo " <tr> <td align='left' style='padding: 5px; padding-left: 25px;'><strong>$item_name</strong></td> <td align='left' style='padding: 5px;'>$item_description</td> <td align='middle' style='padding: 5px;'><a href='?use&id=$item_id&name=$item_name&type=$item_type&value=$item_value'>Use</a> | <a href='#sell_$item_name' id='$item_id'>Sell</a></td> </tr> "; } }else{ echo " <tr> <td align='left' style='padding: 5px; padding-left: 25px;'>No Items</td> <td align='left' style='padding: 5px;'>No Items</td> <td align='middle' style='padding: 5px;'>No Items</td> </tr> "; } echo " </table> </div> "; if(isset($_GET['use'])){ echo "Hey"; $use_id = $_GET['id']; $use_name = $_GET['name']; $use_type = $_GET['type']; $use_value = $_GET['value']; if($use_type == "Credits"){ $use_type = "Current_Credits"; } $check_item = "SELECT id FROM player_items WHERE id = '".mysql_real_escape_string($use_id)."' AND Username = '".$_SESSION['user']."'"; $run_check = mysql_query($check_item) or die(mysql_error()); $num_check = mysql_num_rows($run_check); $e = mysql_fetch_array($run_check); $item_stat = "SELECT `".$use_type."` FROM stats WHERE Username = '".$_SESSION['user']."'"; $run_stat = mysql_fetch_array(mysql_query($item_stat)) or die (mysql_error()); $new_stat = $run_stat[''.$use_type.'']; if($num_check == 1){ $new_stat = $new_stat + $use_value; mysql_query("UPDATE stats SET `".$use_type."` = '".mysql_real_escape_string($new_stat)."' WHERE Username = '".mysql_real_escape_string($_SESSION['user'])."'") or die(mysql_error()); mysql_query("DELETE FROM player_items WHERE id = '$use_id'") or die(mysql_error()); }else{ } }else{ } }else{ header("Location: index.php"); } ?> Hi guys, first time posting here. Anyway, heres my problem. I have this section of code at the beggining of my page: Code: [Select] if (isset($_POST['userChoice'])) { $try = check_word($_POST['userChoice']); echo ("We are into the loop"); } else { echo ("<br/>about to call change word"); changeword(); echo ("<br/> we called the changeword"); } And here is my form: Code: [Select] <html> <head> </head> <body> <form name="wordguess" action="Index.php" method="POST"> <table> <tbody> <tr> Try to guess what the following word is: <?=$scrambled ?> <br/> </tr> <tr> Your Guess: <input type="text" id="userChoice" size="20" /> <br/> </tr> <tr> <td> <input type="submit" name="submit" id="submit" value="Submit"> </td> </tr> <tr> <?=$correct?> </tr> </tbody> </table> </form> </body> </html>' Now, how i assumed it worked was that the first time the page is loaded it would display the form and that's it. However, even when they hit the submit button on the form, its not really doing the POST, so when the page reloads, gives me the same stuff so it always goes on the else part of the if. Any help would be appreciated. Thanks, GoodVibe Hi Everyone, I am a great fan of the 'isset' function, which I use alot when submitting forms, but not wanting to navigate away from the page. Normally I just use a form with a submit button with a name, for example: Code: [Select] <input type='submit' name='updatetable' value='Go!'/> and then use the following: <?php if (isset ($_POST['updatetable'])) { do this stuff... } ?> But I want to start to use images as submit buttons, so when you click on them, you are able to submit the underlying data. Is there a way to do this using the isset function? Because effectively, the image, which would submit using javascript, wont have a name. Any ideas appreciated Many Thanks Matt Hi guys I am trying to create a page where if a selection has not been made then a jump menu is displayed listing all of the fixtures for a season, if a selection has been made then at present I want it to show Enter match info, however when a match is selectd it goes to a yahoo search page, as if the page cannot be found, the code I have used is below, any ideas what I have done wrong? The page can be seen at www.yardleyheroes.co.uk/admin/edit_result.php Code: [Select] <h1>Submit Results</h1> <?php if (isset ($_GET['match_id'])) { echo('Enter match info'); } else { $con = mysql_connect('localhost', 'user', 'password', true); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('dbname', $con); echo('<form name="form" id="form">'); echo('<select name="jumpMenu" id="jumpMenu" onChange="MM_jumpMenu(\'parent\',this,0)">'); $fixtures=mysql_query('SELECT * FROM `fixtures` where current=1 ORDER BY `match_date`'); if(mysql_num_rows($fixtures)==0) echo('<option>there is no data in table..</option>'); else echo('<option selected="selected">Please select the match</option>'); { while($matchrow=mysql_fetch_assoc($fixtures)) { echo ('<option value="edit.php?match_id='.$matchrow['match_id'].'">'.date("d-M-Y", strtotime($matchrow['match_date'])).'|'.$matchrow['Opposition']."</option>"); } } echo('</select>'); echo('</form>'); } ?> [/cod] Hi there, I have just move hosts with our website and it loads the frontpage but non of the subsequent pages. The site works like this, depending on the variables in the address depends which page and which template are loaded into it. If the template is "ros" it loads rosettes template, if it is "tro" it loads trophy template, and then the name of the item, ie "hazel" will load up the hazel product page. All it is doing at the moment is loading the home.php page. The code to do this is below: <? if (!isset($template)) {include ("static/home.php");} else if (isset($id)) { if (!file_exists("site_templates/$template.php")) { echo "OOPS! <P> The template you have requested does not exist!<BR><BR><BR><BR><BR><BR>"; }elseif (file_exists("site_templates/$template.php")) { include ("site_templates/$template.php"); } } ?> It worked with our last host, but refuses to work now. Is there someone out there that can help. Thanks in advance, Phil Im trying to use an if isset to stop my error messages displaying before they submit the form it worked on another part of my website but wont work for this, It just wond submit the form at all when i click submit here is the code: <html> <head> </head> <body> <form action="contact.php" method="post"> <fieldset> <legend>Contact Us</legend> Your Email:*<br> <input type="text" name="email"><br> Subject:*<br> <select name="subject"> <option value=""></option> <option value="1">Recruitment</option> <option value="2">Absense</option> <option value="3">Enquiry</option> </select> <br> Message:*<br> <textarea name="message" cols="50" rows="5"></textarea><br> <?php require_once('recaptchalib.php'); $publickey = "6LeB8LwSAAAAAKwvC3HWJNwWw9vYiSEkvFEvDduD"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> <br> <input type="submit" value="Send Email"> </form> Required fields are marked with a *<br><br> <?php if(isset($_POST['Submit'])){ $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = "nathan_k_boothby_1994@hotmail.co.uk"; //checcking that all relevent information is entered and correct if(!$message || !$email) { $errmessage ="Please fill in all required data."; } require_once('recaptchalib.php'); $privatekey = "6LeB8LwSAAAAAA_0IIEnAxL5uOau0TBm83Iog7Ey"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $errmessage ="The text you wrote did not match the image."; } //Sending the email if nothing is wrong if(!$errmessage) { header("location:send.php?to=".$to."&subject=".$subject."&email=".$email."&message=".$message.""); }else{ echo $errmessage; } } ?> </fieldset> <br><br><br> </body> </html> And here is a link to the page: http://valiantflight.comlu.com/emailer/contact.php Any help will be greatly appriciated, Thanks, Blink359 Hi, just began working with the isset function, and having a few problems with the following code. As you can see I'm trying to assign some variables using the explode function. This is the string that is taken from the form on my index page http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/refresh_stat_manual?user_id=100000898907997&auth_key=e5f4a2308d13346b4bf6e8228e9f50636240bf9f&nocache=1290001265332& $RawHeader = str_replace(' ', '', $_POST['RawHeader']); if (isset($RawHeader)) { $UserID = explode('user_id=', $RawHeader); $UserID = explode('&', $UserID[1]); $UserID = $UserID[0]; $AuthKey = explode('auth_key=', $RawHeader); $AuthKey = explode('&nocache=', $AuthKey[1]); $AuthKey = $AuthKey[0]; } I am new to the isset function so I don't really know if there is anything wrong with it, but if I try echo out both $UserID and $AuthKey it returns nothing. Any suggestions or solutions? Thanks Code: [Select] if (isset($_COOKIE['hide_div']['0']) && isset($_COOKIE['hide_div']['2'])){ $cookie1 = $_COOKIE['hide_div']['0']; $cookie2 = $_COOKIE['hide_div']['2']; } if ($cookie1 == $cat_id OR $cookie2 == $cat_id) { foreach ($this->forums as $forum_id => $forum_data) { if ($forum_data['category'] == $cat_id) { //----------------------------------- // We store the HTML in a temp var so // we can make sure we have cats for // this forum, or hidden forums with a // cat will show the cat strip - we don't // want that, no - we don't. //----------------------------------- $temp_html .= $this->process_forum($forum_id, $forum_data); } } if ($temp_html != "") { $this->output .= $this->html->CatHeader_Expandedhidden($cat_data); $this->output .= $this->html->end_this_cat(); } unset($temp_html); }else{ $cookie1 = ''; $cookie2 = ''; why in the world is it displaying Undefined variable: cookie1 and cookie2 as errors? When I declared both of them even AFTER my if statement, this is bogus dude, lol this isset stuff is really confusing or am i just not doing it right? The below should be making it so that in order for "customer reviews" to be visible, you should need the "&review" in the url, but it's coming up regardless if it's in the URL or not. http://ghosthuntersportal.com/store.php?product=2 Code: [Select] elseif(isset($_GET['product'])){ $product_id=$_GET['product']; $sql500="SELECT * FROM $tbl_name3 WHERE product_id='$product_id'"; $result500=mysql_query($sql500); $num_rows500=mysql_num_rows($result500); if($num_rows500==0){ $average_rating=0; } else{ while($row500=mysql_fetch_array($result500)){ extract($row500); $total = $total + $review_product_rating; $review.=' <div class="review_container"> <div>'.$review_product_rating.' '.$review_title.'</div> <div>By '.$review_name.' from '.$review_location.' on '.$review_date.'</div> <div>Pros: </div><div>'.$review_pros.'</div> <div>Cons: </div><div>'.$review_cons.'</div> <div>Describe Yourself: </div><div>'.$review_describe.'</div> <div>Best Use: </div><div>'.$review_best_use.'</div> <div>'.$review_text.'</div> </div> '; } $review_product_rating_total=$total; $average_rating=$review_product_rating_total/$num_rows500; } $sql50="SELECT * FROM $tbl_name WHERE product_id='$product_id'"; $result50=mysql_query($sql50); while($row50=mysql_fetch_array($result50)){ extract($row50); $section=ucwords($product_category); $product_name=ucwords($product_name); $crumbs='<a href="./index.php">Home</a> <span class="eleven">></span> <a href="./store.php?cat='.$product_category.'">'.$section.'</a> <span class="eleven">></span> <a href="./store.php?product='.$product_id.'">'.$product_name.'</a>'; $section=" - ".$section; $product_highlights=str_replace("[","<li>", $product_highlights); $product_highlights=str_replace("]","</li>", $product_highlights); $content.=' <div class="product_wrapper"> <div>'.$product_name.'</div> <div class="product_image"> <div><img src="'.$product_image.'" alt="'.$product_name.'" /></div> </div> <div class="product_details"> <div class="product_price">Price: $'.$product_price.'</div> <div class="product_code">GHP#: '.$product_code.'</div> <div class="rating_image">'; if($num_rows500==0){ $content.='No Rating'; } else{ $content.='<img src="'.$average_rating.'.png" alt="'.$average_rating.'" />'; } $content.=' <span class="twelve">('.$num_rows500.' Reviews)</span></div><div>'; if(isset($product_highlights)){ $content.='<div class="product_highlights_text">Product Highlights</div><div class="product_highlights_item"><ul>'.$product_highlights.'</ul></div>'; } else{ } $content.='</div> </div> </div> '; } $content.='<div class="product_links_headers">Overview | Specifications | Customer Reviews</div>'; if(isset($review)){ $content.='<div style="margin-top: 400px;">'.$review.'</div>'; } elseif(isset($specifications)){ $content.='<div style="margin-top: 400px;">'.$product_specifications.'</div>'; } else{ } } |