Jump to content

Recommended Posts

I know most of you guys hate to hear this but I'm relatively new to php, i'm working on a personal site and have created this code that basically removes all members of a softball team.  The code works like a charm for me, as it updates all members of a given team id and sets there team and team_id to NULL.  This is my question, am I doing this the PHP correct way?  Is there another way I could do this that is PHP correct?  I could sit on here for light years and ask you experts questions that I have about PHP but i'll spare you guys tonight.

 

Thanks in advance and any help any guidance is appreciated.. 

 

   $query = "select username, team_id, team FROM tgl_users WHERE team_id = '".$_GET['team_id'] ."'";
   $result = mysql_query($query, $dbc); 
   //run the while loop 
   while($r=mysql_fetch_array($result)) {
//delete info from all users of team_id
$query_update = "UPDATE tgl_users SET team=NULL, team_id=NULL, coach=NULL WHERE team_id = '".$_GET['team_id'] ."'"
or die(mysql_error());
mysql_query($query_update, $dbc)
or die(mysql_error());
   }
   	echo 'team has been deleted and all users have been removed';

} 

Link to comment
https://forums.phpfreaks.com/topic/194080-better-way-to-reword-code/
Share on other sites

One thing i know is that

 

$query = "select username, team_id, team FROM tgl_users WHERE team_id = '".$_GET['team_id'] ."'";
$result = mysql_query($query, $dbc); 

 

can be shortened to

 

   $result = mysql_query("select username, team_id, team FROM tgl_users WHERE team_id = '".$_GET['team_id'] ."'", $dbc); 

 

and same with

 

mysql_query("UPDATE tgl_users SET team=NULL, team_id=NULL, coach=NULL WHERE team_id = '".$_GET['team_id'] ."'", $dbc) or die(mysql_error());

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.