我正在尝试更新mysql多个表,虽然没有错误但是更改没有反映在mysql数据库中。如果我需要使用JOIN将查询更新放在一个字符串中,请告诉我。
我还需要
吗?mysqli_query($conn, $sqlCD) or die(mysqli_error($conn)); in the below ?
$pCDTitle = filter_has_var(INPUT_GET, 'CDTitle') ? $_GET['CDTitle']: null; // store all parameter in variable
$pCDPubName = filter_has_var(INPUT_GET, 'CDPub') ? $_GET['CDPub']: null;
$pCDYear = filter_has_var(INPUT_GET, 'CDYear') ? $_GET['CDYear']: null;
$pCDCategory = filter_has_var(INPUT_GET, 'CDCat') ? $_GET['CDCat']: null;
$pCDPrice = filter_has_var(INPUT_GET, 'CDPrice') ? $_GET['CDPrice']: null;
$pCDID = filter_has_var(INPUT_GET, 'CDID') ? $_GET['CDID']: null;
$pCDPubID = filter_has_var(INPUT_GET, 'pubID') ? $_GET['pubID']: null;
$sqlCD = mysql_query("UPDATE nmc_cd SET CDTitle='$pCDTitle', CDYear='$pCDYear', CDPrice='$pCDPrice'");
$sqlCD2 = mysql_query("UPDATE nmc_category SET catDesc='$pCDCategory'");
$sqlCD3 = mysql_query("UPDATE nmc_publisher SET pubName='$pCDPubName'");
//mysqli_query($conn, $sqlCD) or die(mysqli_error($conn));
//mysqli_query($conn, $sqlCD2) or die(mysqli_error($conn));
//mysqli_query($conn, $sqlCD3) or die(mysqli_error($conn));
mysqli_close($conn);
答案 0 :(得分:3)
您必须更改查询:
$sqlCD = mysql_query("UPDATE nmc_cd SET CDTitle=$pCDTitle, CDYear=$pCDYear, CDPrice=$pCDPrice");
$sqlCD2 = mysql_query("UPDATE nmc_category SET catDesc=$pCDCategory");
$sqlCD3 = mysql_query("UPDATE nmc_publisher SET pubName=$pCDPubName");
原因: 如果Double qoutes中的字符串""有一个像$ test这样的php变量,它的值会自动出现在字符串中但是如果你使用单个qoute''然后打印变量名称。 例如:
$test = 5;
echo "The number is $test"; //The number is 5 prints
echo 'The number is $test'; //The number is $test prints
答案 1 :(得分:1)
mysqli_query($conn, $sqlCD) or die(mysqli_error($conn)); in the below ?
$pCDTitle = filter_has_var(INPUT_GET, 'CDTitle') ? $_GET['CDTitle']: null; // store all parameter in variable
$pCDPubName = filter_has_var(INPUT_GET, 'CDPub') ? $_GET['CDPub']: null;
$pCDYear = filter_has_var(INPUT_GET, 'CDYear') ? $_GET['CDYear']: null;
$pCDCategory = filter_has_var(INPUT_GET, 'CDCat') ? $_GET['CDCat']: null;
$pCDPrice = filter_has_var(INPUT_GET, 'CDPrice') ? $_GET['CDPrice']: null;
$pCDID = filter_has_var(INPUT_GET, 'CDID') ? $_GET['CDID']: null;
$pCDPubID = filter_has_var(INPUT_GET, 'pubID') ? $_GET['pubID']: null;
$sqlCD = mysqli_query($conn,"UPDATE nmc_cd SET CDTitle='$pCDTitle', CDYear='$pCDYear', CDPrice='$pCDPrice'") or die(mysqli_error($conn));
$sqlCD2 = mysqli_query($conn,"UPDATE nmc_category SET catDesc='$pCDCategory'") or die(mysqli_error($conn));
$sqlCD3 = mysqli_query($conn,"UPDATE nmc_publisher SET pubName='$pCDPubName'") or die(mysqli_error($conn));
mysqli_close($conn);

试试这个。