-
Posts
2,965 -
Joined
-
Last visited
Everything posted by mikesta707
-
you want to create an HTML array of your variables. something like <td>Powell Cory</td> <td><INPUT name="stat1[]" type="text" size="1"></td> <td><INPUT name="stat2[]" type="text" size="1"></td> <td><INPUT name="stat3[]" type="text" size="1"></td> for each row, you probably want a hidden field to identify whose stat you are updating, like <input type="hidden" name="player[]" /> now when you go to the submit page, you could do something like foreach($_POST['player'] as $key => $player){ //every row has the same key in the post array, so the key for //the player name's will be the same key for his stats. so we can do $playerStat1 = $_POST['stat1'][$key];//and now we have the players stat1 //do the rest for the others $sql = "update etc etc etc"; $query = mysql_query($sql); //etc. }//end foreach
-
back to helping out OP... Like people have said, there is no real straight procedural to OOP conversion. It is more a different way of producing code. Like daniel said To explain this further, you posted a function called validate user. Now if your program was real life, that method would be part of a security system right? Now what else might go into a security system. A way of validating the information the user gives (so they don't just hack our security system). maybe a large burly man to "ban" them if they get uppity? That would be modeling a security system via objects. Now for a website, we may need to model many things. For example, there could be a user class, which stores all the users information (including session info) and that user class may interact with the security class to log in, or get to restricted areas. Now we have objects interacting with each other. There are many more aspects of OOP that I can't cover in this post, but that should give you an idea for how you can (note i said can, not should) implement OOP Now lets take a simple example. The security system for example. assuming you already know the syntax of classes and objects in PHP, lets create a simple class (for sake of ease, i'm just going to declare methods, and not write how they would be implemented. I'll leave the fun parts for you) class securityRobot9000 { //lets declare some methods that our security robot may have validateUser($username, $password){ }//log in a user? validateInput($input){ }//protect against SQL injections banUser($username){ }//ban a user checkAdmin($username){ }//check if a user is an admin //etc }//end class now How could we use this class? well assuming we already defined a user class, we could log them in like so //assuming $user and $login are populated with values from a form $r9k = new securityRobot9000; //check if user is correct if ($r9k->validateUser($username, $login)){ $user = new userClass($username); //do some session stuff } now how you implement these classes is really up to you, and with all programming languages, you have choices. You could pass this object through a session variable, instantiate the class with a session variable, etc. etc. First and foremost, I would read some tutorials, learn the syntax and rules of good use, and try a very simple implementation (a security class is probably a good start for a website) then build from there
-
use $_GET if a link was <a href="mypage.php?val=myvalue" ></a> you could access that get variable, like $val = $_GET['val']; echo $val;//myvalue
-
the global keyword tells the function to use the variable that is in global scope, rather than in local scope. for example, in a simple function function func() { $var = "Hello world!"; echo $var; } the variable $var only exists inside the function, and can only be accessed inside the function. It has what is known as a local scope (local to that particular function) However, variables used in your script(not inside functions or classes) have a global scope, for example $var1;//global scope $var2;//global scope function func(){ $var1;//local scope $var3;//local scope } Global basically means it can be used anywhere (well mostly any where) and local scope means it can only be used in its code block (the {}) note that the two variables that are not in the function have a global scope. Also note that the $var1 variable in the function has a local scope even though it has the same name as a variable with global scope. This is because when you simply declare a variable, by default, it will gain the scope of the part of the program it belongs to. if its in a function, it gains a local scope. if its in the body of the program itself, it has a global scope. If I want to use the global $var1 I have to specify that, by using the global keyword, as cags pointed out $var1 = "hello world"; function func() { global $var1; echo $var1;//hello world }
-
it seems that your form fields are empty. verify that your HTML form has the correct names, and that its action is set to the right page. do you have the code for the html form? also put your code in code or php tags
-
um, you use a submit button to do that. but it appears as if you already have to submit button. post your whole form's code, but im going to sleep soon so if you don't have this solved by tommorow I can take a look at it again
-
PHP - Expire page after it's loaded instantly
mikesta707 replied to Gamerz's topic in PHP Coding Help
if you want a simple form of flood protection, you could create a session, like so //after you do all the form stuff $_SESSION['formXYZ_sent'] = true; then simply check if they sent the form already if (isset($_SESSION['formXYZ_sent']) && $_SESSION['formXYZ_sent']){ //form stuff } else { echo "Information already recieved"; } -
well if it said "mail sent again" than the class thinks that it succeeded in sending the mail. have you checked your spam folder, and double checked your email address is correct
-
Hmm, ok well everything looks fine to me. what exactly happens when you try this. Blank page? try print_r-ing $_POST, and see if the values you expect to be in there are
-
i dont see any form tags. you have to wrap input and other form tags with <form></form> tags, like so <form method="post" > <label for="username" name="username">Username or email</label> <input id="username" name="username" value="" title="username" class="required" tabindex="4" type="text"> </p> <p> <label for="password" name="password">Password</label> <input id="password" name="password" value="" title="password" class="required" tabindex="5" type="password"> </p> <p class="clear"></p> <a href="change_password.php" class="forgot" id="resend_password_link">Forgot your password?</a> <p class="remember"> <input id="submit" value="Sign in" tabindex="6" name="submit" type="submit"> <input id="cancel_submit" value="Cancel" tabindex="7" type="button"> </form>
-
try doing a print_r on the $row array, and post what it says
-
can you post the actual code that you are using to write to the file?
-
if you don't want your program to stop executing at that spot, than remove the die();
-
if ($_SESSION['userLevel'] > 2) { echo "<li><a href=\"#\">TEST</a></li>"; die(); } ?> the problem was you were stopping the program via die the echo statement. die kills the program so the echo statement was never executed
-
as was mentioned, there are performance issues, as well as issues if you want to update more than one variable. to explain the performance may, so you have a huge data set that you want to pass into a function, and change. you have two choices, create a returning function that takes the data set as a parameter, or pass the data set by reference. Not only do you avoid making a copy of a huge data set (which if many people are doing, will severely slow down your server) but you don't have to return anything (a small point, I know) using pass by reference with arrays can really help save a lot of your servers processing power. also, if, say, you want to update multiple variables passed in, without pass by reference you would have to return an array, and use the list function. What happens if based on some criteria, the function only wants to change 2 variables, or 1, or 4. well with pass by reference you don't have to worry. with the return array->list function method, you do have to worry. but you really get a good appreciation of pass by reference if you were to code in, say, C/C++
-
notice on the code you posted you surrounded associative array keys with quotes (usually its single, but it doesn't matter much) when you don't have what should be a string enclosed with quotes, PHP thinks its a global variable. However, if no such global exists, it assumes its a string. what exactly happens when you run this page? no errors? any sql errors? anything at all? blank page? and you get resource id#3 because when you do a sql query, it returns a mysql resource. if you want to fetch the data that you returned you have to use one of the mysql_fetch_XXXX functions
-
there is no sql query on that page. if you want to post data to the database, do something like $sql = "INSERT into post (title, author, content, date) VALUES('$title', '$author', '$content', NOW())"; $query = mysql_query($sql); //etc etc the NOW() part is assuming you have one of the mysql date formats as your date field type. if you have a varchar field type (which I suggest you dont) you can use the date function for your specified format and insert that
-
try using preg_replace Im not very good with regex, but here is an example $pattern = '#\<head\>(.+?)\<\/head\>#s'; $replace = "content to replace" $file = get_file_contents("myfile.html"); preg_replace($pattern, $replace, $file); //then write to the file down here that pattern may be slightly off, but you get the idea
-
im not quite sure what you want. Do you want a google search bar, with your own custom search page? if so thats the google API. If you want it so that when users search google, the results some how magically appear on your site, I doubt thats possible, and if it is, It is probably beyond the scope of these forums. can you explain more clearly what you want
-
[SOLVED] Usine SESSION to transfer a variable; short question
mikesta707 replied to physaux's topic in PHP Coding Help
session_destroy simply destroys all data that is registered to your sessions. If that is your intent, than you need it there. If not, then you don't. Beyond that, the script looks fine -
looks fine to me. but you may want to try <br /> thats more or less the valid way to do it, since the line break tag is self closing (in XHTML) so the browser may be freaking out about that
-
Why not try a simpler class problem? maybe a log in class, or a class for handling sql query data?
-
I would do an htmlentities on the text between no html tags
-
Remove from cart help!! (removing stuff from a session)
mikesta707 replied to jayskates's topic in PHP Coding Help
unset($_SESSION['purchases']['Purchase to Remove']); ? -
.. you aren't choosing tables.. you are choosing columns. I suggest you read up on SQL before you try to do this, because you don't seem to understand the most basic of queries. i found this tutorial very good when i first learned Tizag