无法在php mysql中更新我的数据库

时间:2014-07-24 10:40:00

标签: php mysql database

您好我无法让我的数据库更新。如果我在mySQL查询框中运行它,查询可以工作,但不能在我的PHP代码中... 我没有得到任何错误,但它不会更新。 有人可以帮助我吗?

的PHP

if(isset($_POST['btnSignup']))
{
$con=mysqli_connect('test', 'test', 'test', 'test');
    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    if (isset($name)) {
        mysqli_query($con,
         "UPDATE `tbl_klant` \n"
. " SET `kl_aanspreek`= \'$aansp\',\n"
. " `kl_voornaam`= \'$voornaam\',\n"
. " `kl_achternaam`= \'$achternaam\',\n"
. " `kl_email`= \'$email\',\n"
. " `kl_gsm`= $gsm ,\n"
. " `kl_fax`= $fax ,\n"
. " `kl_telefoon`= $telefoon,\n"
. " `kl_straat`= \'$straat\',\n"
. " `kl_postcode`= $post,\n"
. " `kl_gemeente`= \'$gemeente\',\n"
. " `kl_huisnr`= $huisnr,\n"
. " `kl_firmanaam`= \'$firma\',\n"
. " `kl_btwnr`= \'$btwnr\'\n"
. "WHERE `klant_id`= $name");

    }else {
        echo "werkt niet";
    }

    echo "voorbij query";

    mysqli_close($con);
        }

HTML

<form name="regForm" method="post" action="<?php $_PHP_SELF ?>" onsubmit="return(validateRegistreer());">
<table width="400" border="0" cellspacing="1" cellpadding="2">
    <tr>
    <td >Aanspreek titel</td>
    <td><select name="kl_aanspreek" id="kl_aanspreek">
          <option value="Dhr.">Dhr.</option>
          <option value="Mevr.">Mevr.</option>
        </select>
    </td>
    </tr>
    <tr>
    <td >Voornaam *</td>
    <td><input name="kl_voornaam" type="text" id="kl_voornaam" required  value="<?php echo $voornaam ?>"></td>
    </tr>
    <tr>
    <td >Achternaam *</td>
    <td><input name="kl_achternaam" type="text" id="kl_achternaam" required value="<?php echo $achternaam ?>"></td>
    </tr>
  

表格的代码重复

    <tr>
    <td width="100"> </td>
    <td>
    <input name="btnSignup" type="submit" id="btnSignup" value="Wijzig" >
    </td>
    </tr>
</table>

2 个答案:

答案 0 :(得分:0)

尝试:

if(isset($_POST['btnSignup']))
{
$con=mysqli_connect('test', 'test', 'test', 'test');
    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    if (isset($name)) {
        if(!mysqli_query($con,
         "UPDATE `tbl_klant` "
. " SET `kl_aanspreek`= '$aansp',"
. " `kl_voornaam`= '$voornaam',"
. " `kl_achternaam`= '$achternaam',"
. " `kl_email`= '$email',"
. " `kl_gsm`= $gsm ,"
. " `kl_fax`= $fax ,"
. " `kl_telefoon`= $telefoon,"
. " `kl_straat`= '$straat',"
. " `kl_postcode`= $post,"
. " `kl_gemeente`= '$gemeente',"
. " `kl_huisnr`= $huisnr,"
. " `kl_firmanaam`= '$firma',"
. " `kl_btwnr`= '$btwnr'"
. " WHERE `klant_id`= $name")){
    echo("Error description: " . mysqli_error($con));
}

    }else {
        echo "werkt niet";
    }

    echo "voorbij query";

    mysqli_close($con);
        }

答案 1 :(得分:0)

尝试下一步

$query = "UPDATE tbl_klant SET kl_aanspreek= '$aansp', 
kl_voornaam= '$voornaam'
kl_achternaam= '$achternaam',
kl_email= '$email',
kl_gsm= '$gsm' ,
kl_fax= '$fax' ,
kl_telefoon= '$telefoon',
kl_straat= '$straat',
kl_postcode= '$post',
kl_gemeente= '$gemeente',
kl_huisnr= '$huisnr',
kl_firmanaam= '$firma',
kl_btwnr= '$btwnr'
WHERE klant_id= '$name'";

mysqli_query($con,$query);