georgebates Posted March 22, 2010 Share Posted March 22, 2010 Hi There, I've written this same sort of code many times and I've never had any problems and now It just throws me the error "Unable to insert record into database". Please help me!! Heres the code <?php $hostUrl = '*****'; $userName = '******'; $password = '******'; // connect to database $connectID = mysql_connect($hostUrl, $userName, $password) or die ("Sorry, can't connect to database"); //select the database to read from mysql_select_db("majubagallery_-_data", $connectID) or die ("Unable to select database"); $name=$_POST['name']; $price=$_POST['price']; $thumb_url=$_POST['thumb_url']; $big_url=$_POST['big_url']; if (($_POST['submitted'])) { // the user has submitted a new listing //write to database mysql_query ("INSERT into art_glass (name, price, thumb_url, big_url) VALUES ('$name', '$price', '$thumb_url', '$big_url')", $connectID) or die ("Unable to insert record into database"); if ($success) { print "Record Successfully Added"; header ('Location: microUpload.php'); } } else { // The user has loaded the page to enter a new listing // do nothing - just let the page load } ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 22, 2010 Share Posted March 22, 2010 So, check the actual error and/or check the query. I always advise against building the query directly inside the mysql_query() command. Build the query as a string variable so you can echo it to the page if needed: $query = "INSERT into art_glass (name, price, thumb_url, big_url) VALUES ('$name', '$price', '$thumb_url', '$big_url')" mysql_query ($query, $connectID) or die ("Query:<br />$query<br />Error:<br />".mysql_error()); Quote Link to comment Share on other sites More sharing options...
georgebates Posted March 22, 2010 Author Share Posted March 22, 2010 Both. I just uploaded it to another website i have on a different hosting company and it worked perfect on that so i just have no clue why its not on here. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2010 Share Posted March 22, 2010 Have any queries ever executed on the server in question? Quote Link to comment Share on other sites More sharing options...
georgebates Posted March 22, 2010 Author Share Posted March 22, 2010 yes. I have used this code many a time. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2010 Share Posted March 22, 2010 So, did you use mysql_error() in your error reporting logic, like mjdamato suggested, to find out why the query is failing? Quote Link to comment Share on other sites More sharing options...
georgebates Posted March 22, 2010 Author Share Posted March 22, 2010 Oh stupid me. I fixed it. The reason was It wasn't defining the id. Fixed. Thanks for your help guys! Quote Link to comment 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.