PHP - Select Is Posting Info That Doesnt Exist
hello all,
i have a quick question. i have a select all from toolout with toolid = $tid. the problem is, if there isnt an entry yet in toolout, it is giving me the info from the row above. is there any way that i can do a (if it doesnt exist, set $status to 1, rather than using the previous rows code) my code is below. Code: [Select] if(isset($_POST['search'])) { $tool=$_POST['tool']; echo "<table border='1' style='border-collapse: collapse' bordercolorlight='#000000' bordercolordark='#000000' width='98%' align='center'>"; echo "<tr><td width='100%' colspan='5' align='center'><b>Tool List - $tool</b></td></tr>"; echo "<tr> <th align='center'>Tool</th> <th>Location</th> <th>Status</th> </tr>"; $result = mysql_query("SELECT * FROM tools WHERE toolgroup LIKE '%$tool%' ORDER BY tool"); while($row = mysql_fetch_array($result)) { $id=$row['id']; $tool=$row['tool']; $barcode=$row['barcode']; $location=$row['location']; $result2 = mysql_query("SELECT * FROM toolout WHERE toolid = '$id' ORDER BY id ASC"); while($row2 = mysql_fetch_array($result2)) { $status=$row2['status']; $who=$row2['who']; $datechanged=$row2['datechanged']; $datechanged1 = date( 'M j, Y', strtotime($datechanged) ); if("$status" == "1") { $statusout="<font color='#0000FF' size='4'>IN</font><br /><a href='toolout.php?tool=" . $id . "' target='action'>SIGN OUT</a>"; } if("$status" == "2") { $statusout="<font color='#FF0000' size='4'>OUT</font><br />$who - $datechanged1"; } if("$status" == "3") { $statusout="<font color='#00FF00' size='4'>PENDING OUT</font><br />$who - $datechanged1"; } if("$status" == "4") { $statusout="<font color='#00FF00' size='4'>PENDING IN</font><br />$who - $datechanged1"; } } echo "<tr>"; echo "<td align='center'>" . $tool . "</td>"; echo "<td align='center'>" . $location . "</td>"; echo "<td align='center'>"; if (isset($status)) { echo "$statusout"; } else { echo "<font color='#0000FF' size='4'>IN</font><br /><a href='toolout.php?tool=" . $id . "' target='action'>SIGN OUT</a>"; } echo "</td>"; echo "</tr>"; } echo "</table>"; } Thank you so much. Similar Tutorialshi, i have a select which gets todays schedule for each user. sometimes that user doesnt have anything for todays date and it will display the info from the user above him. how can i make it so it stays blank if there is no record? hello, i am having an issue with tables using incorrect data. i have 2 columns, first is employee name, second is location if the employee doesnt have a location for the current day, it is telling me he is at the same location as the guy in the row above him. i need this to be blank. is this possible? I have an array like so Array (14) ( | ['0'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['1'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['2'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['3'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['4'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['5'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['6'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['7'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['8'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['9'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['10'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['11'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['12'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) | ['13'] => Array (5) | ( | | ['name'] = String(7) "Pikemen" | | ['hp'] = Integer(1) 0 | | ['atk'] = Integer(1) 5 | | ['def'] = Integer(1) 5 | | ['rng'] = Integer(2) 15 | ) ) what i want to do is add the details to a new multi dimensional array but only add one each like so array( ['units'] = array( ['name'] => 'Pikemen', ['lost'] => 14 ) ) basically where the HP is 0 in the first array i need to add them to the second if the name is unique. I have tried array unique but it didnt seem to work. Any ideas? All i get it a loop of each Pikemen Hey, I have this code below which seems to completely fail sending my laptop cpu fan on a frenzy. All I am wanting to do is find whether the id in the url is located inside the array below else state its not in an error saying its not a valid id (for people who change the url shown below). At the moment it doesnt like the else statement if the isset clause it not true. (I have also tried, array_key_exists) All I can think is that it get stuck looking for an id that doesnt exist inside the array but keeps searching though I dont know much about arrays etc. Besides this when a id is inside the array the script works like I want it to. Any ideas would be much appreciated as this is hold me back at the moment Code: [Select] //url: http://localhost/website/shop.php?id=10197 // Array is built from table prior to this as it will grow in size $_SESSION['storesProducts'] = Array ( [10197] => 0 [10198] => 0 [10199] => 1 [10200] => 1 [10201] => 1 [10202] => 1 [10205] => 0 [10206] => 1 [10207] => 1 ) if(isset($_SESSION['storesProducts'][$id])){ $storesProducts = $_SESSION['storesProducts'][$id]; if($storesProducts == 0){ $list = $this->displayCategories($id); }else{ $createProducts = new constructProducts(); $products = $createProducts->pagination($id); } }else{ $list = "ITS NOT HERE"; } $output = new outputShop(); $output->display($list, $products); This is more of a Paypal question, but I'm using php on the listener and hopefully someone has run into this problem. I'm having trouble finding the correct POST name to use to get the OPTION SELECT for the item on my listener page. I tried: $option = $_POST['os0']; But, I'm not getting anything using that. I've also tried os0_x, on0, and on0_x. This is what I'm posting to Paypal: <input type="hidden" name="on0" value="Term"> <select name="os0"> <option value="1 Year">1 Year</option> <option value="3 Years">3 Years</option> <option value="5 Years">5 Years</option> </select> Edited November 3, 2019 by jakebur01 Hi - how's it going? I've been working on something with no luck and I'm wondering if you have any ideas. I have two tables; Members and Events. When a member logs in they are redirected to a page where I want them to be able to see a list of events that they have created based on a user ID that is common in both tables. So if the member has a memberID of 123 I want them to see any events that have the userID of 123. I used two different column names just for clarity. I've tried a number of variations on the following code: <?php session_start(); header("Cache-control: private"); // Connect to Database include ('includes/db.php'); //Has login info // If not logged in if (!$_SESSION['pkMemberID']) { echo ("<div class='box'><h2>Sorry, you are not logged in!</h2>"); exit(); } // Convert Session variable 'pkMemberID' to simple variable. $memberID = $_SESSION['memberID']; $pkMemberID = $_SESSION['pkMemberID']; $name = $_SESSION['name']; //Query Events $sql = "SELECT * FROM events WHERE userID = $memberID"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); echo ("<div>Events:<br />"); // Event exists if (!($num_rows == 0)) { $myrow = mysql_fetch_array($result); do { printf ('<span>– <a href="event_edit.php?pkEventID=%s">%s</a></span><br />', $myrow['pkEventID'], $myrow['eventName']); } while ($myrow = mysql_fetch_array($result)); } echo ("</div>"); //End Events //end page ?> Sometimes I get errors, sometimes just nothing. Any advice would be appreciated. Hi, All: I'm trying to figure out what way it's the best way to pull info belonging to a specific user based on whether he's a logged-in "member", and want to make sure he's not able to access any other member's details... would the best way be to try to match the user's "username" stored in a $_SESSION when fetching his info, something like this: Code: [Select] <?php // Assume the login combo is this: $username = $_POST['username']; $password = $_POST['password']; // Assume he has already logged in: $_SESSION['username'] = $username; //EXAMPLE 1: SELECTING user info simply from actual DB username/password match: if ($_SESSION['username']) { $userRecords = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"); $userInfo = mysql_fetch_array($userRecords); echo $userInfo['id'] . $userInfo['username'] . $userInfo['first-name'] . $userInfo['last-name'] . $userInfo['date-register']; } // EXAMPLE 2: or SELECTING user info based on $_SESSION['username'] value: if ($_SESSION['username']) { $userRecords = mysql_query("SELECT * FROM users WHERE username = . $_SESSION['username'] . AND password = '$password'"); $userInfo = mysql_fetch_array($userRecords); echo $userInfo['id'] . $userInfo['username'] . $userInfo['first-name'] . $userInfo['last-name'] . $userInfo['date-register']; } ?> So, my question is, are this actually working differently? is one better than the other as far as security, preventing other users from hacking either on purpose or accidenally into other user's details? thank! Appreciate any feedback... i have error where my code should update existing data where id exist, it get updated ..but the others data is disappeared .only the data updated is remained $sql1 ="select*from semakan_dokumen where email='$stdEmail'"; $sqlsearch1 = mysqli_query($dbconfig,$sql1); $resultcount1 = mysqli_num_rows($sqlsearch1); if($resultcount1 > 0){ $query1=("UPDATE semakan_dokumen set student_id='$noMatrik', email= '$stdEmail', surat_tawaran='$fileName', ic='$fileName1',sijil_lahir='$fileName2',sijil_spm= '$fileName3',sijil_sekolah= '$fileName4', sijil_dip= '$fileName5',sej_julai='$fileName6',bm_julai='$fileName7',muet='$fileName8', mid1='$fileName9',yuran= '$fileName10',umpa_bend1= '$fileName11',umpa_bend2='$fileName12',bpkp='$fileName13', penaja='$fileName14',kesihatan= '$fileName15', jhepa='$fileName16' where email= '$stdEmail' "); }else{ //filezip $query1 = "INSERT INTO semakan_dokumen (email,surat_tawaran,ic,sijil_lahir,sijil_spm,sijil_sekolah,sijil_dip,sej_julai,bm_julai,muet,mid1,yuran,umpa_bend1,umpa_bend2,bpkp,penaja,kesihatan,jhepa) VALUES ('$stdEmail','$fileName','$fileName1','$fileName2','$fileName3','$fileName4','$fileName5','$fileName6','$fileName7','$fileName8','$fileName9','$fileName10','$fileName11','$fileName12','$fileName13','$fileName14','$fileName15','$fileName16')"; }
Or something like that... I am not sure how to put this.. Anyway, I'll just get started with explaining my problem. I have an admin-page in which you can delete the comments given on blogs, using checkboxes and clicking on a button with the value 'verwijderenSubmit'. The deletion part works just fine, nothing wrong. However, I also want to be able to EDIT the comments with an other button called 'bewerkenSubmit', using the same checkboxes that I use for deletion. Selecting the right CID (CommentID) is no problem, because that works the same as the deletion-part, but selecting the right textarea to update into the database is the problem... I uploaded a file here with the whole code: http://dhost.info/ddfs/myproblem.html I escaped the textarea within with square brackets, because otherwise the whole textarea would screw up.. I also added <!-- RELEVANT CODE --> to select the parts that I need to change. Well, I hope you understand my problem and can help. I am working on a project where I want a select form to display information from a MySQL table. The select values will be different sports (basketball,baseball,hockey,football) and the display will be various players from those sports. I have set up so far two tables in MySQL. One is called 'sports' and contains two columns. Once called 'category_id' and that is the primary key and auto increments. The other column is 'sports' and contains the various sports I mentioned. For my select menu I created the following code. <?php #connect to MySQL $conn = @mysql_connect( "localhost","uname","pw") or die( "You did not successfully connect to the DB!" ); #select the specified database $rs = @mysql_SELECT_DB ("test", $conn ) or die ( "Error connecting to the database test!"); ?> <html> <head>Display MySQL</head> <body> <form name="form2" id="form2"action="" > <select name="categoryID"> <?php $sql = "SELECT category_id, sport FROM sports ". "ORDER BY sport"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['category_id']."\">".$row['sport']."</option>\n "; } ?> </select> </form> </body> </html> this works great. I also created another table called 'players' which contains the fields 'player_id' which is the primary key and auto increments, category_id' which is the foreign key for the sports table, sport, first_name, last_name. The code I am using the query and display the desired result is as follows <html> <head> <title>Get MySQL Data</title> </head> <body> <?php #connect to MySQL $conn = @mysql_connect( "localhost","uname","pw") or die( "Err:Db" ); #select the specified database $rs = @mysql_SELECT_DB ("test", $conn ) or die ( "Err:Db"); #create the query $sql ="SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.sport = 'Basketball'"; #execute the query $rs = mysql_query($sql,$conn); #write the data while( $row = mysql_fetch_array( $rs) ) { echo ("<table border='1'><tr><td>"); echo ("Caetegory ID: " . $row["category_id"] ); echo ("</td>"); echo ("<td>"); echo ( "Sport: " .$row["sport"]); echo ("</td>"); echo ("<td>"); echo ( "first_name: " .$row["first_name"]); echo ("</td>"); echo ("<td>"); echo ( "last_name: " .$row["last_name"]); echo ("</td>"); echo ("</tr></table>"); } ?> </body> </html> this also works fine. All I need to do is tie the two together so that when a particular sport is selected, the query will display below in a table. I know I need to change my WHERE clause to a variable. This is what I need help with. thanks if so how would they be used in a mysql query? Hi all, I want to make a script that identifies if an image JPG file exists. Would somthing like this work? <?php $file = "images/image.jpg"; if ($file > 0) { echo "file exists"; } else { echo "no file"; } ?> Hi.. So what i want to do is basicly to check if id XX exist in my database. How can this be done? Im thinking of something like: if(xx exist){do this} else{do this} Iv'e tried google etc before i posted here, but couldent really find anything where i found a soutable answer.. Hope someone can help! (: Hi all - I have a form that let's a user upload an image to their specified folder. The folder is determined by the "password" the user inputs. The "password" is really just the folder name on my server, so if "michael83" was entered as a password, the directory would be "images/uploaded/michael83". That works great now, thanks to a forum user, litebearer. Thanks again. Here's my second question: I'm working on a "history" page so that a user can input their "password" and view their upload history. The form works right now. If you enter a "password" (folder name) that exists, the code will spit out the contents / files. So, now I'm looking for two things: (1) if a user enters a "password" (folder name) that exists, but there are no files in the folder, "There are no files in the $dir directory." will be echoed; and (2) if a "password" (folder name) is entered that does NOT exist, "The directory $dir does not exist." will be echoed. Here's my code so far (minus the if statements I'm looking for): $dir = $_POST['password']; $path = "images/uploaded/". $dir; $dir_handle = @opendir($path); while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." ) continue; if(isset($_POST['Submit'])) $url = "http://www.mysite.com/". $path . "/" . $file; { echo "<a href=\"$url\">$url</a><br />"; }} closedir($dir_handle); As always, many thanks in advance for any help on this. Gud pm!! So i made this script to check if a username and password exist but it kinda fails me. It gives me a database connection error from my confirm_query() which means it returned false? so here's my code: Code: [Select] function check_if_exist($username, $password) { global $connection; $query = "SELECT username, hashed_password"; $query .= "FROM users "; $query .= "WHERE username = '$username' "; $query .= "AND hashed_password = '$password' "; $query .= " LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if(mysql_num_rows($result_set) == 1) { return true; } else { return false; } } my confirm_query(): Code: [Select] function confirm_query($result) { if(!$result) { die("Database connection failure ". mysql_error()); } } I have a another script to check if the email exist and it works perfectly, i dunno why this won't work properly.. maybe another simple mistake.. Any ideas or Violent reaction? Thanks! hi, im having trouble adding a get variable to a url if one already exists. eg current url = http://www.example.com/index.php?var1=something i want to be able to change this to new url = http://www.example.com/index.php?var1=something&var2=another even so i can have a few get variable there. I can add the first var through a form or link, but how would i add more through a link or through the header function? I am positivly stuck. Thanks Basically this gets a number from a table on my DB, and displays the content relevent to that number...the second part checks for that number and gets other information according to that number... what i want to do is make sure that the number from the first query exists in the table from the query, and if it doesn't print out and error saying "there is no information" or whatever.. anyone have an idea? hopefully this makes sense Code: [Select] <?php require_once('Connections/myConnect.php'); $detnum = $_GET['Details']; $detinfo = mysql_query("SELECT* FROM `Agency Stores - Table 1` WHERE F11=".$detnum); $det = mysql_fetch_array($detinfo); $salesnum = $det['F3']; $salesinfo = mysql_query("SELECT* FROM `By Agency Store _` WHERE store_store=".$salesnum); $sales = mysql_fetch_array($salesinfo); if(mysql_query("SELECT* FROM `By Agency Store _` WHERE store_store=".$salesnum)){ } ?> Does the concept of a "Namespace" exist in PHP? If so, how do you use them? This is a snippet from ASP.NET that made me ask this question... Quote <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> TomTees hi, im getting the error Quote Fatal error: Call to undefined function notification() in C:\xampp\htdocs\xampp\index.php on line 21 after including the functions.php file i wrote. It does include it but the data isnt being recognised from it. If i copy/paste the notification() function into index.php it works. Can someone tell me why so i can fix it? I have a field in a table named flights I hope to find a 1 line statement to bypass inserting a new row if $flight_no is already in the field flight_no btw flight_no is the primary key and won't allow a duplicate anyway but I want to avoid the error message this is what I tried but doesn't work if(SELECT * FROM flights WHERE flight_no !LIKE %$flight_no%) { |