Jax2 Posted June 17, 2010 Share Posted June 17, 2010 Hi all, I have a list of map coordinates that need to be saved to a database -- the coordinates look similar to this: 1,3 or 129,45 ...etc I have set up a text entry for each set of coordinates (There will be up to 10 total per person) and I am trying to add them to my database. Here is the code for the first section (Data Entry I'll call it) <td align="center"> <input type="text" name="coord[]" size=8> </td> <td align="center"> <input type="text" name="coord[]" size=8> </td> I have 10 of those total. Now, on the actual database code, which I am trying to store it into the database with, I am using: for ($i = 0; $i < 10; $i++) { if ($coord[$i] != "") { $sql = "insert into coords (playerID, coord) values ('$playerID', 'coord[$i]')"; $result = mysql_query($sql ,$con); } } The code inserts the correct number of records, along with the correct playerID, the problem is, instead of coords like 12,140, I am getting the following: coord[0] coord[1] coord[2] coord[3] ...etc, instead of 121,123 141,22 192,102 ...etc I am not sure why this is happening. I have made sure to call my variable ( $coord=$_POST['coord']; so it should be showing up correctly. I am using the same code in another script for ingredients in recipes and it works perfectly fine. Any suggestions would be helpful! Could it be the , inbetween the numbers that is causing the problem? Link to comment https://forums.phpfreaks.com/topic/205012-issue-with-arrays-saving-multiple-coordinates/ Share on other sites More sharing options...
kenrbnsn Posted June 17, 2010 Share Posted June 17, 2010 In this line: <?php $sql = "insert into coords (playerID, coord) values ('$playerID', 'coord[$i]')"; ?> coord[$i] is a literal, since you forgot the "$" in front of it. <?php $sql = "insert into coords (playerID, coord) values ('$playerID', '$coord[$i]')"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/205012-issue-with-arrays-saving-multiple-coordinates/#findComment-1073265 Share on other sites More sharing options...
Jax2 Posted June 17, 2010 Author Share Posted June 17, 2010 Yet again, another stupid mistake. Thanks much. Spent a long time looking for the obvious :/ Link to comment https://forums.phpfreaks.com/topic/205012-issue-with-arrays-saving-multiple-coordinates/#findComment-1073270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.