php - PHP突然插入空白值
问题描述
我的表单可以很好地连接并插入我的数据库——除了没有插入表单的任何值。都是空白。请看一下我的代码,看看我是否缺少任何东西。我不记得改变任何会导致这种情况发生的事情。我只会包括表单区域(我认为这是相关的。如果看起来不错,我会包括更多可能会影响它的内容。谢谢!
(按照建议使用 PHP 和 Html 更改进行编辑)
PHP
<?php
$link = mysqli_connect("localhost","eativft2_steven","sgmexican", "eativft2_artistsdb");
array_walk_recursive( $_POST, 'mysqli_real_escape_string' );
$Fname = $_POST['Fname'];
$Lname = $_POST['Lname'];
$Website = $_POST['Website'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$Interests1 = $_POST['Interests1'];
$Interests2 = $_POST['Interests2'];
$Interests3 = $_POST['Interests3'];
$PersonalStatement = $_POST['PersonalStatement'];
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$result = mysqli_query($link,"INSERT INTO User (Fname, Lname, Website, Phone, Email, Interest1, Interest2, Interest3, PersonalStatement) VALUES('$Fname', '$Lname', '$Website', '$Phone', '$Email', '$Interests1', '$Interests2', '$Interests3', '$PersonalStatement')");
if(!$result){
echo "ERROR: Could not execute $result. " . mysqli_error($link);
} else{
echo "<h2>We got you.</h2>";
}
mysqli_close($link);
?>
HTML
<div class="modal-box" id="modal-box">
<div class="modal-content">
<span class="close"> X </span>
<h2 id="modal-title">Create a profile</h2>
<form action="/Collaborate/indexxx.php" method="post" name="User">
<label for="Fname">FIRST NAME</label><br>
<input type="text" name="Fname" placeholder="first name" required> <br>
<label for="Lname">LAST NAME</label><br>
<input type="text" name="Lname" placeholder="last name" required> <br>
<label for="Website">WEBSITE URL</label><br>
<input type="text" name="Website" placeholder="show your work" required> <br>
<label for="Phone">PHONE NUMBER</label><br>
<input type="text" name="Phone" placeholder="1234567890" required> <br>
<label for="Email">EMAIL ADDRESS</label><br>
<input type="text" name="Email" placeholder="you@awesome.com" required><br>
<label for="Interests1">INTERESTS</label><br>
<select class="Interest1" id="Interests1" name="Interests1">
<optgroup label="Audio">
<option>ADR</option>
<option>Audio Post</option>
<option>Composer</option>
<option>Electrician</option>
<option>Foley</option>
<option>Mixer</option>
<option>On-Set</option>
<option>Sound Design</option>
<option>Studio</option>
<option>Learning Audio</option>
</optgroup>
<optgroup label="Animation">
<option>Modeling</option>
<option>Motion</option>
<option>Lighting</option>
<option>Backgrounds</option>
<option>Learning Animation</option>
</optgroup>
<optgroup label="Culinary">
<option>Baker</option>
<option>Catering</option>
<option>Cuisine (specify)</option>
<option>Management</option>
<option>Learning Culinary</option>
</optgroup>
<optgroup label="Fashion">
<option>Costume</option>
<option>Design</option>
<option>Marketing</option>
<option>Tailor</option>
<option>Wardrobe</option>
<option>Learning Fashion</option>
</optgroup>
<optgroup label="Gaming">
<option>3D Artist</option>
<option>Animator</option>
<option>Art Director</option>
<option>Concept Artist</option>
<option>Environment Artist</option>
<option>Game Tester</option>
<option>Modeler</option>
<option>Motion Capture</option>
<option>Project Manager</option>
<option>Programmer</option>
<option>UI Artist</option>
<option>Learning Gaming</option>
</optgroup>
<optgroup label="Industrial Design">
<option>Product</option>
<option>Learning Industrial Design</option>
</optgroup>
<optgroup label="Interior Design">
<option>Commercial</option>
<option>Drafting</option>
<option>Environment</option>
<option>Hospitality</option>
<option>Institution</option>
<option>Residential</option>
<option>Learning Interior Design</option>
</optgroup>
<optgroup label="Photo">
<option>Commercial</option>
<option>Event</option>
<option>Fashion</option>
<option>Narrative</option>
<option>Nature</option>
<option>Real Estate</option>
<option>Sports</option>
<option>Wedding</option>
<option>Learning Photo</option>
</optgroup>
<optgroup label="Video">
<option>Cinematography</option>
<option>Director</option>
<option>Editor</option>
<option>Producer</option>
<option>Production Assistant</option>
<option>Scriptwriter</option>
<option>Learning Video</option>
</optgroup>
<optgroup label="Web Design">
<option>Developing</option>
<option>Interface</option>
<option>Typography</option>
<option>User Experience</option>
<option>Learning Web Design</option>
</optgroup>
</select>
<label for="Interests2">INTERESTS</label><br>
<select class="Interest2" id="Interests2" name="Interests2">
<optgroup label="Audio">
<option>ADR</option>
<option>Audio Post</option>
<option>Composer</option>
<option>Electrician</option>
<option>Foley</option>
<option>Mixer</option>
<option>On-Set</option>
<option>Sound Design</option>
<option>Studio</option>
<option>Learning Audio</option>
</optgroup>
<optgroup label="Animation">
<option>Modeling</option>
<option>Motion</option>
<option>Lighting</option>
<option>Backgrounds</option>
<option>Learning Animation</option>
</optgroup>
<optgroup label="Culinary">
<option>Baker</option>
<option>Catering</option>
<option>Cuisine (specify)</option>
<option>Management</option>
<option>Learning Culinary</option>
</optgroup>
<optgroup label="Fashion">
<option>Costume</option>
<option>Design</option>
<option>Marketing</option>
<option>Tailor</option>
<option>Wardrobe</option>
<option>Learning Fashion</option>
</optgroup>
<optgroup label="Gaming">
<option>3D Artist</option>
<option>Animator</option>
<option>Art Director</option>
<option>Concept Artist</option>
<option>Environment Artist</option>
<option>Game Tester</option>
<option>Modeler</option>
<option>Motion Capture</option>
<option>Project Manager</option>
<option>Programmer</option>
<option>UI Artist</option>
<option>Learning Gaming</option>
</optgroup>
<optgroup label="Industrial Design">
<option>Product</option>
<option>Learning Industrial Design</option>
</optgroup>
<optgroup label="Interior Design">
<option>Commercial</option>
<option>Drafting</option>
<option>Environment</option>
<option>Hospitality</option>
<option>Institution</option>
<option>Residential</option>
<option>Learning Interior Design</option>
</optgroup>
<optgroup label="Photo">
<option>Commercial</option>
<option>Event</option>
<option>Fashion</option>
<option>Narrative</option>
<option>Nature</option>
<option>Real Estate</option>
<option>Sports</option>
<option>Wedding</option>
<option>Learning Photo</option>
</optgroup>
<optgroup label="Video">
<option>Cinematography</option>
<option>Director</option>
<option>Editor</option>
<option>Producer</option>
<option>Production Assistant</option>
<option>Scriptwriter</option>
<option>Learning Video</option>
</optgroup>
<optgroup label="Web Design">
<option>Developing</option>
<option>Interface</option>
<option>Typography</option>
<option>User Experience</option>
<option>Learning Web Design</option>
</optgroup>
</select>
<label for="Interests3">INTERESTS</label><br>
<select class="Interest3" id="Interests3" name="Interests3">
<optgroup label="Audio">
<option>ADR</option>
<option>Audio Post</option>
<option>Composer</option>
<option>Electrician</option>
<option>Foley</option>
<option>Mixer</option>
<option>On-Set</option>
<option>Sound Design</option>
<option>Studio</option>
<option>Learning Audio</option>
</optgroup>
<optgroup label="Animation">
<option>Modeling</option>
<option>Motion</option>
<option>Lighting</option>
<option>Backgrounds</option>
<option>Learning Animation</option>
</optgroup>
<optgroup label="Culinary">
<option>Baker</option>
<option>Catering</option>
<option>Cuisine (specify)</option>
<option>Management</option>
<option>Learning Culinary</option>
</optgroup>
<optgroup label="Fashion">
<option>Costume</option>
<option>Design</option>
<option>Marketing</option>
<option>Tailor</option>
<option>Wardrobe</option>
<option>Learning Fashion</option>
</optgroup>
<optgroup label="Gaming">
<option>3D Artist</option>
<option>Animator</option>
<option>Art Director</option>
<option>Concept Artist</option>
<option>Environment Artist</option>
<option>Game Tester</option>
<option>Modeler</option>
<option>Motion Capture</option>
<option>Project Manager</option>
<option>Programmer</option>
<option>UI Artist</option>
<option>Learning Gaming</option>
</optgroup>
<optgroup label="Industrial Design">
<option>Product</option>
<option>Learning Industrial Design</option>
</optgroup>
<optgroup label="Interior Design">
<option>Commercial</option>
<option>Drafting</option>
<option>Environment</option>
<option>Hospitality</option>
<option>Institution</option>
<option>Residential</option>
<option>Learning Interior Design</option>
</optgroup>
<optgroup label="Photo">
<option>Commercial</option>
<option>Event</option>
<option>Fashion</option>
<option>Narrative</option>
<option>Nature</option>
<option>Real Estate</option>
<option>Sports</option>
<option>Wedding</option>
<option>Learning Photo</option>
</optgroup>
<optgroup label="Video">
<option>Cinematography</option>
<option>Director</option>
<option>Editor</option>
<option>Producer</option>
<option>Production Assistant</option>
<option>Scriptwriter</option>
<option>Learning Video</option>
</optgroup>
<optgroup label="Web Design">
<option>Developing</option>
<option>Interface</option>
<option>Typography</option>
<option>User Experience</option>
<option>Learning Web Design</option>
</optgroup>
</select>
<br>
<label for="PersonalStatement">PERSONAL STATEMENT</label><br>
<textarea name="PersonalStatement" id="PersonalStatement" minlength="800" maxlength="1500" rows="5" cols="20" placeholder="Let us get to know you better." required></textarea><br />
<button id="submit" name="submit"> Submit my profile </button>
</form>
</div>
</div>
解决方案
扩展 Sohrab Yousefi 的答案,您可以通过递归迭代 $_POST 来缩短代码以使用 mysqli_real_escape_string()。
array_walk_recursive( $_POST, 'mysqli_real_escape_string' );
请参阅此处以供参考。
希望这可以帮助。
推荐阅读
- python - boto3.client('S3') 返回什么?
- java - 如何在使用 openCSV 写入 .csv 文件时添加分隔符
- ruby-on-rails - 如何在 Rails 中将 url 路径传递给 form_with partial?
- machine-learning - 如何在 sklearn:: LGBMClassifier() 中为 LightGBM 分类器的 feature_importances_ 中设置“增益”作为特征重要性度量
- html - (HTML) 如何在不缩小尺寸的情况下并排插入两张图片?
- python - 字典文字中是否可以有可选键?
- jquery - 使用 jquery 切换按钮回复和编辑以在单击时显示表单的问题
- html - 确保 HTML iframe 不会变得比正方形高
- r - 如何遍历目录以处理光栅文件而不使用 R 中的应用系列
- python - 卷积神经网络中的图像预处理在 Keras 与 Tflearn 中的精度较低