Jump to content

Boo-urns

Members
  • Posts

    144
  • Joined

  • Last visited

    Never

Posts posted by Boo-urns

  1. <?php
    class db extends MySQLi {
         // some vars
    
        public function insertQuery($table, $fields, $values) {   	// Insert into table function;
      
      // Field processing (separating string, adding proper syntax to the field as well
    	$fVal = '';									   	// field value for the insert query
    	$insertFields = explode(", ", $fields); 		// separating the field string
    	$fCount = count($insertFields);
    	$i = 1;
    
    	foreach ($insertFields as $fieldVal) {
    		$fVal .= ($i < $fCount) ? "`$fieldVal`, " : "`$fieldVal`";
    	    $i++;
    	}
      // end of field processing	
    
      // value processing
      													// pretty much same as above code
      	$val = '';
    	$values = explode(", ", $values);
    	$vCount = count($values);
    	$j = 1;
    
    	foreach ($values as $v) {
    		$val .= ($j < $vCount) ? "'$v', " : "'$v'";
    		$j++; 
    	}
      // end of value processing
    
    
      // INSERTING INTO DB STRING	
    	$insert = "INSERT INTO ". $table ." ( ". $fVal ." ) VALUES ( ". $val . " )";
    
    	mysqli::query($insert);
    
    } // end of insertQuery
    
    }
    

     

    So my problem is the query. It's not querying the mysqli query function. I have errors being displayed but its not giving me any problems. What am I doing wrong?

     

    -Corey

  2. I have a dropdown and when a user selects how many entries they want to add it calls a file to create a form and bring it back. Well it works great locally but not on a live server. Firebug is saying I'm getting a 500 error. (I've tried absolute and relative paths but it's not working.) If I copy the include file on that script page it will run hardcoded but isn't getting the variables. The data posts just fine but PHP isn't pulling the variables.

    <?php $numForms  = mysql_real_escape_string($_REQUEST['numForms']);

    Is something screwed up in the php.ini file or something on the server? Any ideas? I'm stumped  :(

     

    -Corey

  3. I wasn't sure if it was a php.ini setting or not.

     

    The code runs great locally, I didn't change anything then I put it on a development server. If i do:

     $var = $_REQUEST['var']; 

    That is giving me a 500 error. Maybe that will help?

  4. I've been working locally creating some scripts, when I moved it to a development server the main scripts work.  (i.e. if i post on that page) However If I am calling a file with AJAX and bringing info back it's not working. I believe it is something with the $_REQUEST['varname'].

     

    The variable passes just fine but isn't getting pulled into a variable on the file I am calling with the request method. If i send the variable straight up as a request back in the json_encode it will show up.

     

    Any ideas on what to change?

     

    Thanks!

    -Corey

  5. So you're just looking to have 5 not be a static variable? i.e. they can have 7 tickets or 100 tickets etc...?

     

    What I do is I create a table for defaults and have a column for what you're going after. (ticketMax column = whatever maximum number)

     

    Unless, you aren't going to reuse it somewhere else you could always create a variable up top for ticket max and input it in your code

     

    <?php
    
    $ticketMax = 10; // or pull the maximum from the db if you do it that way.
    
    if($getnumber >= $ticketMax && $opentick['status'] == "Open"){
    
        echo "<b><center>Please wait until one of your tickets is solved before creating another one.</center></b>";
    
    }
    

     

    I hope that is what you were asking.

  6. Can you use bind_param and execute in a for loop? (With the bind outside of it)

     

    <?php
    // $db is being extended from the mysqli class
    
    if($stmt = $db->prepare("INSERT INTO test (fName, lName) VALUES(?, ?)")) {
    
    			$stmt->bind_param('ss', $fName, $lName);
    
    			for($i = 1; $i <= $numDeclared; $i++) { // numDeclared is a hidden field to figure out how many forms there are on the page
    			// i am starting on 1 on purpose.
    
    				$fName = $fName[$i];
    				$lName = $lName[$i];
    
    				// Execute the prepared Statement
    	    		       $stmt->execute();	
    
    			}
    
    			// Close the statement 
    	    	        $stmt->close(); 				
    		}
    

     

    It loops properly but is only inserting the first row (if i have multiple). Also is there a built in real_escape_string when preparing queries? (I'm doing it outside of it right now)

     

    Thanks!

     

    -Corey

  7. Yea I could see that being a great way for that.

     

    What if other developers are working on the same project want to use your __autoload func that you wrote up to include them?

    Say I write my files class.animal.php and the other guy writes it animal.class.php and another guy writes is just animal.php Or should i just be like this is the way we name files? Any suggestions?

     

    <?php
    
       function __autoload($className) {
            // granted to incorporate different ways to save files I will need to write more code
           
    	$file = 'classes/class.'.$className.'.php';
    	include_once($file);
    }
    
    $test = new testAutoload();	// w/ autoload func it will pull file "classes/class.testAutoload.php"
    
    ?>
    

  8. Yea I went to school for Multimedia but they didn't stress to much programming and/or require programming minus basic C++ and some Javascript / PHP / etc....but no OOP.

     

    Yea mchl I agree a lot of the examples I have found are class Animal / class Dog extends Animal etc... I do the same as premiso for any programming create an outline of general functionality of what will be needed.

     

    Would autoload be better use in a framework? I have been going over some autoload examples this morning but atm it seems better to just include the file myself.

  9. Wow thanks for all the insights about OOP. Along with the links to some tutorials.

     

    I've been through a few tutorials so far and have probably just touched the surface of OOP but want to dive much deeper so I can create some very reusable code in the future and possibly create a framework (in time). I'll most likely have more questions in the future but thanks for the push guys!

  10. Some uses of oop are easy to comprehend. Class for Users / Common Validation etc... Would it be a good idea to extend the mysqli class? To create queries and to return the loaded results. Along with that to create it for ease of use in the future should I send it fields / table / WHERE info or would that not be a good idea?

     

    I just need a push :)

  11. From what you're saying make sure you change the second part of what you're matching to "songName LIKE" as currently it is artistName. That might be your problem.

     

    I did test the code locally on a test table and it worked fine I just threw it variables for easier testing

     

    i.e. LIKE '%$string1%'

     

    Hopefully that helps.

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