
DaveyK
Members-
Posts
289 -
Joined
-
Last visited
-
Days Won
1
Everything posted by DaveyK
-
You realize that select has an option to allow multiple options at the same time? Its not that pretty, but it works. Look here: http://www.w3schools.com/tags/att_select_multiple.asp BTW, still countr 5 <p> tags and only 4 </p> tags Did that help? It if definitely possible without that "multiple" attribute, but its your call.
-
var_dump(date('l', strtotime('20 Dec, 2011'))); // "Friday" Or, what Psycho said.
-
Well, even though I dont really understand, start here: 1) All your code should be in code tags. [code]YOUR CODE[/code] 2) All you logic should be above your HTML. Right now you are not consistent. <?php session_start(); if (isset($_POST['submit'])) { chosenItems(); } $_SESSION['counter'] = (!$_SESSION['counter']) ? 0 : $_SESSION['counter']; if($_POST['add']) { $_SESSION['submit']++; } function chosenItems() { $foodSelected[$counter]= $_REQUEST["foodType"]; echo "food added: ", "<BR>"; print_r($foodSelected); } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Calorie Counter</title> </head> <body> <p>It's Breakfast </p> <p> <form action="" method="post"> <p> <select name="foodType" id="foodType"> <option selected="selected">Labneh</option> <option>Cucumber</option> <option>Tomato</option> <option>Lettuce</option> <option>Cucumber Pickles</option> <option>Olive Oil</option> <option>Cucumber without peal</option> <option>Olive Black</option> <option>Olive Green</option> </select> <input name="submit" type="submit" id="submit" value="add"> </p> </p> </form> </body> </html> Thats a START. Its still far from done. 3) Third, you have two if statements on the _POST. One for "submit" and another for "add". The "add" will NEVER run, as the name for the submit button is "submit" and not "add" (the value is add, but thats just for the users). One might argue if its even smart to put a conditional on the submit. You can also check if $_POST["foodType"] is empty or not and go from there. 4) Not as important, but your HTML nesting is faulty. <p> <form action="" method="post"> <p> ........... </p> </p> </form> 5) I STRONGLY urge you to use value attributes for HTML <option> tags <option value="<SOME_VALUE>">SOME_NAME</option> This is the part that PHP reads (the "value"). 6) In the function, you are reading $_REQUEST. Why dont you just pass it as a value?! function chosenItems($foodType) { $foodSelected[$counter]= $foodType; echo "food added: ", "<BR>"; print_r($foodSelected); } Also, $counter will an undefined index error since it doesnt exist anywhere. That covers the general part of your script. Now what do you actually wish to achieve?
-
But what about my idea about storing it normalized, use a SQL view for fetching and perhaps cache it to a file to be refreshed every once in a while... ?
-
Okay I know this thread is no longer actively discussed, but some thought hit me. What if you keep everything perfectly normalized like I suggested, but create a SQL view and fetch from that view? I have never used SQLs views before but it just seems usefull to keep everything normalized if you want to translate things on the go (or even let users vote on translations).
-
Backbone.js can do this. It basically keeps the user from loading new pages but rather refreshes parts of the page using AJAX. But even with normal JS you can go a long way. Dont use iframes.
-
That appears to work. Thanks again Requinix (and again, and again!)
-
Hey Freakers, I have an issue in my htaccess again... To better explain, I have attached two screenshot. The first is how it is SUPPOSED to look like (localhost) and the second is from the server. As I said, the first is how it supposed to look like. It is a screen of the blogpost. The second, however, displays the screen from the blog "homepage" (so the page that shows all the blog posts rather than that single one.) You may see it for yourself at http://trekeffect.com/developers-blog, then click the blog title link and the page will refresh, but nothig will change. I started tracing the problem and it appears to be in the htaccess, but the htaccess on the server and localhost are identical. The way I found out is to var_dump $_GET in php. Localhost will show an array with the id and title, while the server array is (shockingly) empty. Here is the htaccess I am using on the server: <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On </IfModule> RewriteCond %{HTTP_HOST} ^www.trekeffect.com$ [NC] RewriteRule ^(.*)$ http://trekeffect.com/$1 [R=301,L,S=4] # If requested resource exists as a file or directory, skip next three rules RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR] RewriteCond %{DOCUMENT_ROOT}/$1 -d RewriteRule (.*) - [S=3] # Blog articles. TEST TEST RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?developers-blog/([^/]+)/(\d+)/(\d+)$ developers-blog.php?title=$1&id=$2&reply_to=$3 [L,S=1] RewriteRule ^/?developers-blog/([^/]+)/(\d+)$ developers-blog.php?title=$1&id=$2 [L] # Remove the .php extension RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] RewriteRule (.*)\.xml(.*) $1.php$2 [nocase] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ app.php?tag=$1 [QSA,L] # ---------------------------------------------------------------------- # Custom 404 page # ---------------------------------------------------------------------- # You can add custom pages to handle 500 or 403 pretty easily, if you like. ErrorDocument 403 /error.php?type=403 ErrorDocument 404 /error.php?type=404 ErrorDocument 500 /error.php?type=500 The fact that files who are (supposedly) exactly the same would give different results is puzzling me. Any idea what is going on? Thanks!
-
As you said, its YOUR problem.
-
What have you tried so far to achieve your goal ?
-
Its not likely that anyone is going to download or even read your files. You should extract the relevant code, put it in code blocks and point in the right direction as to what you need and what you've tried so far.
-
maybe constants arent supposed to end with _ ?
-
What would you want that? What is the value to the user that it says .html instaed of .php, or even remove the extension altogether...
-
He is already using that. The only thing you can do is ban all the IPs and email addresses. If he doesnt use a bot, and he just wants to troll and be annoying, he will just keep on registering untill you ban him. At this point, I dont think theres much else you can do.
-
Do you have error reporting turned on? If not, turn it on.
-
Select Option box to display data from table
DaveyK replied to josephbupe's topic in PHP Coding Help
so you fill the array with the content from a table using SQL -
Okay, I get that. But what function would you use to validate the char set and string length? Also, I dont think htmlentities(nl2br()) should be in that order, because you will create <br /> tags and then create htmlentities of the tags...
-
Please put your code in [ code ] [ /code ] tags... Also, I have no idea why you are trying to write JS in PHP in JS here <script type="text/javascript"> var jvalue = form1.code1.value; <?php $abc = "<script>document.write(jvalue)</script>"?> </script> Why dont you use Ajax?
-
Help update database from while loop
DaveyK replied to I WanT To Code PHP's topic in PHP Coding Help
Ofc that works, but I dont think running a query on every single ID doesnt seem very efficient. Look into this http://www.karlrixon.co.uk/writing/update-multiple-rows-with-different-values-and-a-single-sql-query/ -
I am trying to write a function that will do all the string validation on my project. I am doing this so that I can validate a charset and string length in one place, which makes it easier to maintain for me on the long run. Someone told me to do it like: $var = mysql_real_escape_string(trim(nl2br(htmlentities($var)))); if (strlen($var) < 3 || strlen($var) > 400) { // do something } That is roughly how I used to do it. A Freaker (not sure who) told me this is wrong and that I should use htmlentities() (and probably also nl2br()) only before displaying the strings. So here I am, confused and not knowing how I should be validating strings prior to adding them to the DB.The situation I want to go to (I THINK) is something like... $var = mysql_real_escape_string(trim($var)); if (!validate_string($var)) { // do something } As I said, I dont know if thats correct or not. How do you Freakers do it? What is "best practise"? Ideally, I would just want to have UTF-8 valid strings in my DB, but I have very very little experience with this. ALSO: I know Im not supposed to be using MySQL, but converting is not an option at this point. Please leave that be
-
I misread the question, sorry!
-
You dont technically have to run a login function, because you can fake your session. $_SESSION['user_id'] = 2 // user_id of the user you want to log in as. You have to place that somewhere in your header (like a header.php file if you have one). Also, keep in mind that above code will log in ALL the users and guests to that specific user, so it would be wise to use: if ($_SESSION['user_id'] == 1) // If you are logged in, guessing that YOUR id is "1" { $_SESSION['user_id'] = 2 // user_id of the user you want to log in as. } So if you are logged in (ID = 1), change the session user_id to 2. Voila
-
Wait what?!
- 18 replies
-
- configuration
- php
-
(and 2 more)
Tagged with:
-
cant you do that in PHP and just perform a redirect?
-
I see your points, and I agree. As I said, I never actually built it so I just went with a guess. But if you serialize your data inside the table you will lose the functionality... and "Gebruikersnaam" is Dutch (NL), not German (DE).