Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Can i do multiple queries like the following

I have page where i update members reservation. The code i have at moment is:

<?
session_start();
include "db_connection.php";
 //$submit=$HTTP_POST_VARS["submit"];
 //$reset=$HTTP_POST_VARS["reset"];
$OrderID = $_POST['OrderID'];
$username = $_POST['username'];
$RegNo = $_POST['RegNo'];
$pickup = $_POST['pickup'];
$dropoff = $_POST['dropoff'];
$datepickup = $_POST['Pick_Up_Date'];
$datedropoff = $_POST['Drop_Off_Date'];
$model = $_POST['model'];
$make = $_POST['make'];
$transmission = $_POST['transmission'];
$RegNo1 = $_POST['RegNo1'];

$_SESSION['RegNo'] = $RegNo;


$_SESSION['datepickup'] = $datepickup;
$_SESSION['datedropoff'] = $datedropoff;
//print_r($_POST);
$datedropoff1 = $_SESSION['datedropoff'];
$datepickup2 = $_SESSION['datepickup'];
$connect = db_connect();
//if ($connect)

$query = "UPDATE reservation SET username = '$username', RegNo = '$RegNo', pickup = '$pickup', transmission1 = '$transmission', dropoff = '$dropoff', datePickUp = '$datepickup', dateReturn = '$datedropoff', Model = '$model', Make = '$make' WHERE OrderID = '$OrderID'";

//$query1 = "UPDATE car SET status = 'Reserved' WHERE RegNo = '$RegNo'";

$result = mysql_query($query,$connect);

include 'success.php';
?>

Could i do three updates on this page like this

$query1 = "UPDATE car SET status = 'Available' WHERE RegNo = '$RegNo1'";
$query = "UPDATE reservation SET username = '$username', RegNo = '$RegNo', pickup = '$pickup', transmission1 = '$transmission', dropoff = '$dropoff', datePickUp = '$datepickup', dateReturn = '$datedropoff', Model = '$model', Make = '$make' WHERE OrderID = '$OrderID'";
$query2 = "UPDATE car SET status = 'Reserved' WHERE RegNo = '$RegNo'";


0
act1ve
Asked:
act1ve
  • 2
  • 2
2 Solutions
 
stefanaichholzerCommented:
act1ve,

 If the only thing you need is a "yes" or "no" answer, then you have the "yes", You can perform as much udpates and queries in the same page or block of code...

 Let me know if you need anything else...

;)
0
 
act1veAuthor Commented:
do i have seperate one of these lines for query?

$result = mysql_query($query,$connect);
0
 
ldbkuttyCommented:
Unless improved mysql extension (mysqli) is used only one query can be executed at a time!

But there is no need to assign the result. This should do:

mysql_query($query1, $connect) or die("Update query1 error: " . mysql_error());
mysql_query($query2, $connect) or die("Update query2 error: " . mysql_error());
mysql_query($query3, $connect) or die("Update query3 error: " . mysql_error());

You should also use mysql_real_escape_string( http://www.php.net/mysql_real_escape_string ) to avoid MySql injection! Simply using the quote_smart() function in the example 3 is enough.
0
 
stefanaichholzerCommented:

 >>  Unless improved mysql extension (mysqli) is used only one query can be executed at a time!

That's totally correct. ldbkutty, it's always good to see you around. :D

act1ve, let us know how it goes or if you need anything else...

;)
0
 
act1veAuthor Commented:
yes all went well
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now