![]() |
| ||
| Multiple SQL Queries in PHP page Hi all, I have been racking my brain today, trying to get a page to run 2 queries. Basically i have a page that has a form on it and there is a bunch of numbers in one of the drop down lists that comes from a table called cab_eticket_numbers this and the rest of the data on this form is posted to a MySQL table called cab_details, which works all good. However I also need to update a flag in the cab_eticket_numbers table called cab_eticket_used so that the number does not come up in the drop down list again. Can someone please advise how you would do this? I have checked out google and found a few things (such as http://www.artfulsoftware.com/infotree/tip.php?id=799) however dont seem to make much sense, i feel there has to be a better way as i thought this would be a rather common scenario? Any help would be much appreciated, maybe even if i could use the same query that i use to do the INSERT if i cant have 2 queries. Any help would be much appreciated. Thanks very much in advance. |
| ||
| Re: Multiple SQL Queries in PHP page Why shouldn't you be able to use more than one query in a php-file? When I got you problem correctyl you want to save the selected dropdown as a flag in the table mysql_query("UPDATE `cab_eticket_numbers` SET `cab_eticket_used`=1 WHERE `number`=".$yourphpvariable);and secondly you want to hide it the second time:mysql_query("SELECT * FROM `cab_eticket_numbers` WHERE `cab_eticket_used`=0");I hope I got you right. |
| ||
| Re: Multiple SQL Queries in PHP page Yeah kinda what I am after I don't actually want to save the selected item from the drop down... but the query will be based on one of the drop downs. Here is a copy of the page. The SQL with variable $sql (The INSERT) works fine and the database is populated perfectly. However the second one with variable $updateused (The UPDATE) does not seem to do anything at all? <? |
| ||
| Re: Multiple SQL Queries in PHP page I have not yet solved the problem as i still can not get the UPDATE query to use the variable $cab_eticket_number to be used as part of the SQL query. I did spot an error in my above code with the UPDATE query where it was setting it to 0 instead of 1, this has been corrected, however as i said still having the issue. I tried to hard code the UPDATE without using the $cab_ticket_number variable and it seemed to work ok.... anyone have any ideas what im doing wrong here? Thanks |
| ||
| Re: Multiple SQL Queries in PHP page Spotted the problem, instead of using the variable name i should have used the POST to get the ticket number. I replace the UPDATE with the one below and all works perfect now. $updateused = "UPDATE cab_managernumbers SET cab_ticket_used = 1 where cab_eticket_number = ". $_POST["cab_eticket_number"] .""; |
| ||
| Re: Multiple SQL Queries in PHP page Quote:
Taking variables directly from the POST, GET or QUERY in PHP is not safe, it leaves your script vunerable to injection attacks.. You should be taking the POST variable and sanitizing it first (for instance, a number should only contain the characters 0-9) you could do the following: if(is_numeric($_POST["cab_eticket_number"])) { |
| ||
| Re: Multiple SQL Queries in PHP page You beat me to it Xan :) I too noticed the use of $_POST and $_GET vars directly in the queries, something you absolutely do not want to do. If you have some kind of user-input validation on the client-side, it isn't good enough, client-side validation is for user convenience so they don't have to post the page only to have it reload and tell them there was a problem. This is one lesson you do not want to learn the hard way ;) |
| All times are GMT -4. The time now is 5:30 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC