Jump to content

how to display successful msg together with commit action?


Recommended Posts

mysql_query("COMMIT");
echo "</br>successful added";

tested with abnormal termination ..and found sometime ...the system already commit but doesnt display the successful msg....(maybe my abnormal termination taken after commit and before display successful msg.

how to make commit and success msg ....appear together?

 

and another question..does rollback keyword needed..since...no commit...and the system wont save the last transaction..

 

The mysql_query() functin returns false if the query is not executed, or there occured an error.

Use an if statement.

<?php
if (false == ($var = @mysql_query("COMMIT"))) {
   // error..
  echo 'There was an error: ' . mysql_error() . '.';
}
else {
   //success
  echo 'Success: ' . $var . '.';
}

<?php
mysql_query("COMMIT");
                                                         <------abnormal terminate at here....
if (false == ($var = @mysql_query("COMMIT"))) {
   // error..
  echo 'There was an error: ' . mysql_error() . '.';
}
else {
   //success
  echo 'Success: ' . $var . '.';
}

 

wat if abnormal terminate at the point show above? will it still running the following line which showing success or failure msg? since the program already terminated(stopped at the point) at the point

<?php
include '../../../config.php';
include '../../../opendb.php';

include '../adminmain.php';
include '../../../pyramidfunction2.php';


mysql_query("BEGIN");


//insert admin card module!!!!!!!!!!!!!

if(isset($_POST['insertadmincard'])){
//store admin card into gamecard table
	$result=mysql_query("SELECT * from rate ORDER BY RID");


	//while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	$lastcardserial=findcurrentserial();

	for($i=0,$count=$_POST['admincardnum'];$i<$count;$i++) {
	$lastcardserial+=1;

	$ID="Admin".($lastcardserial-1000);
	$sql="INSERT INTO gamecard(Serialnum,Serial,Ownerid)
              VALUES
    ('$ID','$lastcardserial','AdminCard')";
	mysql_query($sql);
	mysql_query("UPDATE gamecard SET LatestSerial='$lastcardserial'") or die(mysql_error());

	//$pyrtable=findpyramid($ID);
	$prytable=$_POST['assotable'];
	echo "</br>prytable=".$_POST['assotable'];

	addpyramidcard($ID,$_POST['assotable']);
    	  		    
    	setpyramidbonus($ID,$_POST['assotable']);


	}

		     



}

function findcurrentserial(){
$result=mysql_query("SELECT Serial from gamecard ORDER BY Serial DESC LIMIT 1 LOCK IN SHARE MODE");

	if(mysql_num_rows($result)==0){
		return 1001;

	}



while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ 
	$serial=$row[serial];


}
return $serial;








}


mysql_query("COMMIT");
//echo "</br>successful added";

if (false == ($var = @mysql_query("COMMIT"))) {
   // error..
  echo 'There was an error: ' . mysql_error() . '.';
}
else {
   //success
  echo 'Success: ' . $var . '.';
}






include '../../../closedb.php';







?>



<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head> 


<form name='insertadmincard' action='admincard.php' method=post>
<table border="3">
<tr>
<td>Number of Admin card to be insert into pyramid公司卡数目</td>
<td><input type="text" name=admincardnum></td>
</tr>
<tr>
<td>Select which pyramid table to be insert选择输入的金字塔</td>


                <td><select name=assotable>
                <?php
                include '../../../config.php';
                include '../../../opendb.php';
                
                $result2 = mysql_query("SELECT * FROM pyramidT") or die('Query failed: ' . mysql_error());
                while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){

                 if($row[AssoTable]==$row2[TableName]){
                 echo "<option value=$row2[TableName] selected='selected'>$row2[TableName]</option>";
                 }//end if
                 else{
                 	echo "<option value=$row2[TableName]>$row2[TableName]</option>";                 	
                 }//end else
                                  
                 }//end while
                 include '.../../../closedb.php';
                 ?>
                 </select>
                 </td>
</tr>
<tr>

<td><input type="submit" name='insertadmincard' value='insert'><td>
</tr>
</table>
</form>


</html>

mysql_query("COMMIT");
//echo "</br>successful added";

if (false == ($var = @mysql_query("COMMIT"))) {
   // error..
  echo 'There was an error: ' . mysql_error() . '.';
}
else {
   //success
  echo 'Success: ' . $var . '.';
}

I am wondering why you use mysql_query("COMMIT"); even it is already in condition.

So remove it and condition will check whether true or false.

Try nuxy code without that like:

//mysql_query("COMMIT");
//echo "</br>successful added";

if (false == ($var = @mysql_query("COMMIT"))) {
   // error..
  echo 'There was an error: ' . mysql_error() . '.';
}
else {
   //success
  echo 'Success: ' . $var . '.';
}

wat i want is...when user abnormal terminate..then it still will display the error msg(althought it already terminated)

and now also when the system is display the success msg but seem not at the same time with the commit action..

(is it cause by slow speed of my computer)?

 

the query is performing faster than the display in the page.....which sometime already commit..but havent display it on the page yet.

well since HTTP is a stateless protocol it terminates when the button is pressed the only way you could do it is through AJAX and I do not think that would work too if the stop button is pressed!

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.