Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Everything posted by wildteen88

  1. I've not modified that part of the code. However I believe it should be: echo file_get_contents("./templates/register.html");
  2. Course that code wont work as expected. You are using variables before you have defined them! <?php $msg3 = 'no'; if (isset($_POST['submit'])) { $msg3 = 'yes'; if ($_POST['user'] == ""){$msg1 = "please enter a your name";$msg3="no";} if ($_POST['last'] == ""){$msg2 = "please enter a your last name";$msg3="no";} } $form_block = "<form action=\"$_SERVER[php_SELF]\" method=\"post\"> name :<input type=\"text\" name=\"user\" />".$msg1."<br /> last :<input type=\"text\" name=\"last\" />".$msg2."<br /> <input type=\"submit\" value=\"check!\" /> </form>"; ?> <html> <body> <?php if ($msg3 == "no") echo $form_block; else echo "submitted"; ?> </body> </html> Reorganised your code.
  3. mysql_error is mispelt on this line: $con = mysql_connect("localhost","root","orange") or die(msql_error()); change msql_error to mysql_error Do you still get a blank page? If you do then this makes me believe that the mysql extension is not enabled and thus when you use mysql_connect or any other mysql_* function your code dies. In order to confirm this create a new script called info.php with the following code: <?php phpinfo(); ?> Run info.php you should get a page full of info about PHP setup. Scroll down the page and look for a main heading called mysql. If you can't find a mysql heading then the mysql extension is not loaded and thus your code will not work. You will need to enable the mysql extension within the php.ini in order for your code to work. There is an FAQ here for enabling that extension however that is for Windows. If you are using *nix/Mac then you'll need to recompile PHP with the --with-mysql=[path/to/mysql/here] command.
  4. Those if statements would be better of being a switch/case also did a few fixes in your code. $x = 1; $results = null; while ($getQuery = mysql_fetch_array($query)) { $findUser = fetch("SELECT * FROM members2 WHERE id = '{$getQuery['userid']}'"); switch($findUser['rank']) { case '0': $color = 'red'; $text = 'Suspended'; break; case '1': $color = 'red'; $text = 'Logged In - No Rank'; break; case '2': $color = 'red'; $text = 'Under 13'; break; case '3': $color = 'red'; $text = 'Regular User'; break; default: $color = 'green'; $text = 'Staff'; break; } $rank = '<font color="' . $color . '">' . $text . '</font>'; $results .= "$x. {$findUser['username']} - {$getQuery['ip_addr']} - $rank<br>"; $x++; } print "<p>$x results found.</p><p>$results</p>";
  5. You'll have to remove the try/catch statement then and use basic if/else statements instead: <?php /* Has user submitted data? If not, display the registration form. */ if (! isset($_POST['submitbutton'])) { echo file_get_contents("/templates/register.html"); /* Form data has been submitted. */ } else { $conn = mysql_pconnect("localhost", "corpweb", "secret"); mysql_select_db("mygame"); /* Ensure that the password and password verifier match. */ if ($_POST['pswd'] != $_POST['pswdagain']) { echo "<p>The passwords do not match. Please go back and try again.</p>"; /* Passwords match, attempt to inster information into userauth table. */ } else { // never use raw _POST data within a query. Always escape user input. // I suggest using mysql_real_escape_string to help prevent SQL Injection attacks. $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $query = 'INSERT INTO userauth (commonname, email, username, pswd) '; $query .= "VALUES ('$name', '$email', '$username','" . md5($_POST['pswd']) . "'"; $result = mysql_query($query) or die('Registration problems were encountered!'); echo "<p>Registration was sucessful!</p>"; } } ?> That code should work as expected. Note I added a bit of extra code to help prevent SQL Injection attacks.
  6. Umm strange! Could you attach your httpd.conf here
  7. What version of PHP do you have installed? I see you're using try/catch statements these are only available with PHP5. PHP4 does not support these. Also line 34 should be: echo "<p>Registration was sucessful!</p>"; You forgot the " at the end of the line to close the string.
  8. You'll have to return $username from the formresults(); function. Functions have their own variable scope.
  9. By incorporate do you mean merge the two pieces of code together? If thats the case then try: function get_numbers($file) // this function builds the $numbers array { $contents = file($file); foreach($contents as $line_value) { list($cat, $int, $id, $num) = explode("\t", $line_value); $cat = str_replace('#', '', $cat); $number[$cat][$int][$id] = trim($num); } return $numbers; } function calculate_range($source_file, $cat, $bool, $range_min, $range_max) { $numbers = get_numbers($source_file); // get the numbers from a source file $total = 0; for($i = $range_min; $i <= $range_max; $i++) { if(isset($number[$cat][$bool][$i])) { $total += $number[$cat][$bool][$i]; } } return $total; } $file = $_FILES['userfile']['name']; // the source file $total = calculate_range($file, 'UB', -1, 1600, 1650); // calculate the range All I've done is added an extra parameter for the calculate_range function which will be used to pass the source file. This parameter will be passed over to the get_numbers function which will generate the numbers array.
  10. We're actually using Mysql I do believe. This site and the rest of freaks network is owned by the owner of serverpowered.com and webhostfreaks.com
  11. Because variables act differently when used within functions. If you create a variable outside of a function, then that function will not be able to access variables outside of it and vice versa. In order to use a variable within a function that has been created outside of it you have two options: - Either define the variable as global within the function - Or pass that variable as a parameter to the function In order to understand this more you'll need to read up on variable scope
  12. Check Apaches error log. All errors that cause a 500 Internal error messages are logged within the error log. NOTE: Look at the bottom of the error log for the most recent error.
  13. There are many posts discussing which is the best editor to use for PHP (This thread is one of them) As for running your PHP scripts you need to install a http server configured with PHP. The most popular free http server is Apache and you can get PHP from php.net If you are new to installing and setting up http servers with PHP then there are many pre-configured packages out there. I'd recommend WAMP for windows, or XAMPP for *nix or MAMP for Mac Before using any of the packages above make sure you read the documentation that comes with it in order to now where to place your PHP script in order to run them.
  14. Ahh I see... You'll want to use $test1 = $_POST[$arrayvalue[$i]]
  15. Use unset eg: unset($array['key_name_here']) EDITE Orio beat me
  16. Where does $arrayvalue[$i] get set/come from?
  17. Correct
  18. The following line is an in-line if/else statement (most commonly called a ternary operator): $array = ( isset($_SESSION['somename']) && is_array($_SESSION['somename']) ) ? $_SESSION['somename'] : array(); Converted into a normal if/else statement: if( isset($_SESSION['somename']) && is_array($_SESSION['somename']) ) { $array = $_SESSION['somename']; } else { $array = array(); }
  19. CSS would be better a option. Most browsers nowadays support CSS pseudo classes for links. Visit this site for learning how to create CSS menus. Javascript is so "old-school" for doing hover effects.
  20. Hold on... I didn't read your script fully and now I understand what you are trying to do. You'll want to change the following two lines: $array = array(); $array = $_SESSION["somename"]; to: $array = ( isset($_SESSION['somename']) && is_array($_SESSION['somename']) ) ? $_SESSION['somename'] : array(); EDIT: @snk PHP automaticaly serializes session data. No need to serialize/unserialize arrays being stored within a session.
  21. Ohh... I do not have any experience with Linux so I cant really help you sorry. Perhaps another member will be able to help you more.
  22. Does $_SESSION["somename"] actually contain an array? If it is PHP should not be outputting that error. In the following bit of code: $array = array(); $array = $_SESSION["somename"]; You setup a variable called $array as an array data type, however on the next line your assign it the value of the $_SESSION["somename"] variable. Now if that variable does not contain an array PHP will change $array's datatype to a string. WHich will result in the in_array function returning the above error message
  23. PHP will still function fine if no php.ini is found. It'll resort to a default configuration. If you are using Apache (version 2.0.x or above) you can add the following directive the httpd.conf: PHPIniDir "C:/php" change C:/php to where you have installed PHP to. Now go to PHP's installation folder and and find a file called php.ini-recommended rename this file to php.ini . Save your httpd.conf and restart Apache. Rerun phpinfo and you should see PHP is now reading the php.ini located in PHP's installation folder. NOTE: I always recommend adding PHP to the Windows PATH variable. In doing so can help to keep problems to a minimum as you don't need to keep moving php library files around the file system, you can keep them all in one place. To learn how to add PHP to the PATH please read this PHP FAQ
  24. How are you passing your array of data to the next page? The best way to pass temporary data easily and efficiently without using a database is sessions. Then once your script has processed all the data and there is no errors you can insert it in the the database at the final stage.
  25. You should use $_POST['tagit'] not $_POST[$tagit] $tagit will only work if a setting called register_globals is enabled within the php.ini. register_globals has been disabled by default when PHP is installed, as it can cause a security exploits within your code. You can enable this setting if you wish however it is not recommended to. This is why your website site works fine however your local dev website (Win XP2) doesn't.
×
×
  • 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.