Jump to content

ricmetal

Members
  • Posts

    351
  • Joined

  • Last visited

Posts posted by ricmetal

  1. hi guys

    im struggling with data. encoding, decoding, validation, sanitation...i have come up with this life cycle for data i would like to share and see how or if it can be improved.

     

    the first line is based on the data life cycle of a variable passed with AJAX to the database and back.

    the second line is a simple dbase data fetch and html print.

     

    limit char length in javascript, encode, decode in php, limit in php, insert in db. fetch from db, encode in php, decode in javascript, sanitize before html insert.

     

    for simple db fetches in php and direct html insert, just sanitize

     

    any comments would be great.

  2. hi guys

    i am trying to insert a new row in a table with

    if ($stmt = $mysqli->prepare("INSERT INTO photographers (id) VALUES (?)")) {

    my photographers table has an id column, which is not incrementable and is an integer.

    the value passed to the SELECT is also an integer. (i've double checked and using intval() ).

    now, i can't get this row to be inserted! everything i can think and know of is working, db connections, etc. such, that if i change the value to be inserted, (and the column to insert to), the insert works. for instance, if i insert a string in the email column, the insert occurs.

    what can i check to see why the id integer won't insert?

     

    here is an excerpt of the code i am working on:

    // The following insert works fine and yields the id created through the insert (auto incremented)
    if ($stmt = $mysqli->prepare("INSERT INTO users (id, user_email, user_pwd, intro_text) VALUES (NULL, ?, ?, ?)")) {
        $stmt->bind_param('sss', $email, $md5pass, $introText);
        $email = $_POST['email'];// this is fetched and treated elsewhere, just here for consistency
        $md5pass = substr(md5($_POST['pass2']), 0, 32);
        $introText = substr($_POST['intro_text'], 0, 500);
        $stmt->execute();
        $newIdString = $stmt->insert_id;
        $newId = intval($newIdString);
        $stmt->close();
    
            // Insert new user into photographers table. This is where the insert doesn't happen.
            // The commented out lines will work if i run those instead.
            if ($stmt = $mysqli->prepare("INSERT INTO photographers (id) VALUES (?)")) {
        // if ($stmt = $mysqli->prepare("INSERT INTO photographers (user_email) VALUES (?)")) {
                $stmt->bind_param('i', $newId);
            // $stmt->bind_param('s', $email);
                $stmt->execute();
                echo $newId;
                $stmt->close();
                $mysqli->close();
    

     

    what can i check to make this work?

     

  3. To determine if the row was not affected due to the data being the same or the WHERE clause being false, you would need to fist execute a SELECT query with the same WHERE clause. You would then know that the matching row exists and the update returned a zero for mysql_affected_rows() because the data being updated is the same as the old value.

     

    thats what i thought after posting this thread.cheers

  4. yeah but "placing that string into an array of others" can mean a multidimension array. "placing that string into an array of others arrays" :)

     

    anyho, ive figured this out.

     

    var resultRaw = "3,1a_2a_3a_4a-1b_2b_3b_4b-1c_2c_3c_4c";
    var charAtPos = resultRaw.indexOf(',');
    var items = resultRaw.substring(0, charAtPos);
    var resultVar = resultRaw.substr(charAtPos + 1);
    
    var simpleArray = resultVar.split("-");
    var array = new Array(items);
    for (var i = 0; i < items; i++) {
    array[i] = new Array(4);
    var row = simpleArray[i].split("_");
    for (var j = 0; j < 4; j++) {
    	array[i][j] = row[j];
    }
    }
    
    alert(array[2][3]);
    

  5. "maybe i'm reading it wrong but it seems to me that your concatenating your results into a single string and then placing that string into an array of others.."

     

    well that is what multidimensional arrays is, right?

     

    im not very fluent in programming so ill have a hard time to explain any further details but this is what i can use:

     

    
    // the concatenated string
    var resultString = id1,photo1,thumb1,description1,id2,photo2,thumb2,description2,id3,photo3,thumb3,description3;
    
    resultArray[0][0] = "id1";
    resultArray[0][2] = "photo1";
    resultArray[0][3] = "thumbnail1";
    resultArray[0][4] = "description1";
    resultArray[1][0] = "id2";
    resultArray[1][2] = "photo2";
    resultArray[1][3] = "thumbnail2";
    resultArray[1][4] = "description2";
    

     

    ive got this so far, in order to create the multidimensional arrays

     

    var resultVar = "3,1a_2a_3a-1b_2b_3b-1c_2c_3c";
    var charAtPos = resultVar.indexOf(',');
    var x = resultVar.substring(0, charAtPos);
    
    var parentArray= new Array(x);
    for (var i=0; i<x; i++) {
    parentArray[i]=new Array(3); 
    }
    

     

    but i am stil trying to find out how to populate them.

  6. hi all

    i need some help figuring out how to create something.

     

    i have a database table with 4 columns. id, photo, thumbnail, description.

     

    i am querying the table and fetching all rows with the id == 1 (theres many id numbers, but i only want to fetch all rows where id = 1).

    this from an AJAX request.

    in the PHP file which is called from the AJAX request, i have a script i used for another site which yields a variable with the content fo a single table row, and with in between each column fetched i added a unique text to use to do an array split, as following.

     

    //JavaScript
    var resultArray = resultVar.split(" uniqueDeviderLineForPhp "); // resultVar in the varibale sent from php to javascript
    $(':input#exhibNameEditField').val(resultArray[0]);
    $(':input#exhibDescEditField').val(resultArray[1]);
    $(':input#dayEditDD').selectOptions(resultArray[2]);
    $(':input#monthEditDD').selectOptions(resultArray[3]);
    $(':input#yearEditDD').selectOptions(resultArray[4]);
    

    now, this is for one single row fetch.

     

    how could do the same thing for a resultVar variable with multiple rows. i already devide each columns content with the unique deivder line for php. how could i go about dividing the string not only by column, but also id?

     

    the resultVar string i get is something link:

     

    resultVar = id8 uniqueDeviderLineForPhp photo.jpg uniqueDeviderLineForPhp thumbnail.jpg uniqueDeviderLineForPhp description uniqueDeviderLineForPhp id16 uniqueDeviderLineForPhp photo.jpg uniqueDeviderLineForPhp thumbnail.jpg uniqueDeviderLineForPhp description uniqueDeviderLineForPhp  id34 uniqueDeviderLineForPhp photo.jpg etc
    

     

    the id is only a number, i just added the id  text in front of the number for ease of understanding.

    also, the ids are not sequencial. regards

  7. hiy

    it would be nice if there was a bookmark option where i could bookmark posts i want to read later.

    unlike the follow, or notify, i would not get an email for these posts, when a reply to the post is made.

    i use the notify option as well to get notifications on posts i want to get notifications on, so the bookmark addon would be different.

    cheers

  8. hey people

    i cant get copy() to work.

    im working on an online server and trying to copy a file into directories i just created.

    i read about fopen() having to be enabled if both source and destination files are urls, and fopen is enabled and both files are urls (and on the same server).

    the directories get created but the file doesnt get copied. the directories have permission 777.

    could it be that when i call the copy function the directories aren't yet available on the server? i am copying the file in the same code block as 'create folders', right after.

    any pointers?

  9. OpenCart uses something, that, depending on a language setting it loads a different php page filled with variables like so:

    $_['text_no_reviews']     = 'There are no reviews for this product.';

    so, if your language for the app is english it loads that php file filled with variabes containing text in english.

    i want to do something similar.

    i want to have a php file with all the text to be used throughout the application in English, and call it from each php page i am at.

     

    i don't how to make myself clearer because i myself and not a hardcore coder. like the avatar sub title says: 'enthusiast'

  10. hey guys

    i made this php application without any kind of specific framework....it started out a just a little website for a friend, but i kinda want to try and upgrade it to create an app i can sell.

     

    for this, i want to add a language setting so users can navigate the app with their desired language.

    i looked up the MVC framework because i've been modding OpenCart, but it looks too complex to learn just for what i need.

     

    so, i ask, is their any easier way to setting up a language setting thing, preferably as lite as possible.

     

    ?

     

    my app is divided into single php pages, connected through href links solely.

     

     

     

  11. hi guys

     

    here are my settings:

        * Server: Localhost via UNIX socket
        * Server version: 5.0.91-community
        * MySQL charset: UTF-8 Unicode (utf8)
    
    Web server
        * MySQL client version: 5.0.91
        * PHP extension: mysql
    

     

    my situation:

     

    i am retrieving data from the database with the mysqli extension.

    ...
    $stmt = $mysqli->prepare("SELECT city FROM world WHERE city = ? ");
    $stmt->bind_param('s',$city);
    $stmt->execute();
    $stmt->store_result();
    if($stmt->num_rows == 0){
      //no rows
    }
    ...
    

     

    i don't want to change any setting to the default configuration set by a script i installed, if i don't have to but i need to test input data (from a html form) against existing data in the dbase for duplicated entries, without taking into account text case. when i test against case-sensitivity, according to testing, an input "lisbon" is different from an existing dbase entry of "Lisbon" but i want it to be the same.

     

    i am turning all input data from the html form into lower case before i test it against the data retrieved from the dbase but i need to have the dbase data retrieved turned to lower case as well.

     

    anyone have an idea how i would go about doing this?

  12. hey

    i'm making an addon for opencart so people can upload their own digital products-

    i am trying to make a secure thing with error handling so there's a few steps like checking duplicate file names, file extension, etc.

    but i'm wondering: when does the actual upload occur?

     

  13. i think all you need to do if check when the variables you called from php have arrived to flash and then you should check them and see what the variables contain. if they contain a success message, then login, else, logout.

    use onEnterFrame and cehck the names of the variables that come in from php to see if they exist. when they exist, check their content.

    LoadVars gives you a better control btw to do this.it contains a built in event handler that automatically check when the variables are  loaded, so you don't need to setup the onEnterFrame.

     

    var myVars:LoadVars = new LoadVars();
    myVars.onLoad = function(success:boolean) { //the event handler
      if(success) { //variables where loaded into flash successfully
        if(myVars.thePhpVarContainingTheResultOfASuccessfullLogin == "login successfull") {
          gotoAndStop("login");
        }else{
          gotoAndStop("logout");
        }
      }else{
        trace(the variables where unable to be loaded check the php path and code);
      }
    }
    myVars.load("file.php");
    

  14. from php echo an urlencoded line to send to flash like following

     

    echo "varNameForFlashToPickUp=".rawurlencode($phpVariable)."";
    //if that doesn't work, add a & before 'varNameForFlashToPickUp'
    

     

    from within flash use the LoadVars method to load variables into flash

     

    var phpVariables:LoadVars = new LoadVars();
    phpVariables.onLoad = function(){
       trace(phpVariables.varNameForFlashToPickUp);
    }
    phpVariables.load("phpFile.php");
    

     

    the rawurlencode funtion in php is used to make sure that all special characters like $ don't mess with the rest of the code

    flash automatically decodes

  15. okay, i hate to go into encodings and decodings, and i need to buy a javascript book to learn more about js's inner workings but i got my problem solved, escaping and encoding.

     

    i tried jquery's ajaxform and bullshit, it didn't help with stripslashing and character encoding, so i managed to emulate the ajax form and improve it with just a few lines of js :P

     

    anyway for the peeps looking to have ajax forms and are stuck with encodings and characters here's a few thing to look up in order to get the job done. (thanks f1fan)

     

    i'll actually post the lines i changed in my code (note that i dont go into charsets, but i do have my main html files with charset set to utf-8. you might want to look into setting charset headers for php files used with ajax) just review and acomodate:

     

    <!-- encodeURIComponent -->
    var params = "textContent="+encodeURIComponent(textContent)+"&cacheid="+Math.random();
    xmlHttp.open("POST", url, true);
    
    <!-- FUNCTION TO STRIP SLAHES I HAVE FROM A PHP GURU WHICH I HIRED SOME TIME BACK -->
    <?php
    function UndoMagicQuotesLambda(&$value, $key) {
           $value = stripslashes($value);
    }
    if (get_magic_quotes_gpc()) {
       $aMagicQuoted = Array(      '_POST', '_GET','_COOKIE', '_REQUEST');
       foreach ($aMagicQuoted as $var)
           array_walk_recursive($GLOBALS[$var], 'UndoMagicQuotesLambda');
    }
    ?>
    
    <!-- AND ON THE PHP SCRIPT CALLED FROM THE XMLHTTP OBJECT  -->
    include '../phpincludes/m_quotes.php';//WHICH CALLS THE ABOVE FUNCTIONS
    $textContent = $_POST['textContent'];
    

     

    regards

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