473,372 Members | 940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Why is my php value not being inserted into the database?

<?php
include 'connection.php';
if(isset($_POST['submit']))
{
$name1=$_POST['name'];
$email1=$_POST['email'];
$re_email1=$_POST['email1'];
$npass1=$_POST['pass'];
$npass2=$_POST['pass1'];
$phone1=$_POST['phone'];
$state1=$_POST['state'];
$city1=$_POST['city'];
$street1=$_POST['street'];
$pin1=$_POST['pin'];
$sql="INSERT INTO user_details (uname,email,re_email,pass1,pass2,phone,ustate,cit y,street,pin) VALUES ('$name1','$email1','$re_email1','$npass1','$npass 2','$phone1','$state1','$city1','$street1','$pin1' )";
// $sql="INSERT INTO user_details (uname,email,re_email,pass1,pass2,phone,ustate,cit y,street,pin) VALUES ('$name1','".$email1."','".$re_email1."','".$npass 1."','".$npass2."','".$phone1."','".$state1."','". $city1."','".$street1."','".$pin1."')";
$result=mysqli_query($conn,$sql);
if($result)
{
echo "<br>User has been registered";
header('Location: mainpage.php');
exit;
}
else{
echo "Error:".$sql.":-".mysqli_error($conn);
}
mysqli_close($conn);
}
?>
<html>
<head>
<title>SignUp</title>
<style>
#carlogo{
width:120px;
height:120px;
padding-top: 2px;
border-radius: 80%;
}

#company_name{
font-size: xx-large;
font-weight: bolder;
padding: 30px;
font-family: 'Courier New', Courier, monospace;
}
.topnavigation{
background-blend-mode: difference;
display:flex;
align-items: center;
box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0), 0 6px 20px 0 rgba(0, 0, 0, 0.0);
box-sizing: border-box;
/* border:white; */
/* border-width:3px; */
/* border-bottom: white; */
}
body{
background-image: url("images/pexels-garvin-st-villier-3311574.jpg");
margin:0px;
margin-top: 20px;
padding: 0px;
background-size: cover ;
zoom: 0;
min-height: 500px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
}
label{
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
font-weight: bold;
color: white;
}
.signup{
border-radius: 25px;
border: 4px solid yellow;
background-color:rgb(32, 32, 32);
margin-left: 50px;
margin-top: 30px;
margin-bottom: 20px;
padding: 20px;
width: 400px;
height: auto;
}
.signup:hover{
background-color: rgb(70, 68, 68);
border: 4px solid yellow
}

.register{
opacity: 0.9;
background-blend-mode: difference;
}
.para{
font-weight: bolder;
font-size:larger;
text-align: center;
}
.button{
background-color: yellow;
border:none;
color:black;
font-weight: bolder;
padding:8px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 18px;
margin:0px 2px;
cursor: pointer;
border-radius: 15px;
transition: 0.3s;
width:40%;
margin-left: auto;

}
.button:hover{
background-color: black;
color:white;
}
input[type=text], select,input[type=email],input[type=password],input[type=number],input[type=tel],textarea[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}

