Jump to content

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


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.

Edited by mrMarcus

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 :)

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.