MySQL Forums
Forum List  »  PHP

How to execute multiple blocks of SQL in PHP ?
Posted by: Arthur Chan
Date: November 13, 2018 10:10PM

Issue:
I need to check the validity of two identifiers that the user entered via Java and sent via https to PHP.
The variables, CID and TID, are of type INT.
PHP would only execute the first block of codes to check the first variable, in this case CID, but then drops out of the script without checking the 2nd block.

What I have done so far:
Research on the internet suggested I do this
$conn = mysql_connect('localhost','user','pwd', instance, 65536)
then create a multi-statemebnt block like this
mysql_query("
// SQL query
// SQL query
");
It didn't work for me b/c I cannot embed PHP processing logic betw successive SQL queries.

Question:
How do I get PHP to continue executing after the first block of codes?

Codes that I have tried, works for 1st block, then drops out of the script:
<?php
$con = mysqli_connect("localhost", "user", "pwd", "instance");
mysqli_set_charset( $con, "utf8mb4" );
if (mysqli_connect_errno($con)) {
   die('Failed to connect to MySQL : ' .mysqli_connect_error());
} 
$cI= (int)$_POST['CI']; 
$fT= (int)$_POST['FT'];


$testCI = "SELECT CName from Company WHERE CID='$cI'";
$result = mysqli_query($con,$testCI);
$numrows = mysqli_num_rows($result);
printf("Number of rows : ". $numrows);
if (!$numrows >0){
     die("Check CID : " .mysqli_error());
} 
// printf("Number of rows : ". $numrows);
//while ($row=mysqli_fetch_row($result)){
//     printf("%s\n",$row[0]);
//}

mysqli_free_result($result);
mysqli_free_result($numrows);

$testFT = "SELECT TName from Company WHERE TID='$fT'";
$result = mysqli_query($con,$testFT);
$numrows = mysqli_num_rows($result);
printf("Number of rows : ". $numrows);
if (!$numrows >0){
     die("Check TID : " .mysqli_error());
} 

// TODO insert record if both CID and TID are correct

mysqli_close($con);
?>

Options: ReplyQuote


Subject
Written By
Posted
How to execute multiple blocks of SQL in PHP ?
November 13, 2018 10:10PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.