</style>
<script type='text/JavaScript'>
function check(){
var letters= /^[A-Za-z]+$/;
var numbers = /^[0-9]+$/;


//password validation
if((signupform.pass.value.length < "6") || (signupform.pass1.value.length <"6") ||(signupform.pass.value > "8")||(signupform.pass1.value > "8")){
alert("!! Invalid Password. Enter Password with 6-8 characters !!");
pass.focus();
pass2.focus();
return false;
}
if(signupform.pass.value != signupform.pass1.value){
alert("! Both the passwords does not match !");
pass.focus();
pass1.focus();
return false;
}

//email validation
if(signupform.email.value != signupform.email1.value){
alert("! Both the Email Addresses does not match !")
email.focus();
email1.focus();
return false;
}

//phone number validation
if((signupform.phone.value.length >10)||(signupform.phone.value.length <9)){
alert("Invalid Phone no, Must contain only 10 digits")
phone.focus();
return false;
}

// window.location.href="login.html";
alert("User has been successfully Registered");
true;
}
</script>
</head>
<body>
<div class="topnavigation">
<img id="carlogo" src="images/download.jfif" alt="Avatar">
<span id="company_name">CLASSICS CUSTOMS</span>
</div>
<div class="register" >
<div class="signup">
<form name="signupform" method="POST" onsubmit="return check()" action="mainpage.php">
<center><b><h2 style="color: white;">Enter your Details to SignUp</h2></b></center>
<label>Name :</label><input type="text" name="name" id="name" placeholder="Enter Full Name" required><br><br>
<label>Email :</label><input type="email" name="email" id="email" placeholder="Enter Email" required><br><br>
<label>Confirm Email :</label><input type="email" name="email1" id="email1" placeholder="Re-enter Email" required><br><br>
<label>Password :<label><input type="password" name="pass" id="pass" placeholder="Enter Password of maximum 10 digits"required ><br><br>
<label>Confirm Password :</label><input type="password" name="pass1" id="pass1" placeholder="Re-enter Password"><br><br>
<label>Mobile No :</label><input type="tel" name="phone" id="phone" placeholder="Enter Phone no"><br><br>
<label>State :</label>
<select name="state" id="state">
<option value="Kerala">Kerala</option>
<option value="Tamil Nadu">Tamil Nadu</option>
<option value="Karnataka">Karnataka</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Goa">Goa</option>
<option value="Maharastra">Maharastra</option>
<option value="Gujarat">Gujarat</option>
<option value="Madhya Pradesh">Madhya Pradesh</option>
</select><br><br>
<label>City :</label><input type="text" name="city" id="city" placeholder="Enter your city"><br><br>
<label>Street/Address :</label><textarea type="text" name="street" id="street" placeholder="Enter your street"></textarea><br><br>
<label>PinCode :</label><input type="number" name="pin" id="pin" placeholder="Enter your PinCode"><br><br>
<center><button class="button" name="submit">SignUp</button></center>
<!-- <center><input*type="submit"*class="button"*name=" submit"*value="Signup"></center> -->
</form>
</div>
</div>

</body>
</html>

