我正在尝试将表单值存储在数据库中,但错误的值存储在我的表中mobilenumber
字段的数据库中。在表格中,我有以下4个字段。
id(自动增量),
移动电话号码,
运算符,
日期。
当我回音时,值显示正确。
但是在将数据库表中存储移动号码时,我得不到mobilenumber字段的相同值。
我有以下代码。
主页
<?php include "header.php"?>
<body>
<div class="form-group">
<form name="myForm" action="invite.php" method="post" class="elegant-aero" onsubmit="return ValidateForm()" >
<h1> Congratulations. You have been invited to win Rs 148 Recharge.
<span>Please fill all the details to get a Rs 148 Recharge.</span>
</h1>
<label>
<span>Mobile Number</span>
<input name="Mobile" id="mob" type="text" placeholder="Prepaid Mobile Number" required />
</label>
<label>
<span>Operator</span><select name="Operator">
<option value="Select Operator">Select Operator</option>
<option value="Bsnl">BSNL</option>
<option value="Airtel">Airtel</option>
<option value="reliance">Reliance</option>
<option value="Vodafone">Vodafone</option>
<option value="Videocone">Videocone</option>
<option value="Aircel">Aircel</option>
<option value="Telenor">Telenor</option>
<option value="Idea">Idea</option>
<option value="Tataindicom">Tataindicom</option>
<option value="other">Other</option>
</select>
</label>
<label>
<span> </span>
<input type="submit" class="button" value="Proceed To Recharge" />
</label>
</form>
<div>
</body>
<?php include "footer.php" ?>
</html>
第2页
<html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "recharge_project";
/**$mobile = $_POST['Mobile'];
$operator = $_POST['Operator'];
**/
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO customer (id, mobilenumber, mobileoperator) VALUES ('', '$_POST[Mobile]', '$_POST[Operator]')";
if ($conn->query($sql) === TRUE) {
echo "datainserteed";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
<?php include "header.php"?>
<body xmlns="http://www.w3.org/1999/html">
<div class="form-group">
<form class="elegant-aero" >
<p> Invite your 10 active <span style="color:#FF0000"> WhatsApp Friends</span> <!-- and 3 <span style="color:#FF0000">WhatsApp Groups </span>-->to claim your recharge
</p>
<label>
<a class="button1" href="whatsapp://send?text=http://rechargetoday.net || Super Promo offer. Get Rs 148 free recharge. Visit above link to get your recharge.NOTE :Offer valid across India!!" onclick="return myFunction()" >Invite</a>
</br>
</label>
<?php echo"</br>";?>
<label>
<a name="finish" type="submit" class="button2" onclick="return aboveTen()">Finished- Inviting 10 friends </a>
</label>
<label>
</label>
</form>
<div>
</body>
</html>
我有以下JS代码。
var invite = 0;
function ValidateForm()
{
var fld= document.forms["myForm"]["Mobile"].value;
var phoneno = /^\d{10}$/;
if(fld.match(phoneno))
{
return true;
}
else
{
alert("Please enter valid number");
return false;
}
}
function myFunction(){ invite ++; }
当我回复$sql
时,我得到了以下查询。
INSERT INTO customer (mobilenumber, mobileoperator) VALUES ( 8574968578, 'Vodafone')
答案 0 :(得分:-1)
请尝试使用$sql = "INSERT INTO customer (id, mobilenumber, mobileoperator) VALUES ('', '$_POST['Mobile']', '$_POST['Operator']')";
$sql = "INSERT INTO customer (id, mobilenumber, mobileoperator) VALUES ('', '$_POST[Mobile]', '$_POST[Operator]')";
。