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
https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/
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.

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;

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')";

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', '[email protected]', 'x Sr', 'New York', 'USA', 'Y/m/d', '127.0.0.1')

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;

 

 

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.

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.