Jump to content

TOA

Members
  • Posts

    623
  • Joined

  • Last visited

Posts posted by TOA

  1. Actually, I wouldn't use output escaping there. That's where I'd validate the input, to make sure it conforms to the expected formats.

     

    Only when sending the data to the SQL (query) would I escape it, to prevent both SQL injections and mangling the content when sent to other systems (like the browser, in case of validation errors).

     

    Valid point. Since there was nothing in between the variable declarations and the actual query, I failed to notice the need for that comment. But very worth pointing out. Good catch.

  2. For each of these

     

    $id_categoria=$_POST["id_categoria"];
    $id_subcategoria=$_POST["id_subcategoria"];
    $articulo_tit=$_POST["articulo_tit"];
    $articulo_descripcion=$_POST["articulo_descripcion"];
    $articulo_novedad=$_POST["articulo_novedad"];
    $articulo_visible=$_POST["articulo_visible"];
    $articulo_oferta=$_POST["articulo_oferta"];
    
    

    it would be

    $id_categoria=mysql_real_escape_string($_POST["id_categoria"]);
    [...]
    

    Then just use the variables as you normally would.

     

    Deprecated means they will stop supporting it soon so you should switch to the mysqli group of functions. Here's a link to get you started: mysqli.

  3. Also, check out this indented version

    $banned = array('Main_Page','Community_portal','Current_events','Special:RecentChanges','Help:Contents','Special:WhatLinksHere/Help:Contents','Special:Upload,Special:SpecialPages','itsmywiki.com:Privacy_policy','itsmywiki.com:About','itsmywiki:General_disclaimer','Special:Preferences,Special:Watchlist','Special:Contributions/itsmywiki.com','Special:UserLogout&returnto=Special%3AContributions%2F$','User:$,User_talk:$');
    $allowed = array('edit','history');
    if (in_array($_GET['title'], $banned)) {
     // do nothing
    } else {
    if (in_array($_GET['action'], $allowed)) {
    // do nothing
    }
    else {
    echo '<center><div class="fb-comments" data-width="800" data-num-posts="100" data-colorscheme="dark"></div></center>';
    }
    }
    

     

    if the $_GET['title'] is in that array, you do nothing. Try negating that (!in_array())

  4. I think your errors are stemming from here. Not your technical errors, but your logic errors (although probably both).

     

    First I have this login page, Where I am creating a connection to the DB and then creating a new user. Then I call the function $user->login();

     

    The user should not log itself in. Query the db with the user input and if successful, construct a user/set a cookie/etc. This could be done procedurally, or you could make some sort of Authorization class.

     

    This is evident by the need to extend the DB class as a User. As trq noted: is a user a database? No. So it should not extend it; nor have any knowledge of it really.

     

    Just my opinion. Hope it helps

  5. If I may offer another opinion..

     

    I would actually say your user class should have no knowledge of where the data comes from at all. What happens if the business rules change to include csv's? I think you should just pass in an array of data so the user doesn't care where it comes from. Handle the logging in the client code or a mediary class.

     

    Just my two cents. :)

  6. From what I know of mssql, it looks fine, but I have to admit that knowledge is limited. But, we already determined it wasn't the connection or the db, it's the results using this (and btw this tests the connection, not the results)

     

    if (!$result) {
    die('We have no result so everything after will fail');
    }
    

     

    When you loop through your result set here

     

    $resultAsArray = array();
    while ( $row = sqlsrv_fetch( $result, SQLSRV_FETCH_ASSOC )) {
    $resultAsArray []= $row;
    }
    print_r($resultAsArray);
    

     

    we proved the results are empty with the print_r() statement.

     

    So that tells us that the problem is before that, and since it's not with the connection, there's only the query left as far as I know. So that must be failing.

     

    Sorry, that's about all I can help with.

  7. Yes $resultAsArray is empty, because it starts out empty. I put my query in to SQL and it pulled my list. My connection to the Database I know works, because I have the same thing for another page and it works fine. But getting this to put into a drop down box does not work. I had something else, but it only worked in Chrome but not IE and that was because I had a table nested into the select, which I have found out is wrong. So someone from another forum suggested this route for the select, but was psuedocode and I had to match up what he had in psuedocode to MSSQL code.

     

    Right, so you're while statement is doing nothing. It has no relevant data is what I mean. It never puts anything into $resultAsArray so the problem is there.

  8. OK, revert it back then; I was trying to see if maybe php wasn't parsing that array value.

     

    The code if (!$result) just makes sure your connection failed or not, not that you have valid results. Add this right before your form and verify you have results, not just a non-false value

    echo "<pre>";
    print_r($resultAsArray);
    echo "</pre>";
    

  9. There's not much of a difference here, but try this and let me know what happens. I'm not sure if this is the problem or not, but we have to start somewhere :)

     

    $result = sqlsrv_query($connection,$query);
    if(!$result) {
    die('We have no result so everything after will fail');
    }
    // Move the data to a simple array to simplify presentation code.
    $resultAsArray = array();
    while ( $row = sqlsrv_fetch( $result, SQLSRV_FETCH_ASSOC )) {
    $resultAsArray []= $row;
    }
    /*echo $resultAsArray;*/
    ?>
    <form method="get" action="getlog.php">
    <table width="250" border="0">
    <tr>
    <td>Forte ID:</td>
    <td>
    <select name="test" id="test">
    <?php foreach ($resultAsArray as $row): ?>
    <option value="<?php echo {$row['ForteID']};?>"><?php echo $row['ForteID']; ?></option>
    <?php endforeach; ?>
    </select>
    

     

    PS options don't need a name, and an ID needs to be unique, so I took out the id too.

  10. Pretty much as in changing the "post" to "POST" so it would trigger,

     

    That doesn't matter if he uses 'post' in the method. It just has to match.

     

    encasing it in PRE tags so it would be more readable

     

    That doesn't make anything more functional or more correct

     

    then adding the PHP tags so it worked

     

    My mistake, I assumed since he was on a php forum... ::)

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