tjverge Posted August 2, 2008 Share Posted August 2, 2008 $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 Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/ Share on other sites More sharing options...
MadTechie Posted August 2, 2008 Share Posted August 2, 2008 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606386 Share on other sites More sharing options...
cooldude832 Posted August 2, 2008 Share Posted August 2, 2008 us this error method it will give you more info on the error <?php $r = mysql_query($query) or die(mysql_error()."<br /><br />\n\n".$query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606388 Share on other sites More sharing options...
tjverge Posted August 2, 2008 Author Share Posted August 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606396 Share on other sites More sharing options...
cooldude832 Posted August 2, 2008 Share Posted August 2, 2008 can u post the error message populated from my answer it will give us an insight on this Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606397 Share on other sites More sharing options...
tjverge Posted August 2, 2008 Author Share Posted August 2, 2008 can u post the error message populated from my answer it will give us an insight on this It is still just returning the "Error, not able to add new members at this time" Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606400 Share on other sites More sharing options...
Stooney Posted August 2, 2008 Share Posted August 2, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606402 Share on other sites More sharing options...
MadTechie Posted August 2, 2008 Share Posted August 2, 2008 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')"; Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606405 Share on other sites More sharing options...
tjverge Posted August 2, 2008 Author Share Posted August 2, 2008 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') Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606409 Share on other sites More sharing options...
tjverge Posted August 2, 2008 Author Share Posted August 2, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606413 Share on other sites More sharing options...
cooldude832 Posted August 2, 2008 Share Posted August 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606415 Share on other sites More sharing options...
Stooney Posted August 2, 2008 Share Posted August 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606416 Share on other sites More sharing options...
tjverge Posted August 2, 2008 Author Share Posted August 2, 2008 Thank you for the help, I changed phone to null, and everything works now. Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606422 Share on other sites More sharing options...
cooldude832 Posted August 2, 2008 Share Posted August 2, 2008 Thank you for the help, I changed phone to null, and everything works now. for fields that aren't foreign or primary keys a NULL values is usually acceptable. Quote Link to comment https://forums.phpfreaks.com/topic/117886-solved-why-is-error-code-being-returned/#findComment-606423 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.