unum_sanctum()'s Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
5 (0.01 per day)
Joined:
08-October 12
Profile Views:
105
Last Active:
User is offline Dec 04 2012 11:19 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   unum_sanctum() has not set their status

Posts I've Made

  1. In Topic: SQL/PHP database call gone wrong

    Posted 29 Oct 2012

    mysql_* functions are deprecated and will eventually not exist in future implementations of PHP. I'd suggest using mysqli. For now, I suppose you're okay.
  2. In Topic: error within function > php mysql_fetch_assoc

    Posted 9 Oct 2012

    View PostAtli, on 09 October 2012 - 09:38 AM, said:

    // Don't use echo or die to print errors. Use PHP's
    // trigger_error() function instead. That way, PHP can


    What's great about this solution is you can use a custom error handler to catch your trigger_error() calls. Good call on the sanitize function as well.
  3. In Topic: error within function > php mysql_fetch_assoc

    Posted 9 Oct 2012

    You're missing one major point. What is the return status of the function?
    if( user_exists("foobar")) 
    {
       // will this ever execute? 
    }
    else
    { 
       // or this???
    }
    
    


    	function user_exists($username){
    	    $username = sanitize($username);
    	    $sql = "SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'";
    	    $result = mysql_query($sql);
    	    if(!$result) {
    	        echo "There was a error in the following sql statement : <br>".$sql;
                    //maybe a throw new Exception goes here
    	    }
                /* start patch */
    	    // Don't you want to return true or false here? 
                if( mysql_num_rows($result) > 0 ) {
                  return true; 
                }else {
                  return false;
                }
                /* end patch */
    	}
    
    


    *** EDIT ***
    wow, I really am batting 1,000 today..

    I didn't notice your query was "SELECT COUNT(*)" ... My patch may not work if you use COUNT(*).
    Better to change your query to select an ID from the table.
  4. In Topic: Fatal error: Call to a member function bindParam() on a non-object in

    Posted 9 Oct 2012

    You'll want to check if $stmt is an object after you attempt the db->prepare() function call.

    $stmt = $this->db->prepare($sql);
    if( is_object($stmt) )
    {
        //Alternatively you can opt to return an error rather than throw an exception
        // but you already have a catch statement so might as well make use of it
        throw new Exception("Prepare returned a non-object: " . var_export($stmt,1) );
    }
    
    


    OOPS. The code is supposed to be this:
    $stmt = $this->db->prepare($sql);
    if( is_object($stmt) == false) //this is the change
    {
        //Alternatively you can opt to return an error rather than throw an exception
        // but you already have a catch statement so might as well make use of it
        throw new Exception("Prepare returned a non-object: " . var_export($stmt,1) );
    }
    
    
    
  5. In Topic: Reload Original Page after submit.

    Posted 8 Oct 2012

    I can think of a few ways to solve this

    Utilize the bootstrap modal window
    http://twitter.githu...javascript.html

    I would have the content editor popup in a modal window (preferably bootstrap's). Why?
    Well because that would still allow you to pull this off with one page.
    When then user submits the content from the content editor, you can submit that via
    ajax (encoding it in json), and then refresh the content on page using ajax.

    Or, if you don't want to do all that javascript, then as soon as the content editor
    saves data, you trigger it to submit in a form. I'm assuming the content editor is a
    giant TEXTAREA anyways, so this sort of hackery should be trivial.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

unum_sanctum() hasn't added any friends yet.

Comments

unum_sanctum() has no profile comments yet. Why not say hello?