Jump to content

'insert into' won't work on mysql


gongpex
 Share

Recommended Posts

Hello all,

 

I think this code, is what did you mean (mysqli_error())

<?php require("connect_db.php");  mysqli_query($connect,"SELECT * FROM member");  $user = $_POST['test']; $name = $_POST['num'];  $ins = mysqli_query($connect,"INSERT INTO member(m_name,m_user) VALUES ('$name','$user')");  if(!$ins) {  printf ("Errormessage %s n",mysqli_error($connect));  } else {  printf ("recorded");  } ?>

this code result : Errormessage Field 'm_pass' doesn't have a default value

 

Q : how to fix this problem ?

 

please help

 

thanks

Link to comment
Share on other sites

Link to comment
Share on other sites

hello,

 

you right, it can be recorded after giving default value.

 

many thanks about this,

 

but about :

 

sounds like that field in your table can't be NULL.

 

Q : yes, but I wonder, why it can be occurs?

 

when I use old PHP version with using mysql not mysqli it can be record without giving default value.

 

please explain to me

 

thanks again

Link to comment
Share on other sites

That's not an error from the PHP API, that's an error from the actual database

 

Q : so, I must change with other database or database version to avoid this error?

 

thanks

Edited by gong
Link to comment
Share on other sites

No, you need to follow the rules that you set for your database. You have a field that doesn't have a default value, and you're not including it in the insert query. That is an error, you need to understand what that error means. The field doesn't have a default value and you aren't giving it a value, so the database doesn't know what value to use for that field, and that's an error. Either change your query to include that field or change the table structure to give it a default value.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...