Jessica
Staff Alumni-
Posts
8,968 -
Joined
-
Last visited
-
Days Won
41
Everything posted by Jessica
-
This is why it's bad to run queries in loops. You need to use a JOIN statement.
-
We don't know what you know, so it's kind of hard to answer that. There's XSRF attacks and Form manipulation which people don't often talk about. You also need to be sure you understand handling user input, hashing passwords, stuff like that. Don't forget to back up your data before letting anyone test it/use it.
-
That is still way messed up.
-
http://us.php.net/manual/en/control-structures.alternative-syntax.php http://us.php.net/manual/en/control-structures.if.php You're missing some punctuation. On most lines.
-
Add print '<pre>'; print_r($twitterInfo); What gets printed?
-
So to sum it up print_r($_COOKIE['Quota_avail_example.com']); // prints the cookie array print_r($domain); //prints example.com print_r($_COOKIE["Quota_avail_$domain"]); // empty? That's what you're saying?
-
Php: Keeping selection after submission in a for form data
Jessica replied to LoolKovsky's topic in PHP Coding Help
If you're using the code I posted, it's $_POST['color'][1]. Look at the php manual or google "multi dimensional array" -
That was my first thought too but he is doing it, it's in the else{} block. OP what is the output of it?
-
Php: Keeping selection after submission in a for form data
Jessica replied to LoolKovsky's topic in PHP Coding Help
What do you mean by after submission it doesn't keep the selection? If you post it and look at the HTML source, do you see any errors in there? Do you have error reporting turned on and set to E_ALL? Can you post your current code including the form and submit button? Edit: I went ahead and loaded it on my localhost. If you fix the <? to <?php depending on if you have short tags enabled, and add the semicolon on line 11....it works. It prints 4 rows not 5, but again that's your original code. This is what I ran on my localhost and it works perfectly. <form method="post"> <?php $colors = array(1=>'Black', 2=>'Red'); //Where does this data come from? for($i=1;$i<5;$i++){ $id = 'color_'.$i; echo '<p> <label for="'.$id.'">color line '.$i.'</label> <select id="'.$id.'" name="color['.$i.']">'; foreach($colors AS $color_key=>$color){ if(isset($_POST['color'][$i]) && $_POST['color'][$i]==$color_key){ $selected = 'selected="selected"'; }else{ $selected = ""; } echo "<option value=\"$color_key\"$selected>$color</option>"; } echo '</select></p>'; } ?> <input type="submit" name="submit" /> </form> -
PHP Beginner - Looking for some help with a Number Guessing Game
Jessica replied to Manwar's topic in PHP Coding Help
"the entire thing has turned into a mess." Then let's not even look at that code ok? First of all, don't use cookies for this, users can edit cookies. If you need it to persist between multiple browser sessions, use a DB. otherwise just use Sessions. This is not at all tested, and you'll have to add all your HTML formatting, but try this and see if it does what you are trying to do. <?php session_start(); $points = array(10,5,2); if(!isset($_SESSION['number'])){ $_SESSION['number'] = rand(1,99); $_SESSION['tries'] = 0; } if(isset($_POST['guess'])){ if($_SESSION['tries'] <= 3){ if($_POST['guess'] == $_SESSION['number']){ echo 'You win! '.$points[$_SESSION['tries']].' Points!'; }else{ echo 'You guessed wrong'; $_SESSION['tries']++; } }else{ echo 'Out of guesses'; } } if(isset($_POST['start_over'])){ unset($_SESSION['number']); unset($_SESSION['tries']); } echo 'You have '.(3-$_SESSION['tries']).' chances left!'; ?> <form method="post"> <input type="text" name="guess" /> <input type="submit" name="submit" value="Submit Guess" /> </form> <form method="post"> <input type="submit" name="start_over" value="Start Over" /> </form> -
If all you need is the number of comments on a post, use COUNT(). SELECT COUNT(comment_id) AS total_comments FROM comments WHERE post_id = x
-
Php: Keeping selection after submission in a for form data
Jessica replied to LoolKovsky's topic in PHP Coding Help
1. I said "not tested". I didn't run it, I reformatted it. 2. Find me an open tag in that code, please. 3. Add the other colors to the array at the top. As I put in the comments, where do they come from? 4. There ARE still loops. 5. You're the one who wrote 5 rows, not me. Use a variable then. 6. Don't be so stuck up. -
Php: Keeping selection after submission in a for form data
Jessica replied to LoolKovsky's topic in PHP Coding Help
I would also recommend instead of having the variables be $color1 through $color5, you use an array. I rewrote the code a little, this is sort of how I would do it. Not tested. <? $colors = array(1=>'Black', 2=>'Red'); //Where does this data come from? for($i=1;$i<5;$i++){ $id = 'color_'.$i; echo '<p> <label for="'.$id.'">color line '.$i.'</label> <select id="'.$id.'" name="color['.$i.']">'; foreach($colors AS $color_key=>$color){ if(isset($_POST['color'][$i]) && $_POST['color'][$i]==$color_key){ $selected = 'selected="selected"' }else{ $selected = ""; } echo "<option value=\"$color_key\"$selected>$color</option>"; } echo '</select></p>'; } ?> -
PHP MySQL, pop up box when a new row is inserted in mysql database?
Jessica replied to Lukeidiot's topic in Javascript Help
What code have you written? Are you using any JS libraries? You know it's AJAX cause you posted here, where are you stuck? -
Preformance of multiple designs in if...else statement
Jessica replied to MargateSteve's topic in PHP Coding Help
Agreed, that's what I was going for -
Preformance of multiple designs in if...else statement
Jessica replied to MargateSteve's topic in PHP Coding Help
*eyeroll* yeah the first couple of links are talking about something completely different. Whatever. If the default style is X and then every time a page is loaded javascript has to run to change it to Y, that isn't "preloading" content. If you use PHP it's much faster. -
*headdesk* in your post you said "I've got 3 variables (value, business_id, bus_id) that cycle through a foreach loop. Here are the results of one particular loop:" So clearly you have some code. Whatever is generating this data needs to be fixed.
-
Preformance of multiple designs in if...else statement
Jessica replied to MargateSteve's topic in PHP Coding Help
Can you show an example of how that would work that wouldn't cause the "flash of unstyled content" -
Preformance of multiple designs in if...else statement
Jessica replied to MargateSteve's topic in PHP Coding Help
So what you're saying is on every page load, javascript will have to check for a cookie, and then change the sheet. -
To answer the actual question, it's called a Query string. $name = $_GET['name']; You need to read about sanitizing user input if you're going to use it.
-
$keuze is clearly a PHP variable...and OP speaks another language as their primary. *shrug* Why don't you just take the first option out of the dropdown? If you insist on doing it that way, you'd do it like this: if($select == 'value'){ echo 'Error'; }
-
Preformance of multiple designs in if...else statement
Jessica replied to MargateSteve's topic in PHP Coding Help
Neither. When the user makes a selection: update the HTML/CSS and save that selection in a cookie using javascript. If the user changes pages, reloads, whatever, it's saved in the cookie, you're all set. How. When they load the page, HOW does the page know which style to use, based on a cookie? -
No, POST your CODE. We can't help if you don't show us what you're doing.
-
Preformance of multiple designs in if...else statement
Jessica replied to MargateSteve's topic in PHP Coding Help
So, when you save it in a cookie, are you then saying that on the next page load, you would load the page then use JS to change the sheet, or have PHP access the cookie to change the sheet?