Jump to content

jcbones

Staff Alumni
  • Posts

    2,653
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by jcbones

  1. FPDF would help you.
  2. Databases is separate from PHP. There are lots of different databases, but PHP can interact with most all of them. SQL is a type of database. databases explained
  3. I cannot reproduce that error, the link works for me. Are you using the code as is, or did you change it?
  4. You need to encode the string before sending it to simpleXML. The question mark (?) is what is causing it to barf. I would suggest the work around. //instead of: $xml->addchild('element',$str); //do $xml->element = $str;
  5. I'm guessing this is what you were after. <?php @include "greenarray.php"; //suppressed error, because I didn't have the file; //variable setting #defaults $rows = 7; $cols = 10; $highlight = 5; //reset variables if they are in the GET array. $rows = (!empty($_GET['rows'])) ? $_GET['rows'] : $rows; $cols = (!empty($_GET['cols'])) ? $_GET['cols'] : $cols; $highlight = (!empty($_GET['highlight'])) ? $_GET['highlight'] : $highlight; //reset variables if they are i the POST array. $rows = (!empty($_POST['rows'])) ? $_POST['rows'] : $rows; $cols = (!empty($_POST['cols'])) ? $_POST['cols'] : $cols; $highlight = (!empty($_POST['highlight'])) ? $_POST['highlight'] : $highlight; ?> <html> <head> <style> body {background-color:salmon} table { border: 1px solid black; margin-right: auto; margin-left: auto;} table tr.odd, span.odd {background-color:#99CC99} table tr.even, span.even {background-color:#CCFFCC} table td {padding:5; } table td.five {background-color:#990000; color:#FFFFFF } div#form { margin-right: auto; margin-left: auto; width: 300px; text-align:center; background-color: #CCCCCC;} div#container {border: 5px ridge #990000; margin: auto auto; width: 600px; background-color:white;text-align: center} h1 {color: #CCCCCC;} a {color:#006} a:hover {text-decoration:none} </style> </head> <body> <div id="container"> <h1>Modified Table Generator</h1> <p ><a href="table.php">Generate Table using default values.</a></p> <p ><a href="?rows=<?php echo $rows . '&cols=' . $cols . '&highlight=' . $highlight; //builds a GET query string?>"> Generate Table with GET: table.php?rows=<?php echo $rows . '&cols=' . $cols . '&highlight=' . $highlight; //prints a GET query string?> </a></p> <div style=";"> <div id="form"> <form name="form1" method="post" action=""> rows <select name="rows"> <option value="5" <?php echo ($rows == 5) ? 'selected' : NULL; ?>>5</option> <option value="6" <?php echo ($rows == 6) ? 'selected' : NULL; ?>>6</option> <option value="7" <?php echo ($rows == 7) ? 'selected' : NULL; ?>> 7 </option> <option value="8" <?php echo ($rows == ? 'selected' : NULL; ?>>8</option> <option value="9" <?php echo ($rows == 9) ? 'selected' : NULL; ?>> 9</option> <option value="10" <?php echo ($rows == 10) ? 'selected' : NULL; ?>>10</option> </select> cols <select name="cols"> <option value="5" <?php echo ($cols == 5) ? 'selected' : NULL; ?>>5</option> <option value="6" <?php echo ($cols == 6) ? 'selected' : NULL; ?>>6</option> <option value="7" <?php echo ($cols == 7) ? 'selected' : NULL; ?>>7</option> <option value="8" <?php echo ($cols == ? 'selected' : NULL; ?>>8</option> <option value="9" <?php echo ($cols == 9) ? 'selected' : NULL; ?>>9</option> <option value="10" <?php echo ($cols == 10) ? 'selected' : NULL; ?>>10</option> </select> highlight <select name="highlight"> <option value="5" <?php echo ($highlight == 5) ? 'selected' : NULL; ?>>5</option> <option value="6" <?php echo ($highlight == 6) ? 'selected' : NULL; ?>>6</option> <option value="7" <?php echo ($highlight == 7) ? 'selected' : NULL; ?>>7</option> <option value="8" <?php echo ($highlight == ? 'selected' : NULL; ?>>8</option> <option value="9" <?php echo ($highlight == 9) ? 'selected' : NULL; ?>>9</option> <option value="10" <?php echo ($highlight == 10) ? 'selected' : NULL; ?>>10</option> </select> <br><input type="submit" name="Submit" value="Generate Table with Post using these values"> </form> </div> </div> <?php $randomnumber = rand(0,100); //get random number; if ($randomnumber % 2 == 0) { $rowclass = "odd"; //if number is even, set the row class to odd. echo "<center>First number is an <span class=\"even\"> even</span> number</center>"; } else { $rowclass = "even"; //if number is odd, set the row class to even. echo "<center>First number is an <span class=\"odd\"> odd</span> number</center>"; } echo "<table>"; //start table. for ($row = 0; $row < $rows; $row++) //if the row number is less than the rows wanted, continue the loop. { $rowclass = ($rowclass == 'even') ? 'odd' : 'even'; //if the row class is even, set it to odd, if it is odd, set it to even. echo "<tr class=\"{$rowclass}\">\n"; for ($col = 0; $col < $cols; $col++) //if the col number is less than the cols wanted, continue the loop. { $columnclass = ($col + 1 == $highlight) ? "class=five" : ""; //if the col number + 1 (since we are always a number behind) is equal to the highlight wanted, set the class. echo "<td $columnclass>$randomnumber</td>\n"; $randomnumber++; //increment number. } echo "</tr>\n"; //end of row. } echo "</table>\n"; //end of table. ?> </p> </body> </html>
  6. I wasn't sure exactly how the flow of the script was suppose to operate. I did notice a lot of redundancy, so I re-wrote portions, trying to keep the output the same. <?php //echo '<pre>' . print_r($_POST,true) . '</pre>'; //debugging?> <?php $WORDS = array("grape","apple","orange","banana","plum","grapefruit"); //add or take away as many as you like; define ("GUESSINDEX",3); //define the desired word, count starts at 0. define("THEWORD",$WORDS[GUESSINDEX]); //defines the actual word. $count = (isset($_POST['count'])) ? (int)$_POST['count'] : 0; //keep count of how many times the form is submitted WRONG. $all_guesses = (isset($_POST['allTheGuesses'])) ? $_POST['allTheGuesses'] : NULL; //our guesses. $message = 'It\'s time to play the guessing game! (1)'; //if POST isn't the request method, this will be our message. if($_SERVER['REQUEST_METHOD'] == 'POST') { if($_POST['myguess'] == THEWORD) { $message = 'You guessed ' . THEWORD . ' and that\'s CORRECT!!! (3)'; //if the answer is correct. } else { ++$count; //if the answer is incorrect, increment the count. $all_guesses .= '|' . $_POST['myguess']; //add the guess to our wrong list. if(empty($_POST['myguess'])) { $message = 'C\'mon, guess something (2)'; //if the guess is emtpy. } elseif(!in_array($_POST['myguess'], $WORDS)) { $message = 'Hey, thats not even a valid guess. Try again (5)'; //if the guess doesn't exist in the array. } else { $message = "Sorry {$_POST['myguess']} is wrong. Try again (4)"; //if the guess is just wrong. } } } ?> <html> <style type="text/css"> body {background-color:orange} div {margin:10px} div#container {background-color: white; border: 3px solid black;width: 400px;margin-right: auto;margin-left: auto; text-align:center;} div#error {color:red} div#guesses,div#header p span {color:green; } h1,h2,h3 {color:#633} </style> <body> <div id="container"> <div id="header"> <p><?php echo implode(' | ',$WORDS); //automatically write out the word list, if you add more to the array, it will show up.?></p> <h1>Word Guess</h1> <a href="?">refresh this page</a> </div> <div id="form"> <h3>Guess the word I'm thinking</h3> <form name="form1" method="post" action="<?php //do not use PHP SELF, XSS vulnerability?>" > <input name="myguess" type="text" value="<?php echo (isset($_POST['myguess'])) ? $_POST['myguess'] : NULL; ?>"> <input type="hidden" name="allTheGuesses" value = "<?php echo $all_guesses; ?>"> <input type="hidden" name="count" value="<?php echo $count; ?>"> <input type="submit" value="GUESS"> </form> </div> <div id="error"> <?php echo $message; ?> </div> <div id="guesses"> <center> <?php $arr = (!empty($all_guesses)) ? explode('|',ltrim($all_guesses,'|')) : 'string'; echo (is_array($arr)) ? "{$count} wrong guesses:<ol>\n<li>" . implode("</li>\n<li>",$arr) . "</li>\n</ol>": NULL; ?> </center> </div> </div> </body> </html>
  7. Do not use PHP_SELF as the form action.
  8. $_SERVER This will just tell if the server was sent a GET or a POST request. It is usually used like: <?php if($_SERVER['REQUEST_METHOD'] == 'post') { //Do }
  9. <input type="hidden" name="allTheGuesses" value = "<? echo $_POST['allTheGuesses'] . '|' . $_POST['myguess']; ?>"> You should add sanitation and validation to all data received.
  10. Why can't you scrape the links, and then use those to continue?
  11. An include that has a relative file path, will be relative to the file calling the include (which would be the script that you call, ie. index.php). The greatest way to include a file is with an absolute file path. That will eliminate relative file path problems. I do this with a Constant in my main Config file. Once you get in the habit, all of your relative woes will be behind you. <?php define('INCLUDES_ABSOLUTE_PATH','home/absolute/path/to/includes'); include INCLUDES_ABSOLUTE_PATH . '/required_file.php'; Now, if you move your files, you only have to change it in one location. The config file.
  12. Going out on a limb here. else { $trys++; $this->letters .= $this->bruteForce($base, $state, $trys); }
  13. Not in it's written form. It isn't a CURLOPT, but a CURLINFO. CURLINFO_HEADER_OUT TRUE to track the handle's request string. Available since PHP 5.1.3. The CURLINFO_ prefix is intentional.
  14. Your question is pretty ambiguous. As in, no one really understands the question. <?php $lines = file("upload/" . $_FILES["file"]["name"]); echo '<pre>'; for($i = 0; $i < $lineCount; $i++) { if(empty($lines[$i])) { continue; } $parts = explode(',',$lines[$i]); echo str_replace('"','',$parts[2]) . ' | ' . str_replace('"','',$parts[4]) . ' | ' . str_replace(array('"','!'),'',$parts[5]) . ' | ' . $parts[6] . ' | ' . $parts[7] . "\n"; } echo '</pre>'; In it's simplest form.
  15. If an extended class has no constructor, then the constructor of the parent is used automatically. Removing the __construct() function from your extended class, you could still pass the arguments, and they would be used in the parent::__construct() automatically. Example <?php class me { function __construct($me) { echo $me . '<br />'; } } class you extends me { } new you('Jcbones'); ?> Thereby, as Nightslyr posted, you don't have the extra datamember that just points back to itself. Here is another great OOP tutorial.
  16. Pagination This should help you. Feel free to use it in any way if you need to. You are welcome.
  17. So that would mean that: if($filesCount[$i] != null) { Should be: if($files[$i] != null) { Right?
  18. I would also suggest getting rid of repetitive coding, it makes it easier to read, and less headache to de-bug. function frm_lostpass($email) { if(isset($_GET['check']) and trim($_GET['check'])=='ok') { //your checks. $sql_check ="SELECT m.Password AS numrows FROM tbl_member AS m WHERE m.Email = '$email'"; //need only 1 database check, if it returns a password, then it is correct for this email. You should be generating a new password instead of retrieving one, but that is another subject. $result = mysql_query($sql_check) or trigger_error('ERROR: ' . mysql_error() . '<br />Run the following string in your MySQL console: <br />' . $sql_check); //if the databse errors, you will get a notice on your screen. if(mysql_num_rows($result) != 1) //if the rows returned are less or more than 1, then tell them the email isn't found. You could add checks for more than 1, but you shouldn't have that problem anyway, as you should check that on signup. { return "<center>Email not found !</center>"; //returns the message and ends the function execution. } else //else continue with the email. { $rows = mysql_fetch_assoc($result); //get the result. // keep password in $your_password $your_password=$rows['Password']; // ---------------- SEND MAIL FORM ---------------- // send e-mail to ... $to=$email; //use the email that was sent to the function, it was found in the database, so it should be good. // Your subject $subject="Your password here"; // From $header="example@example.com"; // Your message $messages= "Your password for login to our website \r\n"; $messages.="Your password is $your_password \r\n"; $messages.="more message... \r\n"; // send email if(mail($to,$subject,$messages,$header)) { //if mail was sent to the SMTP server, tell the user it was sent. return "  Your Password Has Been Sent To Your Email Address."; //return the string, and end script execution. } return "  Cannot send password to your e-mail address"; //if the script gets this far, return the string and end execution. } } return '  Form submitted improperly.'; //If the checks are not in place, the form will not be processed. } Hope this helps in clarification.
  19. Wow, at the globals batman. There are lots of functions in your script, that I do not know what they return. There are also lots of different variables, and while PHP can handle them quite well, the end_user(you) can sometimes run into a problem of "forgetting what the variable is". So, try to keep you variables to a minimum to avoid this problem. // send e-mail to ... $to=$email_to; There is no "email_to" variable. There is an email variable.
  20. There is actually 3. echo "some string $array[key]". //without quotes around the key
  21. You would keep the total of their uploads. So, when they uploaded something new, you add it to the previous amount, and when the delete something you ... There is no need to know the number of files they have, unless you are going to limit that also. To calculate the files a user already has, just pass them to the filesize() function, and keep a running total.
  22. I'm with Buddski on this one. There are things you should think about though. 1. Do you want to keep an archive of the old data? 2. How often does this information change? 3. How easy is it going to be to add functionality to the page?
  23. jcbones

    oop php

    Start here
  24. \n is a newline character. It will only create a new line in a text editor, or the page source code. Browsers ignore them, that is why you must use the break rule <br />.
  25. For the mod-rewrite, I'm not 100% sure if it is required for this script. That is just a suggestion to look into. For the database, goto the website's database console, or phpMyAdmin, and export the database. Import it to your development database (easyPHP has phpMyAdmin, just click the import button at the top.). You should already have a default user (root) for MySQL (no password, unless you specified during installation).
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.