[英]PHP code with variables not UPDATING MySQL db
I am a newbie-ish to MySQL/PHP (using XAMPP).我是 MySQL/PHP 的新手(使用 XAMPP)。 I have tried every recommendation I have seen here for code but nothing seems to work....
我已经尝试了我在这里看到的所有代码建议,但似乎没有任何效果......
I have a 3-column, 19 row table of textboxes (row1Field1, Row1, field2, row1Field3, etc.)我有一个 3 列 19 行的文本框表(row1Field1、Row1、field2、row1Field3 等)
I am trying to UPDATE my database for those records where there will be records for each row (almost)我正在尝试为那些记录更新我的数据库,其中每行都有记录(几乎)
I KNOW THERE IS NO REAL SQL INJECTION PROTECTION.我知道没有真正的 SQL 注入保护。 That is not an issue at this point.
目前这不是问题。 This is all opn my personal laptop & most likely will never see the Internet.
这都是我的个人笔记本电脑,很可能永远不会看到互联网。
Here is my coe, 99% works everytime.这是我的 coe,每次都有 99% 的工作。 The UPDATE does not.
UPDATE 没有。
<?php require '../connect/connect.php'; //connects the db (10 pages so far - all works
// Start the session
session_start();
$wk2Use = $_SESSION["wk2Use"];
?>
<html>
<body>
<?php
$f="";
$s=0;
$p=0;
for($i=1; $i <= 19; $i++) {
$f = "gm" . $i . "Fav";
$s = "gm" . $i . "Sprd";
$p = "gm" . $i . "Pts";
$f = htmlspecialchars($_POST[$f]);
$s = htmlspecialchars($_POST[$s]);
$p = htmlspecialchars($_POST[$p]);
if (!empty($f)) {
//This displays the correct data!
echo 'Wk-' . $wk2Use . ' ' . $f . ' ' . $s . ' ' . $p . '<br>';
//This does NOT work
$sql = ("USE bbschdefs; UPDATE bbschdefs SET sSchFav='".$f."', sSchSprd=$s, sSchOUPts=$p
WHERE ((sSchVTAbrv='".$f."' OR sSchHTAbrv='".$f."') AND schWk=$wk2Use )");
$result = mysqli_query($dbconn,$sql);
}
}
$i=0;
include '../predictions/predict.php'
?>
</body>
</html>
I'd have to guess it's because your variable $wk2Use
is not properly being added to your where clause我不得不猜测这是因为您的变量
$wk2Use
没有正确添加到您的 where 子句中
WHERE ((sSchVTAbrv='".$f."' OR sSchHTAbrv='".$f."') AND schWk=$wk2Use )
Should be应该
WHERE ((sSchVTAbrv='".$f."' OR sSchHTAbrv='".$f."') AND schWk='{$wk2Use}' )
OR或者
WHERE ((sSchVTAbrv='".$f."' OR sSchHTAbrv='".$f."') AND schWk='".$wk2Use."' )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.