php - Having trouble inserting inputted data into database -


i have written question similar before hand , have seemed fix minor errors in code of time, when fix 1 thing, arises.

before clarify problem, want explain background. have 2 registration forms, both used 1 after other own input devices , validations. when input data in first registration form, press next , takes me second form must fill out other information before "register" completely. in second registration form, used list of hidden inputs, <input type="hidden" name="name" value="<?php echo $_post['name'];?>"/> can hold information first registration file , still possess same data without loosing when taken next registration page.

below code:

<?php if (isset($_post['submit'])) { $username = $_post['username']; $password = $_post['password']; $name = $_post['name']; $lname = $_post['lname']; $address = $_post['address']; $agreement= $_post['agreement']; $conditions= $_post['conditions']; }  $conn = mysql_connect("localhost", "*****", "******");  mysql_select_db("*********", $conn)  or die ('database not found ' . mysql_error() );   $sql= "insert `users` (username, password, name, lname, address, agreement, conditions)  values (". $username .", ". $password .", ". $name .", ". $lname .", ". $address .", ". $agreement .", ". $conditions.")";   $rs = mysql_query($sql, $conn)   or die ('problem query' . mysql_error());   mysql_close($conn) ?> 

my form opens list of errors

notice: undefined variable: username ... @ line 140.

line 140 meaning values line variables.

all can @ moment know using correct database , table, why extremely confusing me why data input not inserting database. have tried many methods , nothing have helped improve code far.

you have put values between quotes

try :

$sql= "insert `users` (username, password, name, lname, address, agreement, conditions)  values ('". $username ."', '". $password ."', '". $name ."', '". $lname ."', '". $address ."', '". $agreement ."', '". $conditions."')"; 

and careful when inject data $_post[] sql query : can victim of sql injection !! please read : sql injection

[edit]

mysql_query() deprecated, should use pdo instead


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -