Jump to content

fortnox007

Members
  • Posts

    783
  • Joined

  • Last visited

    Never

Posts posted by fortnox007

  1. HI all, something that keeps bothering me is that i do not fully understand the usefullness of the \n newline character.

    When i use  for testing in a string it doesn't show the effect in my browser. Only when I press view source I can see that right after the \n character the code jumps down 1 line. Does anyone know how and when to use it? I have see it with the php mail function, but i don't really understand why they use it.

     

    If someone could enlighten me i would be very happy  ::)

  2. Cool, I learned something again. I am gonna read that php manual tonight. have to eat now :)

    thanks again you both, i am feeling like a future jedi  ;)

     

    -edit: Oh and thx for the example of the underscore I now understand it : )

  3. Oh a small questions i have about the {} i just tested a bit and foudn out {} cant be used within single quotes but only within double quotes.

     

    But In the book I have it says that i can use variables in a double quoted string without using the special dots which are needed in a single quoted string. So to make it clear for my self; why are you using:

    $fruitOptions .= "<option value=\"{$value}\"{$selected}>{$label}</option>\n";

    instead of

    $fruitOptions .= "<option value=\"$value\"$selected>$label</option>\n";

     

    i hope this isn't the most stupid question, but it totally new for me

  4. Why would you not want to use the ternary operator? It is the perfect solution when you need to set a variable to one of two values based upon a condition.

    Well i am still kinda new to this way of writting php.

     

    In both your codes i see complete new things for me:

    - variables within {}

    -  .=

    - something that looks like an if statements with ? and :

     

    Lol this small script will keep me bussy studying : ) Anyways ty both for the great help

    -edit : Ill try to learn those things today : )

  5. Oh wow thanks you both for the really quick respond. the first one looks pretty advanced  :o I have to decypher it a bit but that's good for learning. I'll try to rewrite it a bit with normal if-statements (i still have to learn alot :) The second looks more easier for my brains :)

    Thanks alot guys!

  6. Hi all, I was wondering if someone knows a clean way to make a dropdown menu using just php and html with the following functionality. If someone selects a value from the dropdown options it should be visible on refresh.

    So in case a have a dropdown menu with: oranges, apples, grapes and someone selects grapes and submits it, grapes should be selected.

     

    I have made someonthing but it looks redundant. I think there should be something with a foreach loop or something but i can't figure it out yet.

     

    Thanks in advance,

    cheers!!

  7. This should get you started. I am using sessions and a switch statement, no javascript needed  ;D

     

    Let me know if you need help,

    cheers!

     

    <?php
    session_start();
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <?php
                $_SESSION['color'] = $_POST['color'];
                // color cases
                switch ($_SESSION['color']) {
                   case 'white':
                    echo '<link href="css/white.css" rel="stylesheet" type="text/css" />';
                     break;
                   case 'green':
                    echo '<link href="css/green.css" rel="stylesheet" type="text/css" />';
                     break;
                   case 'blue':
                    echo '<link href="css/blue.css" rel="stylesheet" type="text/css" />';
                     break;
                }
            ?>
            <title>color tester</title>
        </head>
        <body>
            <h1>bla bla bla h1</h1>
            <h2>dadadadada h2</h2>
            <h3>nanananana h3</h3>
            <p>p p p p p p p </p>
            <p>herunder is a color chooser</p>
            <form action="styleswitcher.php" method="post">
            <select name="color">
                <option value="white">white</option>
                <option value="blue">blue</option>
                <option value="green">green</option>
                <input type="submit" value="change color" name="submit" />
             </select>
            </form>
        </body>
    </html>

  8. So this would not be the correct way?

     

    <?php
    $dbc = mysqli_connect('localhost','user','pass','database');
    
    $query = "SELECT id FROM posts WHERE userID = '$userID' AND posttext='$posttext'";
    $data = mysqli_query($dbc,$query);
    
    while ($row = mysqli_fetch_array($data)){
       if (empty($row['id'])){
           echo 'Double post';
       }else{
           echo 'not a double post';
       }
    }
    
    ?>

     

    This is what I found at php.net maybe thats the way to go. I modified it a bit

     

    <?php
    
    $dbc = mysqli_connect('localhost','user','pass','database');
    
    $query = "SELECT id FROM posts WHERE userID = '$userID' AND posttext='$posttext'";
    $data = mysqli_query($dbc,$query);
    $num_rows = mysql_num_rows($data);
    
    if ($num_rows > 1){
      echo 'double post';
    }else{
      echo 'not a double post';
    }
    
    ?>

     

  9. Hey mjdamato,

     

    Thanks for your swift response. Just to make it clear for myself (i am still in the noobie fase). Is it true that the query you gave will result in True, when an exact post has allready been posted and False if it didnt? And if that's the case use this result in an if-statement to echo out an error of somekind? Not sure how to do this ;)

  10. Hi All,

     

    I was wondering if someone maybe knows a nice way to prevent double posting or posting within a certain time without using javascript. Or maybe even echoing an error if someone posts the exact same ase the previous post.

     

    I found this little snippet:

    onClick="disabled=true;this.form.submit();return true;"

    Which prevents double clicking.

    But its javascript and I rather have something besides that to cover all situations. Would love to hear what you guys use or reccomend.

     

    Thanks!

     

     

  11. I hope this is what your looking for. its a small script that checks if the submit button with the name of submit is pressed, and if a certain value or condition is met. I dont know anything about ajax yet, but for php this works.

     

    <?php
    $x = 1; // assign a value to variable x
    
    if (isset($_POST['submit'])){
        if ($x==$_POST['your_post_value_here']){  
            echo 'you pressed submit '; // or code or form to be executed
        }else{ //if submit wasn't pressed
             echo 'you didn\'t press submit';
      }
    }
    ?>
    

  12. That was initially what I was thinking too and hoping too. At least for the first (validating)part of your reply. The second part I not yet quite understand, but perhaps tomorrow I will understand it better with rebooted brains ;). I am not really familiar yet with the advanced hacking techniques  :D But  is the following what you mean? :

    To use my visual thing. Someone is theoretically able to reroute the output that would normally go to index.php. to somewhere else or another domain? If that is the case I don't yet see what sneaky stuff one could do, but I bet it's  cool :)

     

    Thx a lot Zanos really appreciate it

  13. Well I am afraid if I validated everything properly in the .php-functionality-file which ajax calls the stuff has to be validated again in ajax before returned to the orginal page. so to make it more visible. see the image below ; )

     

    zoayhj.png

     

    I have given numbers to the steps.

    1) user input triggers AJAX and requests functionality.php to act. This userinput gets validated by functionality.php itself.

    2) validated request reached MySQL

    3) MySQL returns data to functionality.php where php validates it again on output.

    4) functionality.php returns data to ajax.

     

    My question is mainly about step 4. Does ajax again needs to validate the output from functionality.php or is it safe this way?

     

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