July 13, 201115 yr I'm not completely up to speed on my PHP... When submitting one query everything works fine, however, I have a form that I want to SELECT from one database and DELETE from another, and I can do only one or the other. When I place in two $query as below, only the last works... I imagine I have to submit them differently? <?php if (isset($_POST['id']) && isset($_POST['member']) && isset($_POST['tradedate'])) { $id = get_post('id'); $member = get_post('member'); $tradedate = get_post('tradedate'); $query = "INSERT INTO buytrade VALUE" . "('$id', '$member', '$tradedate')"; $query = "DELETE FROM sell WHERE id='$id'"; if (!mysql_query($query, $db_server)) echo "INSERT failed: $query<br />" . mysql_error() . "<br /><br />"; } echo <<<_END <form action="confirmtradebuy.php" method="post"><pre> ID <input type="text" name="id" /> Member <input type="text" name="member" /> Trade date <input type="text" name="tradedate" /> <input type="submit" value="CONFIRM TRADE" /> </pre></form> _END; ?>
July 13, 201115 yr two different databases need to different connections, or prefix the table name by the database name and dont use "USE" mysql keyword.
July 13, 201115 yr Author two different databases need to different connections, or prefix the table name by the database name and dont use "USE" mysql keyword. Could you give me an example?
July 14, 201115 yr Author Sorry, I made a mistake in my original post. I'm not trying to connect to two different databases - I should have said that I'm trying to connect to two different tables with one form submit. Eg. my form (above in the first post) if it worked, would enter a new post to the selltrade table, and also deletes a post from the sell table using the ID as reference. The website I am working on is http://www.alistairfellowes.com/afexchange/papertradesid.php My aim is to use the form found on the menu under confirm trade > confirm to buy listing from member to add an entry to Completed trades from Selling Listings (bottom left table), and using the corresponding number found in the ID section, remove the corresponding entry from the All Selling offers (left table), but using the same form submit button each of my php - sql commands work fine on the form when i only execute one, but when I put them both together: $id = get_post('id'); $member = get_post('member'); $tradedate = get_post('tradedate'); $query = "INSERT INTO selltrade VALUE" . "('$id', '$member', '$tradedate')"; $query = "DELETE FROM sell WHERE id='$id'"; Usually neither work, sometimes one or the other - usually coming up saying that the entry cant be made due to a foreign key issue.
July 14, 201115 yr Author My error is: INSERT failed: DELETE FROM buy WHERE id='24' Cannot delete or update a parent row: a foreign key constraint fails (`alistairfellowes/buytrade`, CONSTRAINT `buytrade_ibfk_2` FOREIGN KEY (`id`) REFERENCES `buy` (`id`))
Create an account or sign in to comment