好的,大家好,我一直在努力寻找和测试我的代码,以使其正常工作,但是我总是遇到错误。问题是用户将输入他们的姓名,姓氏,电子邮件和密码,但是在提交时会出现错误,并且错误是:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\register.php on line 9
这是我的register.php:
try {
$connect = new PDO( "mysql: host = 'localhost';", 'root', '' );
$connect->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sqlQuery = "INSERT INTO users_details.details ( firstname, lastname, email, password ) VALUES (
'$_POST['firstName']',
'$_POST['lastName']',
'$_POST['email']'
'$_POST['password']' )";
$connect->exec($sqlQuery);
echo 'Data submitted successfully.';
}
catch(PDOException $e) {
echo $e->getMessage();
}
这就是我的数据库结构:http : //prntscr.com/a8uc2b
我还可以向您展示我的表格:
<!DOCTYPE html>
<!-- Form Name -->
<legend>
Data Submission
</legend>
<!-- First Name -->
<div class="form-group has-feedback">
<label class="col-md-4 control-label" for="firstName">
</label>
<div class="col-md-4">
<input id="firstName" name="firstName" pattern="[A-z]+" maxlength="12" data-error="Enter valid first name only." placeholder="First Name" class="form-control input-md" required="" type="text">
<span class="glyphicon form-control-feedback" aria-hidden="true">
</span>
<div class="help-block with-errors">
</div>
</div>
</div>
<!-- Last Name -->
<div class="form-group has-feedback">
<label class="col-md-4 control-label" for="lastName">
</label>
<div class="col-md-4">
<input id="lastName" name="lastName" pattern="[A-z]+" maxlength="12" data-error="Enter valid last name only." placeholder="Last Name" class="form-control input-md" required="" type="text">
<span class="glyphicon form-control-feedback" aria-hidden="true">
</span>
<div class="help-block with-errors">
</div>
</div>
</div>
<!-- E-Mail -->
<div class="form-group has-feedback">
<label class="col-md-4 control-label" for="email">
</label>
<div class="col-md-4">
<input id="email" name="email" maxlength="16" placeholder="E-Mail" class="form-control input-md" required="" type="email">
<span class="glyphicon form-control-feedback" aria-hidden="true">
</span>
<div class="help-block with-errors">
</div>
</div>
</div>
<!-- Password input-->
<div class="form-group has-feedback">
<label class="col-md-4 control-label" for="password">
</label>
<div class="col-md-4">
<input id="password" name="password" pattern="[A-z0-9!@#$%^*]+" maxlength="25" placeholder="Password" class="form-control input-md" required="" type="password">
<span class="glyphicon form-control-feedback" aria-hidden="true">
</span>
<div class="help-block with-errors">
</div>
</div>
</div>
<!-- Password confirm input-->
<div class="form-group has-feedback">
<label class="col-md-4 control-label" for="passwordConfirm">
</label>
<div class="col-md-4">
<input id="passwordConfirm" name="passwordConfirm" data-match="#password" placeholder="Confirm Password" class="form-control input-md" required="" type="password">
<span class="glyphicon form-control-feedback" aria-hidden="true">
</span>
<div class="help-block with-errors">
</div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit">
</label>
<div class="col-md-4">
<button id="submit" name="submit" class="btn btn-primary" type="submit">
Submit
</button>
</div>
</div>
</fieldset>
是否可以将要插入数据库的值设置为用户以表格形式输入的值?因为当我仍然需要声明其他内容并使我的代码更长时,我便获得了OC,是的,我接受建议和批评。我在这方面还很陌生,但我真的很喜欢效率。爱情<3
我认为以下解决方案应该有效
$sqlQuery = "INSERT INTO users_details.details ( firstname, lastname, email, password ) VALUES ('".
$_POST['firstName'] ."','".
$_POST['lastName'] ."','".
$_POST['email'] ."','".
$_POST['password'] ."')";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句