Studio381 Posted June 24, 2008 Share Posted June 24, 2008 Hi, I'm new to all this but have a site that has been up and running for a number of months. I have an insert query that fails now and again. What puzzles me is why it fails occasionally and not every time. The code for the insert is straightforward... include("misc.inc"); $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); $db = mysql_select_db($database,$connection) or die ("Couldn't select database"); $query = "INSERT INTO BasicTable (Fname, Sname, City, County, State, FirstwillID) VALUES ('$fname', '$sname', '$city', '$county', '$state', '$willidfirstperson')"; $result = mysql_query($query) or die ("Couldn't execute query1222basic1_601."); (I removed some of the entries in the Input query for the sake of space). This is the only piece of code that inserts a new record. Now if there was an error in the format of the insert statement it would fail every time, right? So I thought that maybe the values of what I was trying to insert might be causing the problem. However if I create a new record and enter these values into the database manually it all works. So what else should I look for that could be causing the problem? Thanks, John. Link to comment https://forums.phpfreaks.com/topic/111632-solved-insert-fails-occasionally/ Share on other sites More sharing options...
gijew Posted June 24, 2008 Share Posted June 24, 2008 Probably extra quotes if it's failing "some" of the time. Try adding mysql_escape_string($fname), etc and see if that works. Link to comment https://forums.phpfreaks.com/topic/111632-solved-insert-fails-occasionally/#findComment-573040 Share on other sites More sharing options...
Studio381 Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks - you were exactly correct. Now fixed. Link to comment https://forums.phpfreaks.com/topic/111632-solved-insert-fails-occasionally/#findComment-573065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.