harlequeen Posted July 25, 2008 Share Posted July 25, 2008 Hi I'm trying to get some data from a form to the database, but I keep getting an error. I know the info is being passed as I am echoing it just to see. Here is my code, I'm sure it's something simple, but I can't see it. include("myblah.php"); $Surname=$_POST['Surname']; $Firstname=$_POST['Firstname']; $Position=$_POST['Position']; $previousClub=$_POST['previousClub']; $playerquery=("INSERT INTO player VALUES ('$Surname','$Firstname','$Position','$previousClub')"); echo ($Surname); echo ($Firstname); echo ($Position); echo ($previousClub); $result=mysql_query($playerquery); if ($result) { echo "<b>Entry Successfully Posted!</b>"; }//end then else { echo "<b>ERROR: unable to post.</b>"; }//end else Here is my Html <form name="getentry" action="addplayer.php" method="POST" target="_self"> Surname: <input type="text" name="Surname" size="35" ><br> First Name: <input type="text" name="Firstname" size="30" ><br> Preferred Position: <input type="text" name="Position" size="35" ><br> Previous Clubs: <textarea name="previousClub" cols="20" rows="6"></textarea><br> <input type="submit" name="submit" value="Submit" /> <input type="hidden" name="do" value="send" /> <input type="reset" name="reset" value="Reset" /> </form> and here are the fields I have in my database. Surname Firstname Position Age Honours Playerimage Number (autoincrement field) previousClub I have been trying to get this to work, but just can't do it. I know its bound to be something simple, please help. Quote Link to comment Share on other sites More sharing options...
ranjuvs Posted July 25, 2008 Share Posted July 25, 2008 Whats the error you are getting? Quote Link to comment Share on other sites More sharing options...
MFHJoe Posted July 25, 2008 Share Posted July 25, 2008 $playerquery=("INSERT INTO player VALUES ('$Surname','$Firstname','$Position','','','','','$previousClub')"); When you listed the fields in your database, did you list them in the order they are in the table? If you did, the above code should fix it (you were trying to put $previousClub into the age field which presumably you have set as integer in the table, and this was causing the error). Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 25, 2008 Share Posted July 25, 2008 adjust your query to this, to ensure that any error is spat out: $result=mysql_query($playerquery) or die('query ['.$playerquery.'] failed. mysql said: '.mysql_error()); i think you'll find it's failing because the columns and fields mismatch in count. you have more fields than parameters that you're inputting. when that's the case, you have to explicitly state the columns you're inserting: $playerquery=("INSERT INTO player (Surname, Firstname, Position, previousClub) VALUES ('$Surname','$Firstname','$Position','$previousClub')"); Quote Link to comment Share on other sites More sharing options...
harlequeen Posted July 25, 2008 Author Share Posted July 25, 2008 Thanks all, I thought it might have been that, but didn't realise I could put the '' to represent a missing field. Once I added the 4 blanks required, it worked a treat. I also used "mysql said: '.mysql_error());" which I didn't know about before. Thanks again Harlequeen 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.