Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
what is wrong with this?

Reply  
Thread Tools
Grob needs help's Avatar
Computer Specs
Member with 280 posts.
 
Join Date: Mar 2009
Location: marldon
Experience: Advanced
06-Feb-2010, 11:21 AM #1
Question what is wrong with this?
i am working on a project to create a simple browser based MMORPG and i am currently trying to create the battle script but i have encountered a problem with updating the mysql table with the users involed in the script, the code i am using is

the $_post data is coming from another page where the opponents are selected

mysql_query("UPDATE fight SET attacked = '$_POST[opponent]' AND attacking = '$_POST[attacker]' WHERE name = '$_POST[opponent]'");
mysql_query("UPDATE fight SET attacked = '$_POST[opponent]' AND attacking = '$_POST[attacker]' WHERE name = '$_POST[attacker]' ");

the problem is it does not update the table at all can anyone help me, i am sure there must be a simple answer

thanks
ehymel's Avatar
Senior Member with 660 posts.
 
Join Date: Aug 2007
Location: Texas
07-Feb-2010, 01:12 AM #2
use some error checking so you can get some clues about what is going wrong:

Code:
mysql_query($query) or die("ERROR: ".mysql_error());
I would also suggest that your code is lacking terribly in some basics checks. In this case, I think you'll see that your sql command is wrong, in turn becase your $_POST syntax is wrong.

A much more robust set of commands would look something like this:
mysql_query("UPDATE fight SET attacked = '$_POST[opponent]' AND attacking = '$_POST[attacker]' WHERE name = '$_POST[opponent]'");
mysql_query("UPDATE fight SET attacked = '$_POST[opponent]' AND attacking = '$_POST[attacker]' WHERE name = '$_POST[attacker]' ");
Code:
$opponent = $_POST['opponent'];
$attacker = $_POST['attacker'];

if (( strlen($opponent) > 0 ) && ( strlen($attacker) > 0 )) {
  $sql = "UPDATE flight SET attacked = '$opponent' AND attacking = '$attacker' WHERE name = '$opponent'";
  $result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

  $sql = "UPDATE flight SET attacked = '$opponent' AND attacking = '$attacker' WHERE name = '$attacker'";
  $result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

} else {
  die("Missing opponent or attacker information; opponent='$opponent' and attacker='$attacker'");
}
I typed this free-hand, so there may be spelling errors, but the point is that you should be doing some checks and taking advantage of built-in error reporting tools.
__________________
E.
Grob needs help's Avatar
Computer Specs
Member with 280 posts.
 
Join Date: Mar 2009
Location: marldon
Experience: Advanced
07-Feb-2010, 07:18 AM #3
ok i have used that code and it come out with

A fatal MySQL error occured.
Query: UPDATE flight SET attacked = 'testuser1' AND attacking = 'testuser2' WHERE name = 'testuser1'
Error: (1065) Query was empty

how do i stop this from happening?
Grob needs help's Avatar
Computer Specs
Member with 280 posts.
 
Join Date: Mar 2009
Location: marldon
Experience: Advanced
07-Feb-2010, 08:57 AM #4
oh hang on i see why:
you put
PHP Code:
$result mysql_query($query
but it should have been
PHP Code:
$result mysql_query($sql
that is most likely why the error was occuring

but now it is not showing any error message but still not doing anything to the database
ehymel's Avatar
Senior Member with 660 posts.
 
Join Date: Aug 2007
Location: Texas
08-Feb-2010, 04:26 PM #5
oops, my by bad! This error is in both places. Sorry about that!
Reply

Tags
mysql, php

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:21 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.