Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SQL更新已中断_Php_Sql - Fatal编程技术网

Php SQL更新已中断

Php SQL更新已中断,php,sql,Php,Sql,我已经对这段代码进行了一段时间的故障排除,但它不起作用,我也不知道为什么。有人看到错误吗?另外,我知道没有WHERE语句,我有意更新所有记录 <?php // Connect to database $link = mysqli_connect('*****', '*****', '*****'); if (!$link) { die('Could not connect: ' . mysqli_connect_error()); } mysqli_select_db(bu

我已经对这段代码进行了一段时间的故障排除,但它不起作用,我也不知道为什么。有人看到错误吗?另外,我知道没有
WHERE
语句,我有意更新所有记录

<?php
// Connect to database
$link = mysqli_connect('*****', '*****', '*****'); 
if (!$link) { 
    die('Could not connect: ' . mysqli_connect_error()); 
} 
mysqli_select_db(bullseye);

// Varaible setting
$header = $_POST['header'];
$video = $_POST['video'];
$m_title = $_POST['m_title'];
$m_sub = $_POST['m_sub'];
$w_title = $_POST['w_title'];
$w_sub = $_POST['w_sub'];
$w_t1 = $_POST['w_t1'];
$w_t2 = $_POST['w_t2'];
$w_t3 = $_POST['w_t3'];
$w_d1 = $_POST['w_d1'];
$w_d2 = $_POST['w_d2'];
$w_d3 = $_POST['w_d3'];
$p_title = $_POST['p_title'];
$p_sub = $_POST['p_sub'];

    mysqli_query($link, "UPDATE tbl_name SET 
    header=$header, 
    video=$video, 
    mtitle=$m_title, 
    msub=$m_sub, 
    wtitle=$w_title, 
    wsub=$w_sub, 
    wt1=$w_t1, 
    wt2=$w_t2, 
    wt3=$w_t3, 
    wd1=$w_d1 
    wd2=$w_d2, 
    wd3=$w_d3, 
    ptitle=$p_title, 
    psub=$p_sub");
?>

首先,您应该使用MySQLi as进行准备,以保护自己不受MySQL注入的影响:

$mysqli = new mysqli("localhost", "my_user", "my_password", "bullseye");
$query = $mysqli->prepare("UPDATE tbl_name SET 
        header=?, 
        video=?, 
        mtitle=?, 
        msub=?, 
        wtitle=?, 
        wsub=?, 
        wt1=?, 
        wt2=?, 
        wt3=?, 
        wd1=? 
        wd2=?, 
        wd3=?, 
        ptitle=?, 
        psub=?");

$query->bind_param("ssssssssssssss, $header, $video, $m_title, $m_sub, $w_title, $w_t1, $w_t2, $w_t3, $w_d1, $w_d2, $w_d3, $p_title, $p_sub");

$query->execute();

$query->close();

$mysqli->close();

这个代码应该可以工作。如果没有,请发布错误。

看起来您需要使用变量来连接查询。不仅仅是一个大字符串。

您应该使用以下选项来选择数据库:

mysqli_select_db($link, "bullseye");

你的更新没有何处?我知道代码是可以被破解的,我只是想在清理输入之前让它工作。第一次就把它做好。酷的开发者就是这样做的。@773使用PDO和占位符。您遇到插值问题的原因与SQL注入存在的原因完全相同。@David SkyMesh添加了一个解决方案。不,双引号仍然允许php解析变量inside@Pachonk请不要鼓励易受SQL注入攻击的方法。@Pachonk,是否需要“where”语句?我想更新所有记录。你想让每一行都相同吗?@Pachonk,在数据库名称周围加引号,这样做行不通。你为什么不尝试使用底部的解决方案呢。它将更好地保护您,而且不推荐使用
MySQL
扩展。您应该使用MySQLi扩展。
mysqli_select_db($link, "bullseye");