gpt4 book ai didi

php - 插入不起作用?

转载 作者:行者123 更新时间:2023-11-29 23:08:09 26 4
gpt4 key购买 nike

我有一个简单的 INSERT 不起作用。 php/mySQL 专家可以快速扫描一下吗?当我处理代码时,它确实说“成功”,即“添加了 1 条记录”和“成功创建目录” - 但我在服务器上没有看到新目录,并且它在数据库中添加了一条记录,但所有字段都是空?

include("_inc/config.php"); 

$sql = "INSERT INTO members (id, active, namefirst, namelast, email, username, password, birthyear, gender, country, postalcode, education, dimension, referredby, pic_profile, pic_background, origination, customerid) VALUES ('','$_POST[active]','$_POST[namefirst]','$_POST[namelast]','$_POST[email]','$_POST[username]','$_POST[password]','$_POST[birthyear]','$_POST[gender]','$_POST[country]','$_POST[postalcode]','$_POST[education]','$_POST[dimension]','$_POST[referredby]','$_POST[pic_profile]','$_POST[pic_background]','$_POST[origination]','$_POST[customerid]')";

$newdir=$_POST['username'];

if (!mysql_query($sql,$con)){
die('Error: ' . mysql_error());
}

echo "1 record added";
echo "<br><br>";

// Build Directories
mkdir("../".$newdir,0777);
chmod("../".$newdir,0777);
mkdir("../".$newdir."/assets/",0777);
chmod("../".$newdir."/assets/",0777);

if("../".mkdir($newdir, 0777, true))
{
echo 'successfully created directory';
}
else
{
die('problem creating directory');
}

mysql_close($con)

表格

<form role="form" name="form" action="mpx_signup_process.php">
<div class="form-group">
<label for="nameandemail">Name and Email</label>
<input name="namefirst" class="form-control" placeholder="First Name">
</div>
<div class="form-group">
<input name="namelast" class="form-control" placeholder="Last Name">
</div>
<div class="form-group">
<input name="email" type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
</div>
<div class="form-group"><hr></div>
<div class="form-group">
<label for="accountinfo">Account Information</label>
<input name="username" class="form-control" id="exampleInputPassword1" placeholder="User Name">
</div>
<div class="form-group">
<input name="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<div class="form-group">
<input name="password" class="form-control" id="exampleInputPassword1" placeholder="Password Repeat">
</div>
<hr />
<div class="form-group">
<label for="personalinfo">Personal Information</label>
<h3>Country</h3>
<select name="country" class="form-control">
<option value="USA">United States</option>
<option value="UMI">United States Minor Outlying Islands</option>
<option value="USA">- - - - - -</option>
<option value="ALA">Åland Islands</option>
<option value="ALB">Albania</option>
<option value="DZA">Algeria</option>
<option value="ASM">American Samoa</option>
</select>
</div>

<div class="form-group">
<label for="referredby">Postal Code</label>
<input name="postalcode" class="form-control" id="exampleInputPostalCode" placeholder="Postal Code">
</div>
<div class="form-group">
<label for="gender">Gender</label>
<div class="radio">
<label>
<input type="radio" name="gender" id="optionsRadios4" value="01">
Male
</label>
&nbsp;&nbsp;
<label>
<input type="radio" name="gender" id="optionsRadios5" value="02">
Female
</label>
&nbsp;&nbsp;
<label>
<input type="radio" name="gender" id="optionsRadios6" value="03">
Other
</label>
</div>
</div>

<div class="form-group">
<label for="dateofbirth">Date of Birth</label>
<select name="birthyear" class="form-control">
<?php
for($i = 2010 ; $i > 1920; $i--){
echo "<option value=".$i.">$i</option>";
}
?>
</select>
</div>

<div class="form-group">
<label for="education">Education</label>
<select name="education" class="form-control">
<option value="01">Pre High School</option>
<option value="02">High School</option>
<option value="03">Some College</option>
<option value="04">College Graduate</option>
<option value="05">Graduate Degree</option>
</select>
</div>

<div class="form-group">
<label for="referredby">Referred By</label>
<input name="referredby" class="form-control" id="exampleInputreferredby" placeholder="Referred By">
</div>


<input type="hidden" name="active" value="no">
<input type="hidden" name="dimension" value="00">
<input type="hidden" name="pic_profile" value="mpx_profilepic.jpg">
<input type="hidden" name="pic_background" value="mpx_bsckgroundpic.jpg">
<?php
$date = date('l jS \of F Y h:i:s A');
?>
<input type="hidden" name="origination" value="<?php echo $date; ?>">

<button type="submit" class="btn btn-default">Submit</button>
</form>

最佳答案

在表单中添加method="POST"

<form role="form" name="form" method="POST" action="mpx_signup_process.php">

因为 $_POST["username"] 为空,所以新目录名称为空,因此我认为不创建它的原因。

我还建议添加一项检查以确定记录是否确实已插入。上面的代码总是返回 "1 record added" 这是不正确的。使用类似 mysql_rows_affected 的内容但使用 mysqli 或 PDO 更合适。

if(mysql_affected_rows() > 0)
{
echo "1 record added";
echo "<br><br>";

// Build Directories
mkdir("../".$newdir,0777);
chmod("../".$newdir,0777);
mkdir("../".$newdir."/assets/",0777);
chmod("../".$newdir."/assets/",0777);

}
else
{
echo "No records added";
}

关于php - 插入不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28206614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com