-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
can you post where you create the array that is giving you trouble
-
is there anything in your database?
-
It seems like your query is failing. Try changing your query line to $query = mysql_query("select * from listtest order by id asc") or die(mysql_error()); and post if there is an error (and what the error is) Note: or die() is never good to use in production. its ok for debugging purposes only.
-
In addition to howlin's example, you can also accomplish what you want with the following: simply use exit to stop executing once you find an error. For example, your if statement for phone validation would become if (validatePhone($phone)) { echo $phone . ' is a valid phone number.'; } else { echo $phone . ' is not valid phone number.'; //not valid so exit exit("Email not sent"); } you would obviously have to change your other validation if statements in a similar manner. Some do not like this method, as if you exit execution at this point, other parts of the page will not load (including scripts you may need somewhere below this point. So you can simply set a flag variable to true or false depending on the error. The change to your if statements would be similar. $errors = false;//no errors. put this at top of page ... .. if (validatePhone($phone)) { echo $phone . ' is a valid phone number.'; } else { echo $phone . ' is not valid phone number.'; $errors = true;//there was an error. set the flag } ... make same change for rest of validation functions if (!$errors){//if theres no errors mail (... your arguments here ...); } .. rest of script Hope this helps
-
Also, you seem to be using static data members, with a variable that conceptually shouldn't be static. Since (I assume) different instances of a page class will have different page layouts, the variable holding that information shouldn't be static (as that implies it never changes, and that each instance of the page class should just share 1) However, as Xyph mentioned, without seeing how your classes are structured, it will be hard to give you a direction on how the relationship between the two classes should work.
-
Data entered into fields isn't showing on the email,
mikesta707 replied to jaydoh73's topic in PHP Coding Help
1 thing i noticed, is you are missing the double quotes around your name attributes, namely <input style="WIDTH: 52px; HEIGHT: 22px" maxlength="2" size=6 name=Age> Another is that you are using the names t1, t2, etc. as array keys for the $_POST super global, but the keys you need to be using correspond to the name attribute of the input. for example, if you wanted to access the Favorite Game Type input box, you would use $_POST['Game_Type'] not $_POST['t1'] or t2 or whatever EDIT: howlin posted the second thing I said, but the first is also something you should consider -
Sometimes mail sent via the built in smtp protocol in PHP has some problems. Make sure of a few things A.)Your SMTP server is actually up and running B.)You check your spam folder and such C.)Your email address/info is correct D.)Your header information is formed correctly. D is especially important as some email providers dont allow emails with malformed headers
-
Try turning error reporting on to see if that page produces any PHP errors by sticking the following at the very top of the page error_reporting(E_ALL); ini_set('error_reporting', E_ALL);
-
You only have 1 row because you overwrite the value of $alderaanfleetalt in every iteration of the loop. You may want to concatenate instead of overwriting $alderaanfleetalt = "";//set it to empty string do{ $alderaanfleetalt .= $fleetname." ".$row_Alderaanfleet['FleetName']."</br>".$shipname." ".$row_Alderaanfleet['ShipName'];//concatenate each row onto the whole variable } while ($row_Alderaanfleet = mysql_fetch_assoc($Alderaanfleet));
-
$this is reserved for use inside classes. I don't see the whole script that that snippet was a part of, but seeing you use $this when you have HTML near its use tells me you may be using $this incorrectly. Are there any errors on the page? Can you post more of the code surrounding that snippet?
-
Question: Will the table example you showed always be of those dimensions (IE the quantity and description inner arrays will always have 3 elements) or could the table look different depending on the array (who's size and format may be different every time the script runs)?
-
well serialize will work on non-simple php variables (like arrays, which $_POST['row'] now is) so serialize($_POST['row']) should still "work." You just have to make sure you treat the data returned from the database as an array once you unserialize it.
-
well what criteria are you using for deciding what color to use? Whatever it is, changing to font color is simple enough. You can change the font color of an html element by using the color style as part of the style html tag attribute. So for example, if I wanted to change the color of a p tag to yellow or something, I would write <p style="color:yellow">some text blah blah</p> I don't know how your html is set up, or what criteria the database information must meet to be a certain color, but the above may get you started. If you could post a few more details I can help further
-
Data entered into fields isn't showing on the email,
mikesta707 replied to jaydoh73's topic in PHP Coding Help
try doing a print_r on $_POST to see what its contents are. afterwards, if the contents arent right check your form to make sure its being submitted properly, and the field names match. -
function removeAt($array, $search){ $keys = array();//keys to remove foreach($array as $key=>$a){ if (strpos($array, $search)!== false){ //if we find the search term in the value, we set it for removal $keys[] = $key; } } foreach($keys as $k){ array_splice($array, $key);//remove the elements from the array } }//end removeAt //usage: $array = array(... some stuff ...); $array = removeAt($array, "review"); here you go. Please note that this uses a simple string match. If you want more comprehensive matching, you may want to use a regular expression match rather than the str_pos !== false method
-
If you are curious as to why your version didn't work, check out this manual page: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double In short, double quotes "interpolate" the inner string, which means instead of the literal string, you get the string with any variables replaced by their values
-
Not true. Having posts send GET data instead of POST data is just as valid. POST has some added benefits that makes it common with forms, but saying forms should always send POST data is incorrect
-
well you want to make sure when registering someone usually that the information isn't conflicting with information in the database. This is generally done with unique identifiers of the account (username, or email address for example). You would simply check to make sure there isn't a row with username (or email, or whatever) equal to the username entered in the post data before inserting into the database. This has the added benefit of refusing someone from registering if they use a taken username.
-
Yes and no. You are duplicating user_ids, but otherwise, doing a search on such a large table with a bunch of columns will make your queries less efficient. Giving up a little bit of space (the amount of which is negligible unless you are storing a huge amount of information) is usually worth the increase in efficiency. If you want to keep all the info in 1 table, thats fine I guess. It won't change the underlying logic much regardless. I was under the assumption that you stored more information on users than just the 4 columns you listed in your OP for some reason, so in your case it really doesn't matter too much. The only problem I would see is your are storing users with guests (or are users/guests the same? is there a registration process?) for total users in the last 15 minutes would be the same logic for finding guests in the last 15 minutes except you dont user the column that specifies whether they are a user or a guest (assuming the two are different)
-
If you want to do this efficiently you should use multiple tables. If you try to cram all the information you need in 1 table, traversing it will become a nightmare. Now, lets take your problem step by step. Total number of users is easy. Its simply the count of the number of registered users in your database. You can use the mysql COUNT() function or phps mysql_num_rows function to get this number. For total logged in, and guests within last 15 minutes, i would have a seperate table for all the people currently logged in. This would contain an ip address column, as well as a column for username (or better, user id) with blank being a guest, and a timestamp of the last page activity. Every time someone visits a page, you look at their IP, and if it isn't in the logged in table, they are added. The total count of this table is the total amount of users (guests and registered) For guests, you can easily construct a query using the last page activity timestamp, and the user_id column (it should be blank, or equal to "", or perhaps -1. whatever makes the most sense to you). Of course, you would then need to figure out a way of automatically taking people off of that table (perhaps after 30 minutes of inactivity you remove them from the table.)
-
The selected attribute's value doesn't matter, and it seems like you assume it does here: <select name="gender" id="gender"> <option value="" selected="<?php if (!isset($gender)) {echo "selected";} ;?>">Select</option> <option value="male" selected="<?php if ($gender == "male") {echo "selected";} else {echo "";} ;?>">Male</option> <option value="female" selected="<?php if ($gender == "female") {echo "selected";} else {echo "";} ;?>">Female</option> </select> However, even if you do selected="false" or selected="NOT SELECTED" or anything, the attribute is still there and thus your mark it to be selected. When you have multiple things marked for selection, the first tag you have is the one selected. Perhaps you should try <select name="gender" id="gender"> <option value="" <?php if (!isset($gender)) {echo "selected='selected'";} ;?>>Select</option> <option value="male" <?php if ($gender == "male") {echo "selected='selected'";} else {echo "";} ;?>>Male</option> <option value="female" <?php if ($gender == "female") {echo "selected='selected'";} else {echo "";} ;?>>Female</option> </select> this ensures that only the previously selected option has the selected attribute
-
I'm not sure how this changes what I suggested
-
The way sessions work is PHP gives the user a session cookie, and stores that particular sessions data on the server. Every time a page is loaded, (assuming you used session start) the browser sends this session cookie, and the server uses that value to determine what information that user has stored in session data. That data is used to populate the $_SESSION super global array. You will realize this after you clear your cookies, and then get logged off of each site you were previously logged into! Variables on the other hand have a maximum scope of global to the script. They can't "travel" to other scripts the same way $_SESSION values seem to. However, when you include a page, variables from the page that is included will be available in the page that included it after the include statement. so for example #page1 $v = "a"; #page2 include "page1.php"; echo $v;//echos: a yes, assuming you use session_start to grab the relevant session data. yes.
-
No, a switch statement is not required to have a default case. As far as your second question goes, why not just set your first case as the default case. You could then remove the original first case and he switch statement would be the same