Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Posts posted by wildteen88

  1. For some reason strange reason this allways redirects me to the login form called main_login.php

    I cant see how as the code you posted does not contain anything that will cause this. The only redirect checklogin.php has is to login_success.php

  2. You don't position the text using PHP. You use html/css for this. Example HTML/CSS code for floats

    <div class="float-container">
      <div class="left">text on the left side</div>
      <div class="right">text on right side</div>
    </div>

     

    And the CSS

    .float-container {
        width: 100%;
        overflow: auto;
    }
        
    .left {
        float: left;
    }
        
    .right {
        float: right;
    }

  3. But if i need to change a value thats been already added. i mean existing value. what should i do ?

    Rather than use a simple string replacement

    $contents = str_replace($oldline, $newline, $contents);

     

    You can do a more complex string replacement using regular expressions. This line should make changes to existing values

    $contents = preg_replace('~\$'.$letter.' =.+?;~s', $newline, $contents);

  4. Thank you very much but coders usually have a reason for asking something

    I was just assuming you was going to be using mt_rand to select a random row from your table latter on in your script. That why I mentioned you can select random rows from within your query it self.

     

     

    I need to know the last rows id that is in a table

    To get the last row you use a query like this

    SELECT id FROM `business` ORDER BY id DESC LIMIT 1

    that query will get the last row from the business table

     

    and then put that last rows id into the second field of mt_rand.

    Something like this should work

    $result =  mysql_query("SELECT id FROM `business` ORDER BY id DESC LIMIT 1");
    list($last_row_id) = mysql_fetch_row($result);
    $rand = mt_rand(0, $last_row_id);

  5. Are you trying to select a random row from your database. You can do this within your query

    SELECT * FROM table ORDER BY rand() LIMIT 1

    The above query will select one random row from the table. Change Limit 1 to the number of random rows you want the query to return.

  6. So that if i just change those codes and the form code should remain same ?

    Yes replace your php code with the php code I posted. You do not need to change your form.

     

    and another question is if already my $a=1; value given can it edit that ?

    No, it will not replace the variables that already have a value. It will only change lines like $a = ; to $a = 'value from form field a';

  7. Because your code is overwriting your files contents with

    $string = '<?php  
    
    $a = "'. $_POST["a"]. '" . "\n"; 
    
    $b = "'. $_POST["b"]. '" . "\n"; 
    
    $c = "'. $_POST["c"]. '" . "\n"; 
    
    $d = "'. $_POST["d"]. '" . "\n"; 
    
    $e = "'. $_POST["e"]. '" . "\n"; 
    
    $f = "'. $_POST["f"]. '". "\n"; 
    
    $g = "'. $_POST["g"]. '". "\n"; 
    
    ?>';

    It will not just change these lines of code

    $a = ;
    $b = ;
    $c = ;
    $d = ;
    $e = ;
    $f = ;
    $g = ;

     

    You first need to get the contents of config.php

    $contents = file_get_contents('config.php');

     

    Then replace the variable in config.php using

    $var_letters = range('a', 'g');
    foreach($var_letters as $letter)
    {   
        $oldline = '$' . $letter . ' = ;';
        $newline = '$' . $letter . ' = \'' . $_POST[ $letter ] . '\';';
    
        echo "Replacing <tt>$oldline</tt> with <tt>$newline</tt><br />";
    
        $contents = str_replace($oldline, $newline, $contents);
    }

     

    Now save the new contents to config.php

    file_put_contents('config.php', $contents);

     

    Your variables $a to $g should now be set in config.php with the values you typed within your form.

  8. You can use functions such as var_dump which will print information about a variables data type and its value.

    You can also get a backtrace using debug_print_backtrace

     

    The most important tool when developing code is setting error_reporting to E_ALL and setting display_errors to on within your php.ini. That way any errors occur they will displayed during runtime.

  9. How do I code:

     

    if "SESS_MEMBER_ID" and "SESS_STATUS - set to 'coach'" are both not set - access denied

     

    or     

     

    if "SESS_MEMBER_ID" and "SESS_STATUS - set to 'player'" are both not set - access denied

     

    Like so

    // define the people to allow access
    $people_to_allow = array('coach','player');
    
    if ( !(isset($_SESSION['SESS_MEMBER_ID']) && is_numeric($_SESSION['SESS_MEMBER_ID'])) ||        // check that SESS_MEMBER_ID is set and contains a number
         !(isset($_SESSION['SESS_STATUS']) && in_array($_SESSION['SESS_STATUS'], $people_to_allow)) // check that SESS_STATUS is set and that is in the $people_to_allow array
        )
    {
        header("location: access-denied.php");
        exit();
    }

  10. multiviews allows you to call for files without stating their extension. When it is enabled you can call site.com/about.php using site.com/about

     

    Explanation from the manual

    A MultiViews search is enabled by the MultiViews Options. If the server receives a request for /some/dir/foo and /some/dir/foo does not exist' date=' then the server reads the directory looking for all files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements, and returns that document.[/quote']
  11. Use an if statement to see if there is a value for sex and age

    // sample data to work with
    $data['name'] = 'Joe';
    $data['sex'] = '';
    $data['age'] = '';
    
         echo 'Name: ' . $data['name'] . '<br />';
    
         // Display the sex if its not empty
         if(!empty($data['name']))
         {
              echo 'Sex: '. $data['sex']  . '<br />';
         }
    
         // Display the age if its not empty
         if(!empty($data['age']))
         {
              echo 'Age: '. $data['age']  . '<br />';
         }

×
×
  • 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.