Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Multiple $query commands

Featured Replies

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;

 

?>

two different databases need to different connections, or prefix the table name by the database name and dont use "USE" mysql keyword.

  • 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?

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

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.