【发布时间】:2015-05-21 08:27:53
【问题描述】:
)
我正在建立一个网站,但遇到了一个错误......我有一个脚本应该将变量值上传到 sql 数据库。我正在使用or die(mysql_error()),但我什么也没得到,好像mysql正在工作,但变量没有填充......但我尝试用纯文本交换变量,以查看上传 - 这也没有工作。
这是我的代码
<?php
include("./header.php");
//Validate login
if(!isset($_SESSION['user_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("INSERT INTO user (meas_neckcircumference,meas_shoulderwidth,meas_sleevelength,meas_bicepcircumference,meas_wristcircumference,meas_bustcircumference,meas_abdomencircumference,meas_torsolength,meas_waistcircumference,meas_hipcircumference,meas_trouserrise,meas_thighcircumference,meas_kneesize,meas_trouserlength,meas_bodytype,meas_shouldertype,meas_stomachtype,meas_height,meas_weight) VALUES ('$neckcircumference','$shoulderwidth','$sleevelength','$bicepcircumference','$wristcircumference','$bustcircumference','$abdomencircumference','$torsolength','$waistcircumference','$hipcircumference','$trouserrise','$thighcircumference','$kneesize','$trouserlength','$bodytype','$shouldertype','$stomachtype','$fullheight','$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
}
?>
最好的问候:-)
【问题讨论】:
-
你不能在
insert语句中使用where,除非它的insert into select from -
停止使用已弃用的
mysql_*API。将mysqli_*或PDO与准备好的语句一起使用 -
感谢您的快速而有帮助的回复! :-) 你能详细说明一下吗? @AbhikChakraborty
-
可能您可能需要使用更新查询而不是插入...
-
我猜你的意思是用 upload 更新,你需要使用
UPDATE table () VALUES () WHERE语法来更新你的行数据。
标签: php mysql insert-into