MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 12th, 2005, 06:26 AM
Glo Glo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 2 Glo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 40 sec
Reputation Power: 0
Question 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>

Reply With Quote
  #2  
Old March 12th, 2005, 11:11 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 13
Get rid of the comma after
GoalsFor = '$_POST[GoalsFor]'

Commas in SQL statements are for separating different elements inside a specific clause. A comma between the last element of one clause (SET, in this case) and the beginning of a new one (WHERE, in this case), will cough up a syntax error every time.


Reply With Quote
  #3  
Old March 12th, 2005, 12:28 PM
Glo Glo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 2 Glo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 40 sec
Reputation Power: 0
Smile You were so right!

Thank you! You are the best! My form is working. And I am very happy to move on to new things now.

Reply With Quote
  #4  
Old June 20th, 2017, 02:52 AM
PaulOner PaulOner is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2017
Posts: 1 PaulOner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 1 m 10 sec
Reputation Power: 0
Switch to Hybrid Mode

I think, that you are not right. I am assured. Write to me in PM, we will communicate.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > UPDATE $_POST [id] does not update record


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap