Classico Posted December 10, 2012 Share Posted December 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271822-set-status-to-open-on-newly-submitted-questions/ Share on other sites More sharing options...
mrMarcus Posted December 10, 2012 Share Posted December 10, 2012 (edited) 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 December 10, 2012 by mrMarcus Quote Link to comment https://forums.phpfreaks.com/topic/271822-set-status-to-open-on-newly-submitted-questions/#findComment-1398541 Share on other sites More sharing options...
Classico Posted December 13, 2012 Author Share Posted December 13, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/271822-set-status-to-open-on-newly-submitted-questions/#findComment-1399231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.