简体   繁体   中英

Insert Into doesn't work

表架构

I want to insert data fields like: id=1, id_page=12356. I read the id_page out of an html document and am always getting this error message:

Warning: mysql_query() expects parameter 1 to be string, resource given in /mnt/webi/b0/44/53443744/htdocs/digitalpiano-test/kitareader.php on line 14 error

<?php
$con = mysql_connect("rdbms.strato.de","U1363575","asdasd123","DB1363575");
if (mysqli_connect_errno())echo "Failed to connect to MySQL: " . mysqli_connect_error();

$name = file_get_contents('kitas.html'); $array_name = explode("<tr>", $name);
foreach($array_name as $value)    {
  $value2 = explode('<a href="kitaDetails.aspx?ID=',$value);
  $value3 = explode('">',$value2[1]);
  $id_page =  $value3[0];
  $eintragen = mysql_query($con,"INSERT INTO kita_berlin (id_page) VALUES ('$id_page')") or die ("error");    
} ?>

What is wrong?

MySQL takes the query as the first parameter and the connection as the second parameter.

$eintragen = mysql_query("INSERT INTO kita_berlin (id_page) VALUES ('$id_page')", $con) or die ("error");

This would work, but you really should look at using MySQLi or PDO as MySQL is deprecated now.

Moreover, there's a much cleaner way to get the id_page attribute, by directly using GET , instead of exploding the id_page out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM