Jump to content

Set 'status' To 'open' On Newly Submitted Questions


Classico

Recommended Posts

Basically, I have a form which my players fill in. Which then gets submitted to my database, and sets the question 'status' field to 'Open'. I have that working, but there's a problem.

 

When you submit a question, and my update query is executed, it sets every row in the database to 'Open' in the 'status' field. Is there a way to just set it to open for just that ticket?

 

Here is my code for inserting.

$query = mysql_query("INSERT INTO unbanappeal (username, email, topic, banned_you, ban_reason, unban_reason
   , ticket_id)
   VALUES ('$username','$email', '$topic','$banned','$banned_for','$why_unban','$ticket_id')") or die(mysql_error());

   $set = mysql_query("UPDATE unbanappeal SET status = 'Open'");

 

Also, is there a way to have SET in my $query. I've tried it, but it never worked.

There are several ways to approach this that would *work*; however, the one that makes the most sense is to have "Open" as the default value for the `status` column in the `unbanappeal` table. That way, any time an appeal is submitted, it is automatically an "open" ticket.

 

Then, once the issue/ticket has been closed (or whatever you do with it), you can then update the `status` to "Closed".

 

That is your best bet.

 

To address your current method, naturally all records would update based on your UPDATE query. You are not specifying a specific record. For future reference, use mysql_insert_id() (however, the method you are currently using is not recommended; use the method I posted already):

 

$query = mysql_query("INSERT INTO unbanappeal (username, email, topic, banned_you, ban_reason, unban_reason, ticket_id) VALUES ('$username','$email', '$topic','$banned','$banned_for','$why_unban','$ticket_id')") or die(mysql_error());
$insert_id = mysql_insert_id();

$set = mysql_query("UPDATE unbanappeal SET status = 'Open' WHERE `id` = ". $insert_id);

 

That is dependent on you having an ID column of sorts with AUTO INCREMENT.

 

Another method would be to add the "Open" value to the INSERT query:

 

$query = mysql_query("INSERT INTO unbanappeal (username, email, topic, banned_you, ban_reason, unban_reason, ticket_id, status) VALUES ('$username','$email', '$topic','$banned','$banned_for','$why_unban','$ticket_id','Open')") or die(mysql_error());

 

Again, use first method with default value for `status` column.

There are several ways to approach this that would *work*; however, the one that makes the most sense is to have "Open" as the default value for the `status` column in the `unbanappeal` table. That way, any time an appeal is submitted, it is automatically an "open" ticket.

 

Then, once the issue/ticket has been closed (or whatever you do with it), you can then update the `status` to "Closed".

 

That is your best bet.

 

To address your current method, naturally all records would update based on your UPDATE query. You are not specifying a specific record. For future reference, use mysql_insert_id() (however, the method you are currently using is not recommended; use the method I posted already):

 

$query = mysql_query("INSERT INTO unbanappeal (username, email, topic, banned_you, ban_reason, unban_reason, ticket_id) VALUES ('$username','$email', '$topic','$banned','$banned_for','$why_unban','$ticket_id')") or die(mysql_error());
$insert_id = mysql_insert_id();

$set = mysql_query("UPDATE unbanappeal SET status = 'Open' WHERE `id` = ". $insert_id);

 

That is dependent on you having an ID column of sorts with AUTO INCREMENT.

 

Another method would be to add the "Open" value to the INSERT query:

 

$query = mysql_query("INSERT INTO unbanappeal (username, email, topic, banned_you, ban_reason, unban_reason, ticket_id, status) VALUES ('$username','$email', '$topic','$banned','$banned_for','$why_unban','$ticket_id','Open')") or die(mysql_error());

 

Again, use first method with default value for `status` column.

 

I never really thought about using the first method. But it's the method that I'm currently using now, thanks a lot :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.