数据库
首页 > 数据库> > php-mysql_query字符串未更新

php-mysql_query字符串未更新

作者:互联网

我的代码遇到了一些麻烦:

<?php
include("./header.php");
//Validate login
if(!isset($_SESSION['user_id']) && !isset($_SESSION['invite_id'])) {
    echo "<meta http-equiv=\"refresh\" content=\"0; url=/\">";
}
else {
    $user_login = $_SESSION['user_login'];
    //Get whether user clicked submit
    $submitSuitDesignCredentials = $_POST['submitSuitDesignCredentials'];
    if (isset($submitSuitDesignCredentials)) {
        //Store user input in variables and remove unwanted characters
       $neckcircumference = preg_replace('#[^0-9.,]#i','', $_POST['neckcircumference']);
       $shoulderwidth = preg_replace('#[^0-9.,]#i','', $_POST['shoulderwidth']);
       $sleevelength = preg_replace('#[^0-9.,]#i','', $_POST['sleevelength']);
       $bicepcircumference = preg_replace('#[^0-9.,]#i','', $_POST['bicepcircumference']);
       $wristcircumference = preg_replace('#[^0-9.,]#i','', $_POST['wristcircumference']);
       $bustcircumference = preg_replace('#[^0-9.,]#i','', $_POST['bustcircumference']);
       $lowerribcircumference = preg_replace('#[^0-9.,]#i','', $_POST['lowerribcircumference']);
       $abdomencircumference = preg_replace('#[^0-9.,]#i','', $_POST['abdomencircumference']);
       $torsolength = preg_replace('#[^0-9.,]#i','', $_POST['torsolength']);
       $waistcircumference = preg_replace('#[^0-9.,]#i','', $_POST['waistcircumference']);
       $hipcircumference = preg_replace('#[^0-9.,]#i','', $_POST['hipcircumference']);
       $trouserrise = preg_replace('#[^0-9.,]#i','', $_POST['trouserrise']);
       $thighcircumference = preg_replace('#[^0-9.,]#i','', $_POST['thighcircumference']);
       $kneesize = preg_replace('#[^0-9.,]#i','', $_POST['kneesize']);
       $trouserlength = preg_replace('#[^0-9.,]#i','', $_POST['trouserlength']);
       $bodytype = preg_replace('#[^A-Za-z]#i','', $_POST['bodytype']);
       $shouldertype = preg_replace('#[^A-Za-z]#i','', $_POST['shouldertype']);
       $stomachtype = preg_replace('#[^A-Za-z]#i','', $_POST['stomachtype']);
       $fullheight = preg_replace('#[^0-9.,]#i','', $_POST['fullheight']);
       $weight = preg_replace('#[^0-9.,]#i','', $_POST['weight']);
        //Upload to database
        mysql_query("UPDATE user SET meas_neckcircumference='$neckcircumference',meas_shoulderwidth='$shoulderwidth',meas_sleevelength='$shoulderwidth',meas_bicepcircumference='$bicepcircumference',meas_wristcircumference='$wristcircumference',meas_bustcircumference='$bustcircumference',meas_abdomencircumference='$bustcircumference',meas_torsolength='$torsolength',meas_waistcircumference='$waistcircumference',meas_hipcircumference='$hipcircumference',meas_trouserrise='$trouserrise',meas_thighcircumference='$thighcircumference',meas_kneesize='$kneesize',meas_trouserlength='$trouserlength',meas_bodytype='$bodytype',meas_shouldertype='$shouldertype',meas_stomachtype='$stomachtype',meas_height='$fullheight',meas_weight='$weight') WHERE email='$user_login'") or die(mysql_error());
    }
    ?>
        <div class="headlineContainer">
            <h1>Din målprofil</h1>
        </div>
        <h2>Kropsmål</h2>
        <form id="measurementProfile" action="" method="POST">
        <div class="subContentContainer">
            <table>
               <tr>
                    <td><h4>Hals omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="neckcircumference" name="neckcircumference"></input></td>
                    <td><h4>Skulderbredde</h4></td>
                    <td><input type="text" placeholder="CM" id="shoulderwidth" name="shoulderwidth"></input></td>
                    <td><h4>Ærmelængde</h4></td>
                    <td><input type="text" placeholder="CM" id="sleevelength" name="sleevelength"></input></td>
                </tr>
                <tr>
                    <td><h4>Bicep omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="bicepcircumference" name="bicepcircumference"></input></td>
                    <td><h4>Håndled omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="wristcircumference" name="wristcircumference"></input></td>
                    <td><h4>Bryst omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="bustcircumference" name="bustcircumference"></input></td>
                </tr>
                <tr>
                    <td><h4>Bundribben omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="lowerribcircumference" name="lowerribcircumference"></input></td>
                    <td><h4>Mave omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="abdomencircumference" name="abdomencircumference"></input></td>
                    <td><h4>Overkrop længde</h4></td>
                    <td><input type="text" placeholder="CM" id="torsolength" name="torsolength"></input></td>
                </tr>
                <tr>
                    <td><h4>Talje omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="waistcircumference" name="waistcircumference"></input></td>
                    <td><h4>Hofte omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="hipcircumference" name="hipcircumference"></input></td>
                    <td><h4>Bukseskridt højde</h4></td>
                    <td><input type="text" placeholder="CM" id="trouserrise" name="trouserrise"></input></td>
                </tr>
                <tr>
                    <td><h4>Lår omkreds</h4></td>
                    <td><input type="text" placeholder="CM" id="thighcircumference" name="thighcircumference"></input></td>
                    <td><h4>Knæ størrelse</h4></td>
                    <td><input type="text" placeholder="CM" id="kneesize" name="kneesize"></input></td>
                    <td><h4>Benlængde</h4></td>
                    <td><input type="text" placeholder="CM" id="trouserlength" name="trouserlength"></input></td>
                </tr>
                <tr>
                    <td><h4>Højde</h4></td>
                    <td><input type="text" placeholder="CM" id="fullheight" name="fullheight"></input></td>
                    <td><h4>Vægt</h4></td>
                    <td><input type="text" placeholder="KG" id="weight" name="weight"></input></td>
                </tr>
            </table>
        </div>
        <h2>Kropstype</h2>
        <div class="subContentContainer">
            <table>
                <tr>
                    <td><h4>Figur</h4></td>
                    <td><input type="radio" id="bodytypeRadio1" name="bodytype" value="slim"><label for="bodytypeRadio1">Flad krop</label></td>
                    <td><input type="radio" id="bodytypeRadio2" name="bodytype" value="average"><label for="bodytypeRadio2">Normal krop</label></td>
                    <td><input type="radio" id="bodytypeRadio3" name="bodytype" value="slightlyoverweight"><label for="bodytypeRadio3">Lidt overvægtig krop</label></td>
                    <td><input type="radio" id="bodytypeRadio4" name="bodytype" value="overweight"><label for="bodytypeRadio4">Overvægtig krop</label></td>
                    <td><input type="radio" id="bodytypeRadio5" name="bodytype" value="muscular"><label for="bodytypeRadio5">Muskuløs krop</label></td>
                </tr>
                <tr>
                    <td><h4>Skuldre</h4></td>
                    <td><input type="radio" id="shouldertypeRadio1" name="shouldertype" value="highshoulders"><label for="shouldertypeRadio1">Høje skuldre</label></td>
                    <td><input type="radio" id="shouldertypeRadio2" name="shouldertype" value="average"><label for="shouldertypeRadio2">Normale skuldre</label></td>
                    <td><input type="radio" id="shouldertypeRadio3" name="shouldertype" value="lowshoulders"><label for="shouldertypeRadio3">Lave skuldre</label></td>
                </tr>
                <tr>
                    <td><h4>Mave</h4></td>
                    <td><input type="radio" id="stomachtypeRadio1" name="stomachtype" value="plain"><label for="stomachtypeRadio1">Flad mave</label></td>
                    <td><input type="radio" id="stomachtypeRadio2" name="stomachtype" value="slightlyconvex"><label for="stomachtypeRadio2">Lidt konveks mave</label></td>
                    <td><input type="radio" id="stomachtypeRadio3" name="stomachtype" value="convex"><label for="stomachtypeRadio3">Konveks mave</label></td>
                </tr>
            </table>
        </div>
        <input type="submit" name="submitMeasurementProfile" id="submit" value="Opdater dine mål"></input>
        </form>
<?php
}
?>

