Jump to content

[SOLVED] Why is error code being returned


tjverge

Recommended Posts

$query = "INSERT INTO members (id, fname, lname, uname, password, email, address, city, country, date, ip) VALUES ('', $fname, $lname, $username, $password, $email, $address, $city, $country, $date, $ip)";
mysql_query($query) or die('Error, not able to add new members at this time');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

echo "New member added welcome ",$fname;

 

 

The above code should be inserting the data into my database, but it is returning the error instade, any ideas? Thank you

 

Link to comment
Share on other sites

why are you doing this ?

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

 

does the account have access to do it.. why do you need it ?

 

 

I remove this part of the code as I don't need it, still having the same problem.

Link to comment
Share on other sites

As cooldude832 requested, copy and paste what this outputs:

 

$query = "INSERT INTO members (id, fname, lname, uname, password, email, address, city, country, date, ip) VALUES ('', $fname, $lname, $username, $password, $email, $address, $city, $country, $date, $ip)";
mysql_query($query) or die(mysql_error()."<br /><br />\n\n".$query);

echo "New member added welcome ",$fname;

Link to comment
Share on other sites

yeah we need some more details but try this

 

change

$query = "INSERT INTO members (id, fname, lname, uname, password, email, address, city, country, date, ip) VALUES ('', $fname, $lname, $username, $password, $email, $address, $city, $country, $date, $ip)";

to

$query = "INSERT INTO members (id, fname, lname, uname, password, email, address, city, country, date, ip) VALUES ('', '$fname', '$lname', '$username', '$password', '$email', '$address', '$city', '$country', '$date', '$ip')";

Link to comment
Share on other sites

As cooldude832 requested, copy and paste what this outputs:

 

$query = "INSERT INTO members (id, fname, lname, uname, password, email, address, city, country, date, ip) VALUES ('', $fname, $lname, $username, $password, $email, $address, $city, $country, $date, $ip)";
mysql_query($query) or die(mysql_error()."<br /><br />\n\n".$query);

echo "New member added welcome ",$fname;

 

Field 'phone' doesn't have a default value

 

INSERT INTO members (id, fname, lname, uname, password, email, address, city, country, date, ip) VALUES ('', 'TJ', 'Verge', '', 'password', 'x@x.com', 'x Sr', 'New York', 'USA', 'Y/m/d', '127.0.0.1')

Link to comment
Share on other sites

This is what the code in question looks like now.

 

$query = "INSERT INTO members (id, fname, lname, uname, password, email, address, city, country, date, ip) VALUES ('', '$fname', '$lname', '$username', '$password', '$email', '$address', '$city', '$country', '$date', '$ip')";
mysql_query($query) or die(mysql_error()."<br /><br />\n\n".$query);

echo "New member added welcome ",$fname;

 

 

Link to comment
Share on other sites

exactly as it says you can not do an insert query without defining the field "phone" because it has no default value

 

To fix this give the field phone a default value or make the query be

$query = "INSERT INTO members (id, fname, lname, uname, password, email, address, city, country, date, ip,phone) VALUES ('', $fname, $lname, $username, $password, $email, $address, $city, $country, $date, $ip,'')";
mysql_query($query) or die(mysql_error()."<br /><br />\n\n".$query);

 

The mysql_error() is a great clue to why queries fail and adding the echoing out of the query after 2 breaklines lets you easily see the query with all the php variables applied to it.

 

Link to comment
Share on other sites

I may be wrong, but I think that's due to the fact you have the phone field set as NOT NULL: YES

If you try to insert data into the row, and not give the phone field a value, it'll look for the default.  If there is no default set, but you say it has to have a value, then you'll get an error.  Let me know if this is not the case or if I'm just completely off.

 

edit:  or what cooldude said.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.