fogofogo Posted July 5, 2006 Share Posted July 5, 2006 Hello All,I have a script that displays and allows users to edit records in a mysql database. It displays the information correctly, but when I try to edit the information through forms I have created, it gives me the "successful" message, but makes no changes to the database. I have printed out the sql, which looks like this... UPDATE division_1 SET Team='Dundee', Played='2', Won='3', Lost='4', Drawn='3', [For]='12', Against='5', Points='12' WHERE ID=2and heres what the sql in the code looks like...UPDATE division_1 SET Team='".$Team."', Played='$Played', Won='$Won', Lost='$Lost', Drawn='$Drawn', [For]='$For', Against='$Against', Points='$Points' WHERE ID=".$id;theres probably blinding errors - I'm fairly new to this.Heres my code that inserts it into the database (sorry its a mess) - [CODE]<?php$host = "localhost";$user = "root";$passw="password";$db = "millhill";$connection = @mysql_connect($host, $user) or die (mysql_error());mysql_select_db($db, $connection) or die (mysql_error());$id = $_GET['id'];$Team = $_POST['Team'];$Played = $_POST['Played'];$Won = $_POST['Won'];$Lost = $_POST['Lost'];$Drawn = $_POST['Drawn'];$For = $_POST['For'];$Against = $_POST['Against'];$Points = $_POST['Points'];$submit = $_POST['submit']; if ($id) { if ($submit) { $sql = "UPDATE division_1 SET Team='".$Team."', Played='$Played', Won='$Won', Lost='$Lost', Drawn='$Drawn', [For]='$For', Against='$Against', Points='$Points' WHERE ID=".$id; echo $sql; $result = mysql_query($sql); echo $result; echo "Thank you! Information updated.\n"; } else { // query the DB $sql = "SELECT * FROM division_1 WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form method="post" action="<?php echo $PHP_SELF?>"> <input type=hidden name="id" value="<?php echo $myrow["ID"] ?>"> Team:<input type="Text" name="Team" value="<?php echo $myrow["Team"] ?>"><br> Played<input type="Text" name="Played" value="<?php echo $myrow["Played"] ?>"><br> Lost<input type="Text" name="Lost" value="<?php echo $myrow["Lost"] ?>"><br> Won:<input type="Text" name="Won" value="<?php echo $myrow["Won"] ?>"><br> Drawn:<input type="Text" name="Drawn" value="<?php echo $myrow["Drawn"] ?>"><br> For:<input type="Text" name="For" value="<?php echo $myrow["For"] ?>"><br> Against:<input type="Text" name="Against" value="<?php echo $myrow["Against"] ?>"><br> Points:<input type="Text" name="Points" value="<?php echo $myrow["Points"] ?>"><br> <input type="Submit" name="submit" value="Enter information"> </form> <?php }} else { // display list of employees $result = mysql_query("SELECT * FROM division_1",$connection ); while ($myrow = mysql_fetch_array($result)) { printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["ID"], $myrow["Team"], $myrow["Played"]); }}[/CODE]any ideas what I'm doing wrong?Cheers Link to comment https://forums.phpfreaks.com/topic/13717-problem-inserting-data-to-a-mysql-database/ Share on other sites More sharing options...
mrwhale Posted July 5, 2006 Share Posted July 5, 2006 [For]='$For'think that is the problem? Link to comment https://forums.phpfreaks.com/topic/13717-problem-inserting-data-to-a-mysql-database/#findComment-53238 Share on other sites More sharing options...
fogofogo Posted July 5, 2006 Author Share Posted July 5, 2006 not sure if it is - I thought FOR is a reserved name? I could be wrong. anyone know if this is the problem? Link to comment https://forums.phpfreaks.com/topic/13717-problem-inserting-data-to-a-mysql-database/#findComment-53247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.