dpxua26604 2016-07-10 07:11
浏览 32

无法使用PHP连接到Ajax调用中的MY SQL DB

I am performing a DB operation after making an ajax call using php, 1) I see in fiddler that the request and response to the PHP (ajax call) are fine but and 2) I see the error "Access denied for user 'root'@'localhost' (using password: NO" in Fiddler.

I am not trying to connect to root but to a different user. Here is the view.php file where ajax call is initiated:

$.ajax({ 
 url: 'delete_entry.php',
     data: "id="+del_id,
     type: 'post',
     success: function(output) {
             alert("Success");
                  //document.getElementById("test1").innerHTML = output;
              }
});

I recieve the alert message "Success" though.

Code in delete_entry.php:

<?php

    $servername = "localhost";
    $username = "testdb";
    $password = "testdb";
    $dbname = "testts";


    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection
    if ($conn->connect_error) {
        echo "Connection Failed";
        die("Connection failed: " . $conn->connect_error);
    } 

$id=$_POST['id'];
echo $id;  // I get a proper Id here
$delete = "DELETE FROM ExpenseTable WHERE Id='"+$id+"'";
$result = mysql_query($delete) or die(mysql_error());
?>

Please help as I do not understand why the mysql db is trying to connect to root eventhough I specify the db detais as "testdb". I am able to connect to the same db with these credentials in my view.php

  • 写回答

1条回答 默认 最新

  • dragon87836215 2016-07-10 08:41
    关注

    You are not using your created DB connection when you pass the sql query to the DB. Use the mysqli_query method as below..

    mysqli_query($conn,$delete);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助