/ Published in: PHP
Makes basic insert statements a breeze to type while doing basic PHP inserts.\r\n*The function for \\\'querys\\\' on line 44 can be found here: http://snipplr.com/view/40911/query-the-database-php/ *
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Insert //$sql = "INSERT INTO quick_links (title, link) VALUES('" . $_POST['title'] . "', '" . $link . "');"; function add($table, $columns, $values){ //begin the insert into******************************************************* $sql = "INSERT INTO " . $table; //iterate through the $table************************************************** //iterate through the $columns *********************************************** $sql = $sql . " (" . $columns . ") VALUES("; //iterate through the $values************************************************* //loop the array foreach($arrValue as $arrValueResult){ //check if last index in array $arrValueResult = $arrValueResult ; }else{ $arrValueResult = "'" . $arrValueResult . "'" ; } }else{ $arrValueResult = $arrValueResult . ", " ; }else{ $arrValueResult = "'" . $arrValueResult . "', " ; } }//end if //add to $sql $sql = $sql . $arrValueResult; }//end for each //end the $sql $sql = $sql . ");"; //determine is item in $values is an interger / string //echo $sql; //insert the query $insert_sql = querys($sql); }//end add //----------------------------------------------------------------- //To use this function: $add_cat = add("categories", "cat", $_POST['cat']);
URL: linkdeo.net