473,289 Members | 1,848 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,289 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 15030
dev7060
626 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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.