Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Community Answers

  1. benanamen's post in PHP code stopped working was marked as the answer   
    Of course it's blank. All your doing is setting $error. The script is done by the time you get to this point. Think this through, I am sure you can figure out what needs to be changed.
     
     
            } else {
                $_SESSION['loggedIn'] = false;
                $error = "Invalid username and password!";
            }
     
     
    FYI: This is no kind of logging in code you should be using.
  2. benanamen's post in mysql_fetch_assoc return null values was marked as the answer   
    You have a handle of $row but are using $_row.
  3. benanamen's post in Hyperlink in PHP (harder than it sounds) was marked as the answer   
    Are you defining $content before here? Reason is you are doing dot equals. If it is not defined change .= to just =
     
    The image doesn't help. Where is $content first defined? Meaning where is content= without the period?
  4. benanamen's post in I need your help applying a script to more databases was marked as the answer   
    Eric, I have done a quick review of the code in that script. Get your money back and don't use it. There are several serious security issues with it. One of the more glaring ones is that it uses MD5 or SHA256 for password encryption. It will also output the exact server error messages directly to the user providing valuable information to a hacker.
  5. benanamen's post in Noob Question.. what does ? character do in this statement was marked as the answer   
    That is called a Ternary Operator. Same thing as if/else
     
    https://davidwalsh.name/php-shorthand-if-else-ternary-operators
     
    http://php.net/manual/en/language.operators.comparison.php
  6. benanamen's post in Data are not inserted into database where is the problem in this code? was marked as the answer   
    First, you are using obsolete Mysql code that will not work at all in the latest version of Php. You need to use PDO with prepared statements.
     
    Second, get rid of all the @'s. DO NOT SUPPRESS ERRORS. Errors are your friend, they tell you when something is wrong.
     
    And lets not forget about you jumping case all over the place. Always use lower case names.
     
    Why is your table name a variable? Are you going to insert those exact column names into more than one table?
     
    In your error message there is a missing quote.
  7. benanamen's post in Defining panel size - help needed was marked as the answer   
    Just an FYI, you dont have to set both height and width. You can set one or the other. The image will scale proportionally.
  8. benanamen's post in mutliple conditions for same join for same column was marked as the answer   
    Why do you insist on trying to get a bad design to work? Stripped or not, what you have is simply no good.
  9. benanamen's post in best way to validate in PHP was marked as the answer   
    The second way. The first one is a <?= str_rot13('Pyhfgre Shpx') ?>
  10. benanamen's post in Cant spot syntax error was marked as the answer   
    Problem is here
    if($_POST){  
     
    Delete it.
     
    Your form tables are bad as well. All your tables are missing closing tags No closiing tr or td's, or table. And you shouldnt be using a tables for your forms. Use CSS. And you should probably switch around your if else post to if($_POST) instead of the negative if not post.
     
    Also, there is no need to create all those useless variables.
  11. benanamen's post in syntax Help passing a Variable was marked as the answer   
    Most likely {$row['id']}
     
    Whatever your ID column is named.
    echo "<tr><td><a href=\"kf_orders_entered_detail.php?id={$row['id']}\">{$row['ompCreatedBy']}</td>";
  12. benanamen's post in Separating two variables in an image string was marked as the answer   
    echo "<td width=\"100\"><div align=\"center\"><img src=\"http://www.brickbybricks.ca/php/images/{$row['Color_Name']}/{$row['PartID']}.gif\"></td>";  The only thing about that is you have no choice but to escape and concatenate the variables instead of doing {$row['Color_Name']} (Curly Syntax, my preference). 
  13. benanamen's post in Need help with SELECT WHERE statement was marked as the answer   
    Ok, we are getting somewhere.
     
    Now, just use this code alone while you get things going. The difference is I have now added what is called a "Positional Placeholder" for username which is the question mark. There is another way to do it called "Named Parameters" but we can get into that another time. The code will now give you the individual column data.
     
    This is complete standalone with the connection code. Just practice with this. you can integrate it later. Set the connection parameters to your DB.
     
     
    <?php
    error_reporting(-1);
    ini_set('display_errors', '1');

    $hostdb   = 'localhost';
    $dbname   = 'phphelp_joe';
    $username = 'root';
    $password = '';

    if (!empty($_GET['username']))
        {  
        $pdo = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        $sql  = "SELECT username, firstname, lastname, email FROM users WHERE username=?";
        $stmt = $pdo->prepare($sql);
        $stmt->execute(array(
            $_GET['username']
        ));
        $row = $stmt->fetch();
        echo "{$row['username']} {$row['lastname']} {$row['email']}";
        }
    else
        {
        echo 'No username in URL';
        }
    ?>
  14. benanamen's post in Sql without 000-00-00 date was marked as the answer   
    Add this to your query
    AND t1.`data_prevista` <> '0000-00-00' SELECT t1.`id_plano`,         t1.`atividade`,         t1.`data_prevista`  FROM   `new_pae` AS t1  WHERE  t1.`id_user` = '$idUser'         AND t1.`data_prevista` <= Curdate()         AND t1.`data_prevista` <> '0000-00-00'         AND ( t1.`realizado` IS NULL                OR Length(t1.`realizado`) = 0 )
  15. benanamen's post in Stop submit if function returns false was marked as the answer   
    You might want to just use a date-picker that will put the date format you want into a read only field. Dont allow the user to enter it wrong in the first place.
  16. benanamen's post in database design was marked as the answer   
    You can have millions of records in a table. You should first learn Database Normalization and you will have a better idea how to do your tables. The amount of records you have wont even tickle a database.
  17. benanamen's post in Having Problem Populating a Select/drop down menu Using Data from a MySQL table was marked as the answer   
    Ok, looka here young man, see what you did?
     
    $row2 = mysql_fetch_array($r2, MYSQLI_ASSOC);    
     
    You do remember you are using Mysqli right?
     
     
    I think we should get you on PDO, it's just better. Not an opinion, it just is.
  18. benanamen's post in Submiting form with text fields and checkbox's Need help was marked as the answer   
    OP, so your not confused,
     
     
    $checkbox1 = isset($_POST['checkbox1']) ? 1 : 0;
     
    does the same exact thing as
     
     
     
    What I showed you is a Ternary Operator. It would behoove you to know how to use it. There is no need to have a value for the form check box.
     
    $checkbox1 = isset($_POST['checkbox1']) ? 'this_is_my_check_box_insert_value_not_a_number' : 0;
     
    A string will require to be quoted, a number no quotes.
  19. benanamen's post in var_dump(parse_url($url, PHP_URL_QUERY )) issue was marked as the answer   
    You dont use var_dump as part of your code. That is for debugging.
     
     
     
    Per the manual:
    var_dump — Dumps information about a variable
     
     
     
      $email = 'email@email.com';   echo $key = sha1($email.'my_super_duper_secret_sauce_here'.microtime());    // YOU HAVE TO DO THIS IN THE BROWSER. You also need to save the key to a DB. The key constantly changes so you cant compare what is generated directly. It will NEVER match. //https://www.mysite.com?k=0281cdeb4fa63c4ca087e8052b0c1685fc0a51e6   if ($key_from_db==$_GET['k']){ echo 'Match'; } else { echo 'No Match'; }
  20. benanamen's post in Set Status Code Header(401) and Apache ErrorDocument Help was marked as the answer   
    Try this:
    if($adminString == "False"){ die(header("Location: /path_to_file/error.php")); } Another thing you could do is just redirect them back to your main page and not even show an error to the user.
  21. benanamen's post in read a cvs file and only displaying some data was marked as the answer   
    I will leave it up to you to handle the dates
     
     
    <?php $url  = "http://ichart.finance.yahoo.com/table.csv?s=f"; $file = file($url); foreach ($file as $value)     {     if (stristr($value, '2015-09-10'))         {         echo $value;         }     } ?>
  22. benanamen's post in imploding a multi dimensional array was marked as the answer   
    $cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) ); function r_implode( $glue, $pieces ) { foreach( $pieces as $r_pieces ) { if( is_array( $r_pieces ) ) { $retVal[] = r_implode( $glue, $r_pieces ); } else { $retVal[] = $r_pieces; } } return implode( $glue, $retVal ); } echo r_implode( '||', $cars ) Result: Volvo||22||18||BMW||15||13||Saab||5||2||Land Rover||17||15
     
    Source:http://www.craiglotter.co.za/2010/04/09/php-implode-a-multi-dimensional-array/
×
×
  • 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.