-
Posts
1,216 -
Joined
-
Last visited
Everything posted by WebStyles
-
get info from URL and set as a javascript variable
WebStyles replied to jarvis's topic in PHP Coding Help
if you do something like this: <div id="divname">someValue</div> then you can grab the value into javascript with something like var text1 = document.getElementById("divname").innerHTML; or you can use hidden form elements and grab the elements value from javascript. So in short, yes, it's possible to get a php value into javascript, but you need to make sure the value is set and placed in a place where you can access it from js before your javascript code runs. -
notice how there's a slash missing between paranormal and form. * ignore that. my bad. I read paranormal/form.
-
Since your $_GET['page'] variable has the same name as the files, here's a little variation that will handle any page name: <?php $page = isset($_GET['page']) && $_GET['page'] != '' ? $_GET['page'] : 'home'; include_once($page.'.php'); ?>
-
Sending error message back to user who omitted fields in login form
WebStyles replied to mrherman's topic in PHP Coding Help
$_POST is only available when you submit a form. you need to put the variables in $_SESSION, that will make them available on every page, as long as you add session_start(); to the beginning of every page, before any output. Hope this helps, -
How to make this a variable in my form script
WebStyles replied to chrisidas's topic in PHP Coding Help
hang on... if you're using the hidden field, you do not need to store the value in a SESSION variable.... if you've already got the hidden field, just grab it's value with $_POST['hiddenFieldName'] or $_REQUEST['hiddenFieldName'] -
How to make this a variable in my form script
WebStyles replied to chrisidas's topic in PHP Coding Help
you could just use: $_SESSION['playerName'] = $row['playername']; again: you pages need to have session_start(); at the beginning tor the session variable to work. Also, I'm assuming there will be only 1 player name (as opposed to many different names) since the query is based on a playerID. then on any other page, you can get it with: <?php session_start(); echo $_SESSION['playerName']; ?> -
How to make this a variable in my form script
WebStyles replied to chrisidas's topic in PHP Coding Help
as long as you have session_start(); at the beginning of your pages, you can use $_SESSION to store values, like: $_SESSION['myVarName'] = 'My first session test'; hope this helps -
ok, I'll clarify this for everyone to be happy: @olinroger The code I posted allows you to build a query_string based on the options selected in the form and it will echo the results, so that you can tweak it to your likings, check the results, and when you're happy with them you can implement it into your code and actually pull out the data from your database with mysql_fetch_assoc or mysql_fetch_array. Please notice I used backticks for the table and field names, this seems to annoy other programmers, so I suggest you google it and figure out if you should use them or not. I also did not account for the fact that people might perform an empty search, since that was not the question and I have no idea how you're posting the fields. (i.e. if you're doing it with ajax, maybe you're already checking if it's a valid search or not before it even reaches this part) Hope it was helpful.
-
How to make this a variable in my form script
WebStyles replied to chrisidas's topic in PHP Coding Help
use a hidden input field in your form with the player name as value, of dump the player name into a $_SESSION variable so you can grab it on the next page. -
@EdwinPaul My code is OBVIOUSLY not complete, it's an example of how olinroger can construct a query_string with the options he needs. (which was the initial question). The rest of the code is up to him, as I am here to try and help and point them in a direction where they can solve their problem, and not do everyone's homework for them. (The use of back ticks or not is irrelevant here, and also a personal preference. You say it's dis-advised, I disagree.)
-
Getting no errors, but the query isn't pulling the data
WebStyles replied to Clandestinex337's topic in PHP Coding Help
I'm thinking that your code sequence... $id = '0' ... $this->id = $id; ... if($this->$id !== 0) this will prevent it from executing. also, if `id` in your database is a key/autoincrement 0 is not a valid number. -
want to show a message on the same (form) page.
WebStyles replied to nadeem14375's topic in PHP Coding Help
If you want to check it on the same page, you point your form to $_SERVER['PHP_SELF'] or manually put in the page's name (you can even leave it blank) and check if the form was submitted with something like: if(isset($_POST) && !empty($_POST)){ ... do form checking here, set error if necessary, or redirect to some other page }else{ just show form and error if it was set. } alternatively, you can just include the form-checking script if $_POST is not empty. hope this helps -
<?php $query = "select * from `addresses` where "; if( isset($_REQUEST['street']) && trim($_REQUEST['street'] != '') ){ $query .= "`street` like '%".$_REQUEST['street']."%'"; $addAnd = 1; } if( isset($_REQUEST['city']) && trim($_REQUEST['city'] != '') ){ if(isset($addAnd) && $addAnd == 1) $query .= ' and '; $query .= "`city` LIKE '%".$_REQUEST['city']."%'"; $addAnd = 1; } if( isset($_REQUEST['state']) && trim($_REQUEST['state'] != '') ){ if(isset($addAnd) && $addAnd == 1) $query .= ' and '; $query .= "`state` LIKE '%".$_REQUEST['state']."%'"; $addAnd = 1; } if( isset($_REQUEST['zip']) && trim($_REQUEST['zip'] != '') ){ if(isset($addAnd) && $addAnd == 1) $query .= ' and '; $query .= "`zip` LIKE '%".$_REQUEST['zip']."%'"; } $query .= ' order by `street`,`city` limit 50'; echo $query; ?>
-
Man, I have no idea what you're asking... from what I understand, you only call the headers in some files, but you want the page title to be visible in all of them, is this correct? Then you answered it yourself: include headers in all pages.
-
PHP_SELF will return the page's name, not the full domain name. (I'm guessing you have several domains pointing to the same place, and you want to send each one to the correct folder?) try something like: <?php $serverName = $_SERVER['SERVER_NAME']; header("Location: /".$serverName."/"); ?>
-
I don't really understand what you're asking... sounds like a simple condition: if($varX=='specialPage'){ include_once('specialSidebar'); }else{ include_once('normalSidebar'); }
-
well, yes, if that's the condition you want, if($count > 0 && $isScore == 1){ $checked = 'checked = "checked"'; }else{ $checked = ""; } (BTW, Why does $_GET['pid'] become $prodID if it's called courseID in the database? You basically have 3 different names for the same value, that makes your code harder to read and could easily lead to mistakes.) Something to try: try this little exercise: do a simple database query, grabbing just one row (with limit 1), use mysql_fetch_array and print_r() to view the results. then do the same but use mysql_fetch_assoc instead of mysql_fetch_array. Compare both results. Cool huh? I almost never use mysql_fetch_array. also: while($result = mysql_fetch_assoc($query)){ //... do something } will only work while there are rows being pulled out. if the query returns empty, the code in the while loop will never be executed. With this in mind, what is the point of always doing mysql_num_rows($query) before each database call? you're basically querying the database twice every time. The best way to do things is to adjust your code to the 'most likely event'... meaning: if it's most likely that your database will be empty, you can check it first. Otherwise don't bother, since most of the times it won't be necessary.
-
$_SESSION is used for many other reasons, not just for logins. it's useful to store data while processing, to move data from page to page, etc.. But yes, a cookie (as long as the user has the browser set to remember cookies) will store you login info for longer (depending on the cookie timeout you define). I, personally, do not like cookies. Not only because they depend on browser settings that I cannot control but also because I consider them a security issue, mainly because you cannot trust users to protect their data. I work at a financial servicing company, and out of our 400 employees, about 250 will never remember to lock their computer when they leave... See how serious a cookie can become? Anyone passing by will have access to their accounts, intranet, email, possibly other passwords stored in email... Of course a session has the same issues, but if you control the timeout, you're only vulnerable for about 15 minutes (that's the inactivity time I normally set). Also, with sessions, a text file is created on your server, so you can easily kill any user's session (force logout), whenever you want just by deleting the correct session file.
-
if the array has all those values, why are you doing a query in the middle of the loop to find out the price? try something as simple as this: <?php $cartCount = 0; $cartCost = 0; foreach($_SESSION['cart'] as $id => $value) { if($id=='quantity') $cartCount += $value; if($id=='amount') $cartCost += $value; } ?>
-
If you do not put session_start() at the top of your pages, you will not have access to $_SESSION, no matter how long the sessions last.
-
In simple terms, by adding session_start(); at the top of each page, you have access to using the $_SESSION variable. These variables will exist until: a) your game/application/page destroys them (with session_destroy() ) or b) until browser is closed. or c) until the session time limit in your main configuration is reached so imagine you simply add session_start() to the top of all your pages (including the page where you have your login script) during a successful login, at the end write: $_SESSION['loggedIn'] = 1; //(or whatever names/values you want) then on each page, just check that variable <?php session_start(); if( !isset($_SESSION['loggedIn']) || $_SESSION['loggedIn'] != 1 ){ // user is lot loged in, redirect, show message, etc... exit(); }
-
help with a few array's warning long code****
WebStyles replied to YoungNate_Black_coder's topic in PHP Coding Help
I cannot even begin to picture what a 'ball python breeding game' might be. You say you're done 60% of this, with genetics, physics, etc... but you have no idea how to check if an array contains a certain value? how about in_array(); Even though I have no idea what you're actually asking. -
help !! Undefined variable: option in on line 19
WebStyles replied to pidiw's topic in PHP Coding Help
Debug that? Man, that code is a mess, and it's not even complete. Function tableLoop seems to have no closing }. then you do things like: $qualified = false; ... if($qualified == true) { if ($row['status']=='bad'){ that is never going to run, because you manually set $qualified to false 1 line before you check it. Also: always declare functions before you call them. and this: if($_SESSION['user']==1){ $option='edit'; }else if($_SESSION['user'] == 2){ $option='approve/deny'; } what happens if $_SESSION['user'] is empty or does not exist ? and this: At the beginning you count the number of results, then you send all the variables into tableLoop... and in table loop you decide to check $count. ... but... even if $count is 0, you still try to do this: while($row = mysql_fetch_array($result)) very messy. Try doing a little flowchart of what you want your code to do, so you can organize it in your head first. -
you can do it with preg_match, although I'm not very good at that, so here's a simple suggestion: assuming you have a variable named $newsArticle that contains the entire article: // split it where the </p> is $parts = explode("</p>",$newsArticle); // grab the wanted part and discard the rest. It will be index 0 since it's the first paragraph $wantedPart = $parts[0]; unset($parts); // remove the <p> tag from the start: $finalText = str_replace("<p>","",$wantedPart); Kind of an old-fashioned way to do it, but it should work. Hope this helps
-
I didn't really read through your code, but from the short description this sounds more like a z-index CSS problem, and not php.