Hello everyone, Cannot redeclare createQuery() how to fix the Cannot redeclare createQuery() error, as I understand it is impossible to write two functions, most likely this is a gross error, help solve this problem ..

  function createQuery($id, $a, $b){ $query = "INSERT INTO opisanie (x,text,text_opis) VALUES "; $limit = count($a); for($i=0; $i<$limit; $i++){ $query .= "('{$id}','{$a[$i]}', '{$b[$i]}')".($i!=$limit-1?',':''); } $res = mysql_query($query); } $aText = $_POST['form_text_o']; $aOpis = $_POST['form_text_opis']; $query = createQuery($id, $aText, $aOpis); function createQuery( $e, $s, $c, $d, $id){ $queryz = "INSERT INTO menu_zav (name,sostav,gramm,cena,x_zav) VALUES "; $limita = count($e); for($is=0; $is<$limita; $is++){ $queryz .= "('{$e[$is]}','{$s[$is]}','{$c[$is]}','{$d[$is]}','{$id}')".($is!=$limita-1?',':''); } $resa = mysql_query($queryz); } $eName = $_POST['form_name_menu']; $eOpisa = $_POST['form_opis_menu']; $eGr = $_POST['form_gr_menu']; $eCena = $_POST['form_cena_menu']; $queryz = createQuery($eName, $eOpisa, $eGr, $eCena, $id); 

    3 answers 3

    Since this is PHP , not Java or C # , for example, where you can write the same method names, but with a different signature (method overload), the only way out is to declare a method with a different name. How to call it is up to you.

    Just call meaningfully, not createQuery1 and createQuery2

    • Exactly, thanks for the answer, now I will know - Ruslan Liashenka
    • yes know problamo. - Oleg Zhilyakov
    • And why is it meaningful if the createQuery1 createQuery2 options work too? - Ruslan Liashenka
    • one
      @harbor And then suddenly there will be createQuery3, createQuery4, createQuery5, etc.? And in a year you will remember what kind of kvari are and what they do? And what do they return? And if someone wants to support your product or starts to understand the code? Well, he needs to study your functions and methods far and wide at the beginning in order to understand the logic in the place of the call? It's a nightmare)) Well, uncivilized) - Oleg Zhilyakov

    If it is principally to use the function of the same name, I can suggest using Arguments of variable length . Since the PHP version is not strictly defined, the implementation will be different. The easiest way is to consult the PHP documentation for more information.

    In conclusion, I want to add that this is not the best idea.

      And why do you stop in the middle of unification? collect all the arrays into one two-dimensional (the first "string" is the field names, the rest are the values), and pass the table name and this array to the function. And the list of fields for insertion and blocks of values ​​when forming the text of the query, collect implode lines.