473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

update php and mysql form

hi i need help in making update script
i don't want form or any thing i want that user get active by admin, when admin visit player-update.php it update all user
here is code i am using

Expand|Select|Wrap|Line Numbers
  1.     $query = "SELECT join_survivor.join_user, join_survivor.join_pool, join_survivor.join_done, join_survivor.join_fight, events_fights.event_id, join_survivor.join_event, events_fights.fight_id, join_survivor.join_win, join_survivor.join_lost, events_fights.win, events_fights.lost, survivor_events.event_id, survivor_events.event_period, join_survivor.join_pick ".
  2.     "FROM join_survivor, events_fights, survivor_events ".
  3.        "WHERE join_survivor.join_pick = '1' AND join_survivor.join_done = '0' AND events_fights.event_id = join_survivor.join_event AND join_survivor.join_event = survivor_events.event_id AND survivor_events.event_period = 'past' AND join_survivor.join_win = events_fights.lost  AND join_survivor.join_fight = events_fights.fight_id";
  4.  
  5.  
  6.     $result = mysql_query($query) or die(mysql_error());
  7.     while($row = mysql_fetch_array($result))
  8.     {
  9.     mysql_query(" UPDATE join_survivor SET join_done ='1', join_pick='0' WHERE join_done = '0' AND join_pick = '1' AND event_period = 'past'");
  10.     mysql_query($query) or die ('Same entry please go back');
  11.     }

the problem is this when join_survivor.join_win = events_fights.lost it update whole table, i want that it only update that user only please help me out, if u don't understand let me know, because i have really bad english
thanks in advance
Jul 9 '11 #1
2 1531
Somewhere, you need to be limiting your SQL to the relevant User ID's which isn't mentioned anywhere in the sql you posted.

First, you are performing an unnecessary SELECT operation which doesn't do anything for you other than retrieve some records from the database, but these don't relate to your UPDATE clause in any way.

Then, you are performing an UPDATE which runs exactly the same command over and over. You probably need something in your WHERE clause for the UPDATE that tells it which users you are trying to update (and get rid of the WHERE loop).

Tip: You can also shorten your SQL quite a bit by using 'table aliases'. Eg..
Expand|Select|Wrap|Line Numbers
  1. SELECT js.join_user, ef.event_id FROM join_survivor AS js, events_fights AS ef WHERE ef.event_id = '67'
Jul 11 '11 #2
johny10151981
1,059 1GB
In order to avoid update problem follow two approaches
1. always use a recordid which is primary and auto incremental
2. update as follow: "UPDATE [TABLE] SET field1='..', ... WHERE [conditions] LIMIT 1";
3. Incase of delete do the same: "Delete FROM [TABLE] WHERE [conditions] LIMIT 1"
Jul 16 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Haas | last post by:
Hi, does anyone know of a simple function/class that will take config options: table name and the database connection stuff(or whatever) It will then print out appropriate form fields to allow...
7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or...
1
by: mpmason14 | last post by:
i want to update my "timesheet" form based upon a second form "add employee" whenever a new employee is added. right now the "add employee" form adds the employee to the table, but it doesn't update...
4
by: whitemoss | last post by:
Hi, I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors: client.c: In function senddata:...
4
by: geof | last post by:
Hi ! this is my first post where is my error code in line 15 ($sql ) <html> <head><title> update MySQL Data </title></head> <body bgcolor="#FFFFFF"> <?
1
by: roger.rigsby | last post by:
Ok I know how to get the data I want from mysql but I need to actually do something with this data and then send it back to mySQL. Company heads love the spreadsheet view so this is serious...
1
tolkienarda
by: tolkienarda | last post by:
i need to update a database table using variables in unusual places here are the update statements mysql_query("UPDATE 'grades' SET '$class' = '$grade' WHERE student='$student'");...
11
by: stantron | last post by:
Setup: I only have one database with one table in it. The first page has a form that adds a record (w/ 6 fields in it) to the mySQL database's lone table via PHP. This works fine. I also have a PHP...
1
by: blekok | last post by:
I'm trying to use MS Access for the front end and MySQL as the Data source. I have this MS Access form which uses a table called hotel:...
4
by: Big P | last post by:
I need to update a form everytime a button is clicked. My form has more than 20 buttons. So need i to find out what is the best event to do that. I am new to VB Express and now i have the time...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.