
March 12th, 2005, 06:26 AM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 2
Time spent in forums: 11 m 40 sec
Reputation Power: 0
|
|
UPDATE $_POST [id] does not update record
Hi,
After trying several canned scripts without success, I decided to take a crack at modifying a script from a book whose author does not field questions.
The script is intended to allow a coach to enter weekly stat updates on the mysql db via a web interface. From there the stats will be displayed on the website.
I have been working on this for days and just can't get it. I've set up login, create db, create tables, and enter data with success. Now I want to be able to modify data in the db. The problem seems to lie in the $sql UPDATE section. The data should post and show a page with the modified record.
I enter the data and get this error:
You have an error in your SQL syntax near 'WHERE id = '2'' at line 9
The 2 (or whichever number appears) is the number of the record I am trying to update.
I am connecting to the db. I can add records an they increment by primary id.
What am I doing wrong?
MySQL 3.23.58 on Linux
PHP Version 4.3.3
PHP Code:
<?php if (!$_POST['Team']) { header( "Location: http://mysite.net/pick_modstand.php"); exit; } else { session_start(); } if ($_SESSION[valid] != "yes") { header("Location: http://mysite.net/contact_menu_mine.php"); exit; } $db_name = "mysite_net_-_mystats"; $table_name = "s05standigs"; $connection = @mysql_connect("mysite", "username", "password") or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); //Suppose to update records in database bu gives me an error like this: //You have an error in your SQL syntax near 'WHERE id = '2'' at line 9 //There's the WHERE id = part 9 lines down from here $sql = "UPDATE $table_name SET Team = '$_POST[Team]', Won = '$_POST[Won]', Lost = '$_POST[Lost]', Tied = '$_POST[Tied]', Points = '$_POST[Points]', GoalsAllowed = '$_POST[GoalsAllowed]', GoalsFor = '$_POST[GoalsFor]', WHERE id = '$_POST[id]'"; $result = @mysql_query($sql,$connection) or die(mysql_error()); ?> <html> <head> <title>Team Record Updated</title> </head> <body> <h1>Lady Hurricanes Stats Program</h1> <h2><em>Team Record Updated</em></h2> <p>The following information was successfully updated in <?php echo "$table_name"; ?></p> <table cellpadding=5 cellspacing=3 > <tr><th>Updated Team Information</th> </tr> <tr> <td valign=top> <p><strong>Team Name:</strong><br> <?php echo "$_POST[Team]"; ?></p> <p><strong>Games Won:</strong><br> <?php echo "$_POST[Won]"; ?></p> <p><strong>Games Lost:</strong><br> <?php echo "$_POST[Lost]"; ?></p> <p><strong>Games Tied:</strong><br> <?php echo "$_POST[Tied]"; ?></p> <p><strong>Total Points:</strong><br> <?php echo "$_POST[Points]"; ?></p> <p><strong>Goals Against:</strong><br> <?php echo "$_POST[GoalsAllowed]"; ?></p> <p><strong>Goals Scored:</strong><br> <?php echo "$_POST[GoalsFor]"; ?></p> <p><a href="contact_menu_mine.php">Go Back to Main Menu</a></p> </td> </tr> </table> </body> </html>
|