<!-- pattern="^\d{6}$" -->
Sep 17 '21 #1
2 15095
dev7060
636 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include 'connection.php';
  3. if(isset($_POST['submit']))
  4. {
  5. $name1=$_POST['name'];
  6. $email1=$_POST['email'];
  7. $re_email1=$_POST['email1'];
  8. $npass1=$_POST['pass'];
  9. $npass2=$_POST['pass1'];
  10. $phone1=$_POST['phone'];
  11. $state1=$_POST['state'];
  12. $city1=$_POST['city'];
  13. $street1=$_POST['street'];
  14. $pin1=$_POST['pin'];
  15. $sql="INSERT INTO user_details (uname,email,re_email,pass1,pass2,phone,ustate,cit y,street,pin) VALUES ('$name1','$email1','$re_email1','$npass1','$npass 2','$phone1','$state1','$city1','$street1','$pin1' )";
  16. // $sql="INSERT INTO user_details (uname,email,re_email,pass1,pass2,phone,ustate,cit y,street,pin) VALUES ('$name1','".$email1."','".$re_email1."','".$npass 1."','".$npass2."','".$phone1."','".$state1."','". $city1."','".$street1."','".$pin1."')";
  17. $result=mysqli_query($conn,$sql);
  18. if($result)
  19. {
  20. echo "<br>User has been registered";
  21. header('Location: mainpage.php');
  22. exit;
  23. }
  24. else{
  25. echo "Error:".$sql.":-".mysqli_error($conn);
  26. }
  27. mysqli_close($conn);
  28. }
  29. ?>
  30. <html>
  31. <head>
  32. <title>SignUp</title>
  33. <style>
  34. #carlogo{
  35. width:120px;
  36. height:120px;
  37. padding-top: 2px;
  38. border-radius: 80%;
  39. }
  40.  
  41. #company_name{
  42. font-size: xx-large;
  43. font-weight: bolder;
  44. padding: 30px;
  45. font-family: 'Courier New', Courier, monospace;
  46. }
  47. .topnavigation{
  48. background-blend-mode: difference;
  49. display:flex;
  50. align-items: center;
  51. box-shadow: 0 0px 0px 0 rgba(0, 0, 0, 0), 0 6px 20px 0 rgba(0, 0, 0, 0.0);
  52. box-sizing: border-box;
  53. /* border:white; */
  54. /* border-width:3px; */
  55. /* border-bottom: white; */
  56. }
  57. body{
  58. background-image: url("images/pexels-garvin-st-villier-3311574.jpg");
  59. margin:0px;
  60. margin-top: 20px;
  61. padding: 0px;
  62. background-size: cover ;
  63. zoom: 0;
  64. min-height: 500px;
  65. background-attachment: fixed;
  66. background-position: center;
  67. background-repeat: no-repeat;
  68. background-size: cover;
  69. font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  70. }
  71. label{
  72. font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  73. font-weight: bold;
  74. color: white;
  75. }
  76. .signup{
  77. border-radius: 25px;
  78. border: 4px solid yellow;
  79. background-color:rgb(32, 32, 32);
  80. margin-left: 50px;
  81. margin-top: 30px;
  82. margin-bottom: 20px;
  83. padding: 20px;
  84. width: 400px;
  85. height: auto;
  86. }
  87. .signup:hover{
  88. background-color: rgb(70, 68, 68);
  89. border: 4px solid yellow
  90. }
  91.  
  92. .register{
  93. opacity: 0.9;
  94. background-blend-mode: difference;
  95. }
  96. .para{
  97. font-weight: bolder;
  98. font-size:larger;
  99. text-align: center;
  100. }
  101. .button{
  102. background-color: yellow;
  103. border:none;
  104. color:black;
  105. font-weight: bolder;
  106. padding:8px;
  107. text-align: center;
  108. text-decoration: none;
  109. display: inline-block;
  110. font-size: 18px;
  111. margin:0px 2px;
  112. cursor: pointer;
  113. border-radius: 15px;
  114. transition: 0.3s;
  115. width:40%;
  116. margin-left: auto;
  117.  
  118. }
  119. .button:hover{
  120. background-color: black;
  121. color:white;
  122. }
  123. input[type=text], select,input[type=email],input[type=password],input[type=number],input[type=tel],textarea[type=text] {
  124. width: 100%;
  125. padding: 12px 20px;
  126. margin: 8px 0;
  127. display: inline-block;
  128. border: 1px solid #ccc;
  129. border-radius: 4px;
  130. box-sizing: border-box;
  131. }
  132.  
  133. </style>
  134. <script type='text/JavaScript'>
  135. function check(){
  136. var letters= /^[A-Za-z]+$/;
  137. var numbers = /^[0-9]+$/;
  138.  
  139.  
  140. //password validation
  141. if((signupform.pass.value.length < "6") || (signupform.pass1.value.length <"6") ||(signupform.pass.value > "8")||(signupform.pass1.value > "8")){
  142. alert("!! Invalid Password. Enter Password with 6-8 characters !!");
  143. pass.focus();
  144. pass2.focus();
  145. return false;
  146. }
  147. if(signupform.pass.value != signupform.pass1.value){
  148. alert("! Both the passwords does not match !");
  149. pass.focus();
  150. pass1.focus();
  151. return false;
  152. }
  153.  
  154. //email validation
  155. if(signupform.email.value != signupform.email1.value){
  156. alert("! Both the Email Addresses does not match !")
  157. email.focus();
  158. email1.focus();
  159. return false;
  160. }
  161.  
  162. //phone number validation
  163. if((signupform.phone.value.length >10)||(signupform.phone.value.length <9)){
  164. alert("Invalid Phone no, Must contain only 10 digits")
  165. phone.focus();
  166. return false;
  167. }
  168.  
  169. // window.location.href="login.html";
  170. alert("User has been successfully Registered");
  171. true;
  172. }
  173. </script>
  174. </head>
  175. <body>
  176. <div class="topnavigation">
  177. <img id="carlogo" src="images/download.jfif" alt="Avatar">
  178. <span id="company_name">CLASSICS CUSTOMS</span>
  179. </div>
  180. <div class="register" >
  181. <div class="signup">
  182. <form name="signupform" method="POST" onsubmit="return check()" action="mainpage.php">
  183. <center><b><h2 style="color: white;">Enter your Details to SignUp</h2></b></center>
  184. <label>Name :</label><input type="text" name="name" id="name" placeholder="Enter Full Name" required><br><br>
  185. <label>Email :</label><input type="email" name="email" id="email" placeholder="Enter Email" required><br><br>
  186. <label>Confirm Email :</label><input type="email" name="email1" id="email1" placeholder="Re-enter Email" required><br><br>
  187. <label>Password :<label><input type="password" name="pass" id="pass" placeholder="Enter Password of maximum 10 digits"required ><br><br>
  188. <label>Confirm Password :</label><input type="password" name="pass1" id="pass1" placeholder="Re-enter Password"><br><br>
  189. <label>Mobile No :</label><input type="tel" name="phone" id="phone" placeholder="Enter Phone no"><br><br>
  190. <label>State :</label>
  191. <select name="state" id="state">
  192. <option value="Kerala">Kerala</option>
  193. <option value="Tamil Nadu">Tamil Nadu</option>
  194. <option value="Karnataka">Karnataka</option>
  195. <option value="Andhra Pradesh">Andhra Pradesh</option>
  196. <option value="Goa">Goa</option>
  197. <option value="Maharastra">Maharastra</option>
  198. <option value="Gujarat">Gujarat</option>
  199. <option value="Madhya Pradesh">Madhya Pradesh</option>
  200. </select><br><br>
  201. <label>City :</label><input type="text" name="city" id="city" placeholder="Enter your city"><br><br>
  202. <label>Street/Address :</label><textarea type="text" name="street" id="street" placeholder="Enter your street"></textarea><br><br>
  203. <label>PinCode :</label><input type="number" name="pin" id="pin" placeholder="Enter your PinCode"><br><br>
  204. <center><button class="button" name="submit">SignUp</button></center>
  205. <!-- <center><input*type="submit"*class="button"*name=" submit"*value="Signup"></center> -->
  206. </form>
  207. </div>
  208. </div>
  209.  
  210. </body>
  211. </html>
  212.  
  213. <!-- pattern="^\d{6}$" -->
