php - Inserting an array into mysql database -
this needs adding multiple rows database it's adding first question in array. ideas?
function addnewapp($question, $type, $username, $servername){ $time = time(); $q = "insert ".tbl_applications." values ('0', '$username', '$servername', '', $time)"; if(mysql_query($q, $this->connection)){ return true; }else{ return false; } ($x=0; $x<count($question); $x++) { $q2 = "insert ".tbl_questions." set `text`='".mysql_real_escape_string($question[$x])."', `id`='0', `servername`='$servername', `type`='$type[$x]'"; if(mysql_query($q2, $this->connection)){ return true; }else{ return false; } } }
you returning true within loop.
if(mysql_query($q2, $this->connection)){ return true; }
the return statement ends function , therefor loop well. i'd this:
if(!mysql_query($q2, $this->connection)){ //if correct, don't echo "there error"; // or whatever sort of error reporting }
Comments
Post a Comment