这里的问题是

mysql_query("UPDATE user SET meas_neckcircumference='$neckcircumference',meas_shoulderwidth='$shoulderwidth',meas_sleevelength='$shoulderwidth',meas_bicepcircumference='$bicepcircumference',meas_wristcircumference='$wristcircumference',meas_bustcircumference='$bustcircumference',meas_abdomencircumference='$bustcircumference',meas_torsolength='$torsolength',meas_waistcircumference='$waistcircumference',meas_hipcircumference='$hipcircumference',meas_trouserrise='$trouserrise',meas_thighcircumference='$thighcircumference',meas_kneesize='$kneesize',meas_trouserlength='$trouserlength',meas_bodytype='$bodytype',meas_shouldertype='$shouldertype',meas_stomachtype='$stomachtype',meas_height='$fullheight',meas_weight='$weight') WHERE email='$user_login'") or die(mysql_error());

最近有人告诉我,我应该使用上面的代码行,并且应该可以工作……但是事实并非如此! die不会返回错误,并且行本身也不会上传到db.

最好的祝福,
胜利者

解决方法:

您的查询永远不会运行.您正在检查$_POST [‘submitSuitDesignCredentials’],但您的表单正在发送$_POST [‘submitMeasurementProfile’]

标签:sql-update,mysql,php
来源: https://codeday.me/bug/20191028/1951435.html