Javascript 无法在phpmyAdmin中保存数据
问题: 嗨,我的一张提交表格有问题。我已经创建了一个数据库,还创建了一个表。当我已经填写完表格后,单击submit按钮,并选中phpmyAdmin。它没有显示我已经提交的详细信息 这是我的php代码,包括sqlconnectreserve.php 这是我的表格代码:Javascript 无法在phpmyAdmin中保存数据,javascript,php,html,mysql,css,Javascript,Php,Html,Mysql,Css,问题: 嗨,我的一张提交表格有问题。我已经创建了一个数据库,还创建了一个表。当我已经填写完表格后,单击submit按钮,并选中phpmyAdmin。它没有显示我已经提交的详细信息 这是我的php代码,包括sqlconnectreserve.php 这是我的表格代码: 表单字段名与service.php名称字段中的不匹配。您的更新代码应该是 <?php if($_POST['formSubmit'] === "Submit") { $errorMessage
表单字段名与service.php名称字段中的不匹配。您的更新代码应该是
<?php
if($_POST['formSubmit'] === "Submit")
{
$errorMessage = "";
if(empty($_POST['formName']))
{
$errorMessage .= "<li> You forgot to enter your name! </li>";
}
//Doesnt Have List
$varName = $_POST['name'];
$varEmail = $_POST['email'];
$varPhone = $_POST['phone'];
$varStreet = $_POST['street'];
$varNumber = $_POST['street-number'];
$varCity = $_POST['city'];
$varPostCode = $_POST['post-code'];
$varCountry = $_POST['country'];
//Have List
$varPeople = $_POST['arrive'];
$varTables = $_POST['tables'];
$varTime = $_POST['time'];
$varComment = $_POST['comments'];
if(empty($errorMessage))
{
//Sql Connect
$db = mysql_connect ('sql999.byethost9.com','b9_9999999','password');
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db('b9_9999999_database',$db);
$sql = "INSERT INTO form2 (Name, Email, Phone, Street, Number, City, PostCode, Country, People, Tables, Time, Comment) VALUES (".
//Doesnt Have List Dropdown
PrepSQL($varName) . ", ".
PrepSQL($varEmail) . ", ".
PrepSQL($varPhone) . ", ".
PrepSQL($varStreet) . ", ".
PrepSQL($varNumber) . ", ".
PrepSQL($varCity) . ", ".
PrepSQL($varPostCode) . ", ".
PrepSQL($varCountry) . ", ".
//Have List Dropdown
PrepSQL($varPeople) . ", ".
PrepSQL($varTables) . ", ".
PrepSQL($varTime) . ", ".
PrepSQL($varComment) . ") ";
mysql_query($sql);
header('Location:thankyou.html');
exit();
}
}
//function:PrepSQL()
//use stripslashes and mysql_real_escape_string PHP functions
//tosanitize a string for use in an SQL query
//
//also puts single quotes around the string
//
function PrepSQL($value)
{
//Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
//Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
?>
这将解决您的问题为了澄清问题,您的问题与phpMyAdmin无关。你也应该使用mysqli_uuu函数,或者更好的是,使用PDO。它没有显示我已经提交的详细信息。这是什么?请问一个正确的问题。请阅读:您的输入名称与您在php脚本中使用的变量不匹配。“一点也不。”杰罗恩,哪一个?它在表单代码中吗?
<html>
<?php include("reserve.php"); ?>
<body>
.......
<form action="<?php
echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<!-- PHP-->
<!-- General -->
<div class="form-group">
<h2 class="heading">Booking & contact</h2>
<div class="controls">
<input type="text" id="name" class="floatLabel" name="name" value="<?= $varName;
?>" />
<label for="name">Name</label>
</div>
<div class="controls">
<input type="text" id="email" class="floatLabel" name="email" value="<?= $varEmail;
?>" />
<label for="email">Email</label>
</div>
<div class="controls">
<input type="tel" id="phone" class="floatLabel" name="phone" value="<?= $varPhone;
?>" />
<label for="phone">Phone</label>
</div>
<div class="grid">
<div class="col-2-3">
<div class="controls">
<input type="text" id="street" class="floatLabel" name="street" value="<?= $varStreet;
?>" />
<label for="street">Street</label>
</div>
</div>
<div class="col-1-3">
<div class="controls">
<input type="number" id="street-number" class="floatLabel" name="street-number" value="<?= $varNumber;
?>" />
<label for="street-number">Number</label>
</div>
</div>
</div>
<div class="grid">
<div class="col-2-3">
<div class="controls">
<input type="text" id="city" class="floatLabel" name="city" value="<?= $varCity;
?>" />
<label for="city">City</label>
</div>
</div>
<div class="col-1-3">
<div class="controls">
<input type="text" id="post-code" class="floatLabel" name="post-code" value="<?= $varPostCode;
?>" />
<label for="post-code">Post Code</label>
</div>
</div>
</div>
<div class="controls">
<input type="text" id="country" class="floatLabel" name="country" value="<?= $varCountry;
?>" />
<label for="country">Country</label>
</div>
</div>
<!-- Details -->
<div class="form-group">
<h2 class="heading">Details</h2>
<div class="grid">
<div class="col-1-4 col-1-4-sm">
<div class="controls">
<input type="date" id="arrive" class="floatLabel" name="arrive" value="<?php
echo date('Y-m-d'); ?>">
<label for="arrive" class="label-date"><i class="fa fa-calendar"></i> Arrive</label>
</div>
</div>
</div>
<div class="grid">
<div class="col-1-3 col-1-3-sm">
<div class="controls"> <i class="fa fa-sort"></i>
<select class="floatLabel">
<option value="blank"></option>
<option value="1" <?php if ($varPeople === "Less than 5") echo ("selected=\"selected\""); ?>>Less than 5</option>
<option value="2" <?php if ($varPeople === "More than 5") echo ("selected=\"selected\""); ?>>More than 5</option>
<option value="3" <?php if ($varPeople === "More than 10") echo ("selected=\"selected\""); ?>>More than 10</option>
</select>
<label for="fruit"><i class="fa fa-male"></i> People</label>
</div>
</div>
<div class="col-1-3 col-1-3-sm">
<div class="controls"> <i class="fa fa-sort"></i>
<select class="floatLabel">
<option value="blank"></option>
<option value="deluxe" <?php if ($varTables === "Indoor") echo ("selected=\"selected\""); ?>>Indoor</option>
<option value="Zuri-zimmer" <?php if ($varTables === "Outdoor") echo ("selected=\"selected\""); ?>>Outdoor</option>
<option value="Zuri-zimmer" <?php if ($varTables === "VIP Room") echo ("selected=\"selected\""); ?>>VIP Room</option>
</select>
<label for="fruit">Tables</label>
</div>
</div>
<div class="col-1-3 col-1-3-sm">
<div class="controls"> <i class="fa fa-sort"></i>
<select class="floatLabel">
<option value="single-bed" <?php if ($varTime === "Breakfast") echo ("selected=\"selected\""); ?>>Breakfast</option>
<option value="double-bed" <?php if ($varTime === "Lunch") echo ("selected=\"selected\""); ?>>Lunch</option>
<!-- Add "selected >Lunch" when not using php code -->
<option value="double-bed" <?php if ($varTime === "Dinner") echo ("selected=\"selected\""); ?>>Dinner</option>
</select>
<label for="fruit">Time</label>
</div>
</div>
</div>
<div class="grid">
<p class="info-text">Please describe your needs e.g. Annual Dinner, Party</p>
<br>
<div class="controls">
<textarea name="comments" class="floatLabel" id="comments"><?= $varComment;
?>
</textarea>
<label for="comments">Comments</label>
</div>
<button type="submit" value="Submit" class="col-1-4">Submit</button>
</div>
</div>
<!-- /.form-group -->
</form>
....
</body>
</html>
<?php
if($_POST['formSubmit'] === "Submit")
{
$errorMessage = "";
if(empty($_POST['formName']))
{
$errorMessage .= "<li> You forgot to enter your name! </li>";
}
//Doesnt Have List
$varName = $_POST['name'];
$varEmail = $_POST['email'];
$varPhone = $_POST['phone'];
$varStreet = $_POST['street'];
$varNumber = $_POST['street-number'];
$varCity = $_POST['city'];
$varPostCode = $_POST['post-code'];
$varCountry = $_POST['country'];
//Have List
$varPeople = $_POST['arrive'];
$varTables = $_POST['tables'];
$varTime = $_POST['time'];
$varComment = $_POST['comments'];
if(empty($errorMessage))
{
//Sql Connect
$db = mysql_connect ('sql999.byethost9.com','b9_9999999','password');
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db('b9_9999999_database',$db);
$sql = "INSERT INTO form2 (Name, Email, Phone, Street, Number, City, PostCode, Country, People, Tables, Time, Comment) VALUES (".
//Doesnt Have List Dropdown
PrepSQL($varName) . ", ".
PrepSQL($varEmail) . ", ".
PrepSQL($varPhone) . ", ".
PrepSQL($varStreet) . ", ".
PrepSQL($varNumber) . ", ".
PrepSQL($varCity) . ", ".
PrepSQL($varPostCode) . ", ".
PrepSQL($varCountry) . ", ".
//Have List Dropdown
PrepSQL($varPeople) . ", ".
PrepSQL($varTables) . ", ".
PrepSQL($varTime) . ", ".
PrepSQL($varComment) . ") ";
mysql_query($sql);
header('Location:thankyou.html');
exit();
}
}
//function:PrepSQL()
//use stripslashes and mysql_real_escape_string PHP functions
//tosanitize a string for use in an SQL query
//
//also puts single quotes around the string
//
function PrepSQL($value)
{
//Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
//Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
?>