Adding to the database occurs if you write values ​​in values, and reading from cells does not occur. What should I write in Values ?

mySQL_query("insert into Gefest1 (id,model,color,massa,price) values ();

The add code itself:

 <div id="content"> <? $x=mysql_connect("127.0.0.1","root",""); if (!$x) die ("error#1"); $y=mysql_select_db("Gefest"); if (!$y) die ("error#2"); $q=mysql_query("select*from `Gefest1`"); echo('<table border="1" >'); ?> <tr> <img src="3.jpg" width="1000" height="300"> <tr><td><font size="6">номер</font></td><td><font size="6">модель</font></td><td><font size="6">цвет</font></td><td><font size="6">масса</font></td><td><font size="6">цена</font></td></tr> </tr> <form action='do.html' method='post'><br> номер &nbsp <input type='int' name='txt[0]' value=''><br> модель <input type='text' name='txt[1]' value=''><br> цвет &nbsp&nbsp&nbsp&nbsp <input type='text' name='txt[2]' value=''><br> масса &nbsp&nbsp <input type='int' name='txt[3]' value=''><br> цена &nbsp&nbsp&nbsp&nbsp <input type='int' name='txt[4]' value=''> </form> <? if(@$_GET["action"]=="add") { mySQL_query("insert into Gefest1 (id,model,color,massa,price) values (); } while ($d=mysql_fetch_assoc($q)) { ?> <tr> <td><font size="5"><?echo($d["id"]);?></font></td> <td><font size="5"><?echo($d["model"]);?></font></td> <td><font size="5"><?echo($d["color"]);?></font></td> <td><font size="5"><?echo($d["massa"]);?></font></td> <td><font size="5"><?echo($d["price"]);?></font></td> </tr> <? } echo('</table>'); ?> <a href="?action=add">Добавить</a> <? 
  • So you make a dump ( var_dump/var_export/print_r ) of what comes and see what you need to insert into your INSERT. - BOPOH

1 answer 1

@CAHEK , you yourself quoted a problematic line:

 mySQL_query("insert into Gefest1 (id,model,color,massa,price) values (); 

See what your mistake is:

 if(@$_GET["action"]=="add") { /** * Имена функций регистрозависимы. mysql_query и mySQL_query — не одно и то же * Еще у вас ошибка синтаксиса, пропущено след. выражение: __");__ * Из-за этого все, вплоть до ?> считается частью незакрытой строки */ mysql_query("insert into Gefest1 (id,model,color,massa,price) values ();"); } 

All data coming from the form is stored in the $_GET['txt'] variable;

 $data = $_GET['txt']; //$data[0] - номер //$data[1] - модель //$data[2] - цвет //$data[3] - масса //$data[4] - цена 

You must first check them and then insert them into the database.
Plus, consider using mysql_query that:

This extension is deprecated since PHP 5.5.0 and will be removed in the future. Use MySQLi or PDO_MySQL instead.

  • Thanks, got it. - Alex_7