Why is my php value not being inserted into the database?
What is the error(s) you see? I don't see check() returning true anywhere.
Sep 18 '21 #2
bakertaylor28
45 32bit
This is your problem:

Expand|Select|Wrap|Line Numbers
  1. $sql="INSERT INTO user_details (uname,email,re_email,pass1,pass2,phone,ustate,cit y,street,pin) VALUES ('$name1','$email1','$re_email1','$npass1','$npass 2','$phone1','$state1','$city1','$street1','$pin1' )";
  2.  
The problem is that SQL doesn't know which record to file because you need a WHERE clause to identify the uname field so that SQL knows which record in the database it is modifying. Therefore we need either of the following :

Expand|Select|Wrap|Line Numbers
  1. ...
  2. // Cretate a new database record all at once. Var $foo is presumed to hold the SQL table value for uname
  3.  
  4. $sql="INSERT INTO user_details (uname,email,re_email,pass1,pass2,phone,ustate,city,street,pin) VALUES ('$foo,$name1','$email1','$re_email1','$npass1','$npass 2','$phone1','$state1','$city1','$street1','$pin1' )";
  5.  
  6. // OR we can Modify an existing record using UPDATE combined with a WHERE Clause 
  7.  
  8. ...
  9. UPDATE user_details SET email = $email, re_email = $re_email1, pass1 = $npass1, pass2 = $npass2, phone = #phone1,
  10. ustate = $state1, city = $city1, street = $street1 pin = $pin1 WHERE uname = $foo;
  11.  
Feb 26 '23 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: william | last post by:
Hi Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it (string, integer, boolean type field) Thank willia
1
by: garimapuri | last post by:
hi ihad an array in php and iwant to insert its value in database the coding is: <?php $nv_pairs = explode('&',$query_string); $array; list ($name, $value) = explode ('=',$nv_pairs); $i = 0;...
3
by: kang jia | last post by:
hi i retrieved value from database and now would to put these value inside a textarea. however, it seems cant put in, but the value can be retrieved from database. i don;t know where is wrong, ...
1
by: julianomartins | last post by:
Hi friends, how I make to recoup the value of database and to keep selected in combobox to edit my form? in script below it is selected field of the table that possesss id of the first item of...
1
by: suraj srivastava | last post by:
if we want find the value witout database connection,we want value retrieve from datagrid at .aspx pages at run time. we want to connection of the pages of data value throw datagrid . how will we...
1
by: arial | last post by:
I am having problem inserting checkbox value into database table. My database field is of type char(1). and my code is like this: string cc= null; if (chkdiscipline.checked) { cc = "T";
1
by: bhargavi514 | last post by:
friends i need the code to retrieve value from database and display value in text area using php
2
by: mindi | last post by:
how to retrieve single value form database without using result set. like i need only integer max(acc_id) from database and need to store in a variable
4
by: coder86 | last post by:
Hi, I am new to this site . I am looking for some help in updating my database from the value selected by user. Heres my page I have a table with rows of ID and its status. Status is a drop...
1
by: ilasenthi27 | last post by:
hi.. i'm php beginner,implementing payroll system based on salary per hour.. i want to store the time value on database.the time value get from time picker. and database has wrkingtime as time...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.