0

$result = mysql_query("SELECT max(Cardex_ID) FROM cardex WHERE Onderdeel_ID=$Onderdeel_ID"); if (!$result) { die('无法查询:' . mysql_error()); }

    $Cardex_ID = mysql_result($result, 0, 'Cardex_ID');

    echo $Cardex_ID;

    mysql_query("UPDATE cardex SET PADate=$PAdate, PAhours=$PAhours, PAcycles=$PAcycles, PAlanding=$PAlanding WHERE Cardex_ID=$Cardex_ID");
4

1 回答 1

1

我建议您使用PDO连接到您的数据库,而不是使用该通用连接。此外,如果 $Onderdeel_ID 是一个数字,则您不需要""

   $db = new PDO ('mysql:host=localhost;dbname=DB_NAME','DB_USER','DB_PASS');
    $sql = 'SELECT max(Cardex_ID) FROM cardex WHERE Onderdeel_ID='. $Onderdeel_ID;
    $result = $db->query($sql)->fetch(PDO::FETCH_ASSOC);
    echo 'SELECT';
    if (!$result) {
      echo 'RESULT';
    }

注意:同样有效和首选的是使用该语句prepare来防止 SQL 注入:

    $db = new PDO ('mysql:host=localhost;dbname=DB_NAME','DB_USER','DB_PASS');
    $db->prepare ( 'SELECT max(Cardex_ID) FROM cardex WHERE Onderdeel_ID=:Onderdeel_ID');
    $result = $db->execute( array( ':Onderdeel_ID' => $Onderdeel_ID ) );

此外,如果您一直遇到问题,请检查您$Onderdeel_ID是否已通过。一个简单的var_dump($Onderdeel_ID);就可以了

于 2012-12-03T09:51:24.917 回答