droxy80248
2015-05-22 09:54
浏览 157
已采纳

将数据插入表中不起作用,为什么?

I would like to insert data into table sortiranje1 after I have done with my first $sql statement. For some reason, there are no inserted records into table sortiranje1. Also there are no errors.

$sql = "SELECT * FROM komentari WHERE IDteksta=$b and Tip='vest' and Dodaj='da'";
$result = mysqli_query($conn, $sql);
$zbir=0;
while($row = mysqli_fetch_assoc($result)) {
    $zbir=$zbir+$row['Rezultat'];
}
//echo "zbir lajkova je " . $zbir . " a indeks vesti je " . $b; 



$upis = "INSERT INTO sortiranje1 (IDteksta)             
    VALUES ('$b')";

Also, like you can see I have echo that var $b, and it's ok, but I have no idea why it's not inserted into table! Here is my code for table:

$db_selected = mysqli_select_db($conn,'neprodaji');
$sql = "CREATE TABLE IF NOT EXISTS sortiranje1 (
    ID INT(9) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    IDteksta INT(9) NOT NULL,
    Rezultat INT(9) NOT NULL)";

图片转代码服务由CSDN问答提供 功能建议

我想在完成第一个$ sql语句后将数据插入表sortiranje1。 由于某种原因,表sortiranje1中没有插入记录。 也没有错误。

  $ sql =“SELECT * FROM komentari WHERE IDteksta = $ b and Tip ='vest'和Dodaj ='da'”; 
 $  result = mysqli_query($ conn,$ sql); 
 $ zbir = 0; 
while($ row = mysqli_fetch_assoc($ result)){
 $ zbir = $ zbir + $ row ['Rezultat']; 
} \  n // echo“zbir lajkova je”。  $ zbir。  “一个私人的”。  $ B;  
 
 
 
 $ upis =“INSERT INTO sortiranje1(IDteksta)
 VALUES('$ b')”; 
   
 
 

此外,和你一样 可以看到我有回声var $ b,没关系,但我不知道为什么它没有插入表中! 这是我的表代码:

  $ db_selected = mysqli_select_db($ conn,'neprodaji'); 
 $ sql =“CREATE TABLE IF NOT EXISTS sortiranje1(
 ID)  INT(9)UNSIGNED AUTO_INCREMENT PRIMARY KEY,
 IDteksta INT(9)NOT NULL,
 Rezultat INT(9)NOT NULL)“; 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dopcpc9207 2015-05-22 10:11
    已采纳

    the problem you are facing because you are not executing your insert query, so write this line after insert query:-

    mysqli_query($conn, $upis);
    

    Note:- if you want to put some check (condition) based on this insert query then assign it to a variable like $result = mysqli_query($conn, $upis); and use that variable for check. it will be Boolean type.

    点赞 打赏 评论
  • doulong6761 2015-05-22 09:56

    IDteksta is an integer field - but by using quotes, you turn it into a string. just remove the quotes:

    INSERT INTO sortiranje1 (IDteksta)             
    VALUES ($b)
    
    点赞 打赏 评论

相关推荐 更多相似问题