当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - Php form Update database not working

问题描述:

Cant seem to update my SQL through a HTML form using PHP, can someone help

if (isset($_POST['update'])) {

$UpdateQuery = "UPDATE nmc_cd, nmc_category, nmc_publisher SET " .

"nmc_cd.CDTitle='$_POST[CDTitle]', " .

"nmc_cd.CDYear='$_POST[CDYear]', " .

"nmc_cd.CDPrice='$_POST[CDPrice]', " .

"nmc_category.catDesc='$_POST[catDesc]', " .

"nmc_publisher.pubName='$_POST[pubName]' " .

"WHERE CDID='$_POST[CDID]'";

}

is my SQL query the problem??

网友答案:

Try printing out the sql query from your php page, copying it and running it directly on the database. Does it succeed?

网友答案:

Well, in your code, you're never actually performing the query (with mysql_query($query_string)). Also, you were missing the closing } if your if statement. If all that is fine, then your SQL query looks okay although I would try to run it against the DB (your interpolated string) to make sure the SQL generated is good.

You'll also want to pass your form variables through mysql_real_escape_string to make sure that you are avoiding SQL injection attacks (or just malformed SQL in your case). See the docs.

网友答案:

try

if (isset($_POST['update'])){ 
$UpdateQuery = "UPDATE  nmc_cd, nmc_category, nmc_publisher SET nmc_cd.CDTitle='"; $UpdateQuery .= $_POST[CDTitle]."', nmc_cd.CDYear='".$_POST[CDYear]."', nmc_cd.CDPrice='"; $UpdateQuery .= $_POST[CDPrice]."',nmc_category.catDesc='";
$UpdateQuery .= $_POST[catDesc]."',nmc_publisher.pubName='";
$UpdateQuery .= $_POST[pubName]."' WHERE CDID='".$_POST[CDID]."'"; //run query
}

or just transfer all the Post variables to $something and use that inside the query

分享给朋友:
您可能感兴趣的文章:
随机阅读: