PHP - Setting Up An Array
I am trying to separate this information by the "-" symbol so that I can insert it.
This output would be ideal. Any help today? 105-2-2-3-Cheerleading $value[0] should = 105 $value[1] should= 2 $value[2] should= 2 $value[3] should= 3 $value[4] should= Cheerleading I have tried many approaches and come up with notta 105-Athletics 105-1-Eagle Sports 105-2-Programs 105-2-1-Boys 105-2-1-1-Football 105-2-1-2-Cross Country 105-2-1-3-Golf 105-2-1-4-Basketball 105-2-1-5-Baseball 105-2-1-6-Track 105-2-1-7-Tennis 105-2-2-Girls 105-2-2-1-Volleyball 105-2-2-2-Golf 105-2-2-3-Cheerleading 105-2-2-4-Basketball 105-2-2-5-Softball 105-2-2-6-Track 105-2-2-7-Tennis 105-3-Coaches 105-4-FHSAA 105-5-Game Directions Thank you for looking. Similar Tutorialsi have checkboxes in a form with the name="array[]" and in the php i use the implode function to separate all the values of all that was checked with a comma....my question is... how can i set the order of the array a certain way... i'd like to ultimately have a field where if you check a box you can enter into the field 1, 2, 3, 4 and so on and when you submit the form it will set the order according to what was entered thanks I'm somewhat new to OOP PHP, and I'm still learning, but basically I want searchcolumns() to set which MySQL columns that it'll search inside but I don't know where to go from what I've already coded. Here's the basic input to be sent to my classes file: $getusers = new database; $getusers->search($_GET['search']); $getusers->searchcolumns('username','account','email'); And to put it simple, I need my $where variable to output this: $where .= "(username LIKE '%$search%' OR account LIKE '%$search%' OR email LIKE '%$search%')"; Except replacing the already set columns with the ones that I assigned in the searchcolumns() array, and then adding an OR string if there's more than 1 column set. Here's the code as I have it at the moment, for obvious reasons, it doesn't work how I want it to: // Search columns function searchcolumns($columns) { $this->column = explode(", ", $columns); } // Search results function search($search) { $search = ($_POST['search']); if (isset($_GET['search']) && strlen($_POST['search']) > 1) { $searchresult = explode(" ", $search); $where = "WHERE"; foreach ($searchresult as $key => $search) { $where .= "($this->column LIKE '%$search%')"; if ($key != (sizeof($searchresult) - 1)) $where .= " AND "; } $this->where = $where; } } Sorry if this has been somewhat confusing to explain, but hopefully someone understands what I'm trying to achieve. There's probably an obvious reason but I can't seem to find it... I start with the $_POST array, received from a form: Code: [Select] array(9) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" ["button"]=> string(38) "updateColumnName=EnvironmentID;Value=1" } I get the button value from the array, and unset the button array value. Code: [Select] function load_POST($name) { //returns value and removes it from $_POST array. returns NULL if not existing. $debug = 0; if ( $debug == 1 ) { $backtrace = backtrace(); echo __FUNCTION__."()"; echo " <i>called by ".basename($backtrace[1]['file'])."</i><br/>\n"; } $post = NULL; if( array_key_exists($name, $_POST) ) { $post = urldecode($_POST[$name]); if ( $debug == 1 ) { echo "post $name, value: $post<br/>\n"; } } else { if ( $debug == 1 ) { echo "post $name: doesn't exist<br/>\n"; } } unset($_POST[$name]); return $post; } $_POST is now: Code: [Select] array(8) { ["Name"]=> string(3) "KTN" ["SQLServer"]=> string(24) "10.6.11.20\VSQLI028,1433" ["Username"]=> string(2) "GF" ["Password"]=> string(2) "GF" ["MasterDB"]=> string(11) "GFMaster_KN" ["Version"]=> string(3) "4.9" ["Prod"]=> string(1) "1" ["Monitored"]=> string(1) "0" } Then I create the object to assign the values to: Code: [Select] object(Environment)#1 (9) { ["EnvironmentID"]=> NULL ["Name"]=> NULL ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) } So far so good Then, for each remaining $_POST value, I update the Object accordingly: First one, parametername: Name, parameter: KTN Code: [Select] object(Environment)#1 (10) { ["EnvironmentID"]=> NULL ["Name"]=> string(3) "KTN" ["SQLServer"]=> NULL ["Username"]=> NULL ["Password"]=> NULL ["MasterDB"]=> NULL ["Version"]=> NULL ["Prod"]=> int(0) ["Monitored"]=> int(0) ["ColumnName=EnvironmentID;Value=1"]=> object(stdClass)#3 (1) { ["ColumnName"]=> string(1) "1" } } And there we have the problem, for some reason the button value is added to the object somehow... Any ideas? Thanks in advance! I made a website in PHP mvc framework. Now I want to remove "public" keyword from URL. I tried by removing require "../app/init.php"; these dots and bringing htaccess & index.php file in root directory. But it doesn't work. I searched on google but didn't find anything. Here is my index page code: Quote
<?php require "../app/init.php"; $app = new App();
and my htaccess code: Quote RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f Please give me a solution to it. Thank you can anyone tell me why $username is not setting properly? the password is, but $username is no. it is setting as blank: Code: [Select] if ($_POST['go']) { //Connect to the database through our include if ($_POST['logid'] == ";5757120050531338739=49121200000?"){ $username="oldcheney"; $username = stripslashes($username); $username = strip_tags($username); $username= strtolower($username); $username = mysql_real_escape_string($username); $password="password";} else if($_POST['logid']==";5757120050531338721=49121200000?"){ $username="yankeehill"; $password="password";} else if($_POST['logid']=="%6277202936423578^00000000^X?"){ $username="holdrege"; $password="password";} $password = md5($password); Is it posible?! I'm sure it can be done. Description of the problem's frame: A server , multiple nic's with IPa , IPb, IPc. The problem : More than one PHP scripts running in the same time ,but ... I use scriptA I want it to use NICa with IPa to connect somewhere. Then I also want scriptB to connect to the same place but from another IP. I don't want to use proxies or other stuff. Just want to use a specific network card. In C it is posible to choose one. Thank you for your time. v=$("#txtusername"); $.post('../actions/check.php',{user:v.val().toLowerCase()},function(d){ if(d=='available'){ $("#usernamemessage").html("<span style='color:green;'>Username is available</span>"); }else if(d=='not-available'){ $( "#txtusername" ).effect( "shake" ); $('#txtusername').css('border', 'solid 2px blue'); var iserror = '1' alert(iserror); } }); alert(iserror);The first alert displays '1', however, the second displays 'undefined'. Why is this? Thanks Well this isn't all about cookies or maybe it is, I'm not to sure. On top of this my script has suddenly broke and stops at check.php I'm also not sure how I should go about checking the cookie to identify the user and how to keep other from viewing the output page(s). Code: (index.html) [Select] <html> <head> <title>Deadnode.com</title> <style type="text/css"> img { position:absolute; left:300px; top:130px; z-index:-1; } form { position:absolute; left:365px; top:248px; z-index:0; } </style> </head> <body> <img src="iL0bw.png" /> <form method="post" action="check.php"> <center><table> <tr><td><font face="verdana,arial" size=-1>Username:</td><td><input type="text" size="25" name="user"></td> <tr><td><font face="verdana,arial" size=-1>Password:</td><td><input type="password" size="25" name="pwd"></td> <tr><td><font face="verdana,arial" size=-1> </td><td><font face="verdana,arial" size=-1><input type="submit" value="Login"></td></tr> </table></center> </form> </body> </html> Code: (function.php) [Select] <?php function check() { $admin="test"; $pass="test"; if (isset($_POST["user"]) && $_POST["user"] == $admin && isset($_POST["pwd"]) && $_POST["pwd"] == $pass) { header('Location: output.php'); setcookie("usr", "test", time()+3600); else { header('Location: index.html'); } } ?> Code: (check.php) [Select] <?php require('function.php'); check(); ?> Code: (output.php) [Select] <?php require('check.php'); ?> <html> <body> <p>Congrats!</p> </body> </html> Hi, I'm trying to set cookie but all in vain. I've already posted my php code in my last post. "COOKIE PROBLEM". I think there is nothing wrong with code. may be i need to enable to load some library or something in xampp. Is there anyone who knows what setting do i need to do for enable cookies and in which file? Please help hello, ok if i set a Global on index.php (wwwroot/admin/index.php) it works Code: [Select] $page1='hello from page1 on index'; global $page1; echo $page1; i can echo $page1 on other pages like (wwwroot/admin/pages/home.php) and it will echo out "hello from page1 on index". GREAT but if i write a Global on (wwwroot/admin/pages/home.php) it does not work. i also can not echo it out on any other page Code: [Select] $page2='hello from page2 on home'; global $page2; echo $page2; why is this ??? hi i wants to disable open_base_dir for my folder /home/admin/mysite.com/myfolder/ so in myfolder script i could use CURLOPT_FOLLOWLOCATION I can disable open_base_dir in my kloxo panel but i would like to use it this way, I modified my php.ini file and set this path open_basedir = /home/admin/mysite.com/folder/ but still i get error while using CURLOPT_FOLLOWLOCATION Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in Please any help on how to disable that in /myfolder.? using Centos 5 Thanks I have created my lottery script. At the moment i simply have the time() function being used where the draw will happen. Im wondering if your able to get rid of that and just choose a particular time where i want the draw to happen. I want the draw to be done at 4pm everyday. (in GMT) Is this possible? and what would the right code be for it. I've been working on this for the last few hours and haven't had much luck. Basically, every time you visit the index of my site a random image is shown. The images are stored in a directory, and i use a table to hold the id, name, and url of each image. When the index page is loaded a random int is chosen, and the id equal to the int prints the corresponding url for the image. Now i'm trying to add the id into the url, "domain.com?img=1". I also need this url to always refer to the image in row 1. My table is called uploaded_images and the columns are id(primary key), name, url. I'm pretty lost, any help is greatly appreciated. Hello, My latest issue is with a login page I am trying to set a cookie for. I have deduced that it it pulling my info out of my database correctly. It does not give any errors for username or password when they are entered correctly but when I get to the end of the script where I would like to set a cookie and redirect to a new page it just stays on the same page and appears as if it is loading but nothing happens. After I stop the browser and attempt to reload the page it gives me an error saying the page cannot be displayed. Do I need to specify anything before I can have the following code work or is it that it is clashing somewhere else along the way? Code: [Select] <?php else { // if login good set cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: http://example.com/"); die(); } ?> If I remove this code and simply leave the redirect as shown above, it works. But that defeats the purpose of the script as on the redirected page there has to be a cookie set to display it. Any help would be appreciated HI all i have the following code: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); if (session_status() == PHP_SESSION_NONE) { session_start(); } if (!isset($_SESSION['user_name'])){ header("location: index.php"); } mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); include '../_includes/dbconn.php'; if($_SERVER['REQUEST_METHOD']=='POST'){ if(isset($_POST['delete-equipment-button'])){ $eid = $_POST['EM-id']; $stmt = $conn->prepare(" SELECT a.equipment_id, b.equipment_name from ssm_equipment_order a inner join ssm_equipment b on a.equipment_id = b.equipment_id where a.equipment_id = ? "); $stmt->bind_param('i', $eid); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($eid, $eqname); $stmt->fetch(); $instances = $stmt->num_rows; $_SESSION['eqname']="$eqname"; if($instances>0){ $_SESSION['updateEquipment']="is being used in an active order and cannot be deleted"; header("location: ../equipment-list.php"); }else{ $_SESSION['updateEquipment']="has been successfully deleted"; $stmt = $conn->prepare(" DELETE FROM ssm_equipment WHERE equipment_id = ? "); $stmt->bind_param('i', $eid); $stmt->execute(); var_dump($_SESSION); // header("location: ../equipment-list.php"); } } } ?> The session variable eqname gets set properly when the delete fails (the first half of my if). When i get to the else, the session does not set a value. I assumed that it was because the item whose name i am trying to get is being deleted but i thought this would happen after i have set the session variable and therefore be preserved for when i get back to the equipment list? As always, i appreciate your help. I am trying to make a login using cookies, I had been using sessions but i need to use cookies for it now. I have a page called login.php, and i use ajax to login. It seems to be setting the cookie and printing the value of it out when i login, however that's about it. When i'm reading the cookie on other pages it doesn't appear to recognize a cookie. However, If i set the cookie on just a regular index page it has no problem with setting it and reading it. it works fine when i do that. This is how i set the cookie on the login page (also the exact code i used to test setting it on the index page): $expire=time()+60*60*24*30; setcookie("id", $dbid, $expire); $session = $_COOKIE['id']; then to read it on other pages i just use: $session = $_COOKIE['id']; Hi I was wondering how I could set up a time mod to set time 3 times per hour. DROP TABLE IF EXISTS og_updateattacks; CREATE TABLE og_updateattacks ( lasttime int(20) default NULL, id int(11) NOT NULL auto_increment, PRIMARY KEY (id) ) TYPE=MyISAM; That is what I got, but I want it so users can attack at random times per hour. ok, I run a samp server that has mysql and i'm creating a website to register on the server, Ok, I got it so you can set your charcter age (it's a role play server) but i need help with setting fighting styles, The gamemode uses pawno scirpt lang and the values i use to set each fighting style is 5,6,15 and 26. I have it set it a drop down menu, I want to convert this code so it shows certian names and when you select those certian names it sets the value for that name Here is the code for my age but i want set to like i said above </select> <tr> <td><b>Age:</b></td> <td><select name="age"> <option value="---">Fighting Style</option> '; for ($i=18;$i<99;$i++) { $metai = date('Y') - $i; echo '<option value="'. $i .'">'. $i .' (' .$metai. ')</option> '; } echo ' </select> Instead of it outputting the Age and the Year i want it to Output those values i mention before and the style Example These are in the drop down menu Kung_Fu (6) Elbow (26) Boxing (5) Kick Boxing (6) When you select it, It writes to the database Hi, In < PHP7.3, is it possible to set the session.cookie_samesite to "none' and secure to do away with the warning messages of chrome ? Thanks.
hi i have set up my1 st member area (www.sittonjewelryshop.com). everything works fine except of 1 thing with the checkuser and the verify php files. i have set it up that if some one is trying to go directly to the member area without register it wont let him and send him to the login area but for some reasson it doesnt work. if you write www.sittonjewelryshop.com/member/login_success.php it takes you directly to the membera area. was trying to manipulate verify.php and register.php but could find the problem. any suggestion? tnx. |