Reputation: 158
I do try to insert information into databace with mysqli but it doesn't work! The command seems to be correct!
$creg=mysqli_connect('localhost','uuu','uuu','pro5');
$sqreg="INSERT INTO tbl_users (username,name,lastname,password,email,gender,country,city,register_date,ip1) VALUES('$un','$na','$lnm','$ps','$eml','$ge','$co','$ci','$rdt','$ip')";
if (mysqli_query($creg, $sqreg) ) {
echo "Create successfully"."<br>";
echo $sqreg . "<br>" . mysqli_error($creg);
} else {
echo "Error: ";
}
and this is output
Create successfully
INSERT INTO tbl_users (username,name,lastname,password,email,gender,country,city,register_date,ip1) VALUES('dfvdfvd','vfd','dfv','fvdfvd','dfvdfv','1','1','1','0','0')
what is the problem?! thanks
Upvotes: 0
Views: 52
Reputation: 2984
Two things which may affect your database query:
<?php
$creg = mysqli_connect();
if(!$creg) {
trigger_error('Connection did not work.' . mysqli_connect_error());
}
I am pretty sure this would be the reason for you not being able to complete the action. If you are sending wrong column names, or more than your table has, it will simply not add anything.
For instance, you are sending data to these columns:
username, # @varchar
name, # @varchar
lastname, # @varchar
password, # @varchar
email, # @varchar
gender, # @varchar
country, # @varchar
city, # @varchar
register_date, # @date
ip1 # @int
Now, your table should have those columns, and that they are the right type.
That annoying part is that PHP runs the query as though MySQL took it properly, so it would make sense you are seeing the success message.
So check the query and your table.
You could also share your table_schema
, that would be helpful in determine the issue.
NOTE: please, please, please! Look at prepared statements, they are both more elegant, and just common sense today.
Upvotes: 1