Jump to content

Two actions on one button?


Mr Chris

Recommended Posts

Hi Guys,

I have a php page which i've written - this:

1) Finds an area via a GET function ie:
[url=http://www.slougheaz.org/directory/deletion_of_area/delete.php?the_town=Fife]http://www.slougheaz.org/directory/deletion_of_area/delete.php?the_town=Fife[/url]

2) Says how many records are associated with the_town (fife in this example) in a table named ‘directory_listings’

3) And calls out values from a table named ‘prop_areas’ into a combo box.

And an example of what I’m doing can be found here:

[url=http://www.slougheaz.org/directory/deletion_of_area/delete.php?the_town=Fife]http://www.slougheaz.org/directory/deletion_of_area/delete.php?the_town=Fife[/url]

[code=php:0]

<?PHP

// Get the townl address from the URL
$actual_town = $_GET['the_town'];

//Start Connection to DB
function db_connect()
{
$result = @mysql_pconnect("localhost", "*******************", "************");
if (!$result)
{
return false;
}

if (!@mysql_select_db("sleaz_directory"))
{
return false;
}

return $result;
}
//End Connection to DB

// Check the connection to the database
       
$can_i_connect = db_connect(); // by db_connect function is in my include file
if(!$can_i_connect)
  {
    echo "Could not connect to database";
  } 

// End the connection to the database

// Start Functions to pull out areas

function db_result_to_array($result)
{
  $res_array = array();

  for ($count=0; $row = mysql_fetch_array($result); $count++)
    $res_array[$count] = $row;

  return $res_array;
}

function get_areas() {
    $query='SELECT * FROM prop_areas ORDER BY the_region';
    $result=mysql_query($query);
    if(FALSE==$result)
        return false;
    if((0 || FALSE)==mysql_num_rows($result)) {
        return false;
    } else {
        $result=db_result_to_array($result);
        return $result;
    }
}

// End Functions to pull out areas

?>


<html>
<head>
<title>Search Results ...</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>// Remember front screen dictakes what is deleted<p>You are about to delete the area: <b><?php echo $actual_town; ?></b>
<p>You have <b>
<?php

$actual_town = $_GET['the_town'];

$search_query = "SELECT * FROM directory_listings WHERE town='$actual_town'"; 

$search_results = mysql_query($search_query, $can_i_connect);
$result = mysql_query($search_query) or die (mysql_error());

$number_of_results = mysql_num_rows($search_results);

if($number_of_results <= 0)
{
echo "There are currently <b>NO</b> businesses associated with this area";
}

// Else and Start to find how many pagination pages I have
        else
        {
        echo "<b>**WARNING: There are ".$number_of_results." business(es). associated with this area.  Where yould you like to move these ".$number_of_results." business(es) **  <br /><br />";
        }
?>
</b>
<p><font color="#CC0000">Which area would you like to Move these areas to:?</font><br />
<br />
<FORM NAME="form1" METHOD="post" ACTION="">
Area: <select class="input" name="location" id="location">
<option value="" selected> </option>
<?PHP
$area_array=get_areas();
foreach ($area_array as $thisarea) {
    //print_r($thisarea);
  print("<option value=\"".$thisarea['the_region']."\">".$thisarea['the_region']."</option>\n");
}
?>
</select> 
<p><input type="submit" name="Submit" value="Delete Area &amp; Move to Chosen Dropdown Option">
</form>
</body>
</html>

[/code]

Now when submit is hit I want the page to do two things (this is what I’m stuck on):

1) Update the ‘propeties’ table to whatever is selected from the dropdown menu value replacing what the GET value is in $actual_town
2) Delete the GET value in $actual_town

Now I’ve written how I thought the two queries would work:

[code=php:0]
// Start Update records from database
if(isset($_POST['Submit']))
{
$query = "UPDATE properties SET town = '$area_array' WHERE town = '$actual_town'";
// Ie Update table properties and set the town field to what is selected from the below combo box where the town in table properties is equal to the GET actual_town (called on top of the script)

mysql_query($query) or die (mysql_error()); 
}
// End Update records from database

// Start Delete records from database
if(isset($_POST['Submit']))
{
$query = "DELETE FROM prop_areas WHERE the_region = '$actual_town'";
mysql_query($query) or die (mysql_error()); 
}
// End Delete records from database

[/code]

But how do I get that into One query so when submit is hit ONCE it performes two queries  - updates one table, then deletes the other?

And also my Update Query does not get the value selected from the combo box to update it in the ‘properties’ table?

Can anyone please help me with the queries?

Thanks

Chris
Link to comment
Share on other sites

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.