funny results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

funny results

Post by ghadacr »

I have a script which inserts data into a database(Thats fine) now what the script does it goes through a loop of how many times it should inset the data(thats fine). As shown below:

Code: Select all

<?PHP include 'opendb.php'; ?>

<?PHP include 'header.php'; ?>





<?php
extract($_GET);
$datefrom= $_GET['$datefrom'];
$dateto= $_GET['$dateto'];

// This checks for querystring vars called DateHeld and UserName. If they are
// present, then the if gets executed. If not, then the $DateHeld and $UserName
// vars are unset/undefined
if( isset($_GET['DateHeld'], $_GET['UserName']) )
{
  $DateHelds= $_GET['DateHeld'];
  $UserNames= $_GET['UserName'];
}


$UserNames   = $_GET['UserName'];
$forename  = $_GET['forename'];
$daterep   = str_replace("/","-",$datefrom);
$datereps = str_replace("/","-",$dateto);
$dat = str_replace("/","-",$DateHelds);
$dateheld = str_replace("/","-",date("d/m/Y"));

$newdate = date ("d M Y", strtotime ($daterep));
$newdates = date ("d M Y", strtotime ($datereps));
$newheld = date ("d M Y", strtotime ($dat));
$optionheld = date ("d M Y", strtotime ($dateheld));

$query = mssql_init ("sp_insertClientDetails");

mssql_bind($query, "@Surname", $surname, SQLVARCHAR);

mssql_bind($query, "@UserID", $UserNames, SQLVARCHAR);

mssql_bind($query, "@DateHeld", $optionheld, SQLVARCHAR);

mssql_bind($query, "@ForeName", $forename, SQLVARCHAR);

mssql_bind($query, "RETVAL", &$ClientDetailID, SQLINT2);


if (($result = mssql_execute($query)) === false)
{
    die('Could not execute the query query 2(Insert client)');
}

if(isset($_GET['HotelRoomID']))
 	{
foreach($_GET['HotelRoomID'] as $k=>$k1)
  {
//----Query 5------


///--------------------------------------------

$quess = mssql_init ("sp_SearchHeldRooms");


mssql_bind($quess, "@HotelRoomID", $k1, SQLINT2);

mssql_bind($quess, "@AvailableFrom",$newdate, SQLVARCHAR);

mssql_bind($quess, "RETVAL", &$RoomDateIDs, SQLINT2);


if (($rep = mssql_execute($quess)) == false)
{
    die('Could not execute the query query 5');

//---------------------------------------------------
} else {

if($RoomDateIDs > 0) {

//---query 2---------------------

$qos = mssql_init ("sp_insertOptionRoom");

			mssql_bind($qos, "@RoomDateID", $RoomDateIDs, SQLINT2);

			mssql_bind($qos, "@ClientDetailID", $ClientDetailID, SQLINT2);

			mssql_bind($qos, "@UserName", $UserNames, SQLVARCHAR);

			mssql_bind($qos, "RETVAL", &$OptionRequestID[], SQLINT2);

			//mssql_execute($qos);

		if (($reson = mssql_execute($qos)) === false)
{
    die('Could not execute the query query 4(Option request)');
}

} elseif($RoomDateIDs == "") {







//----Query 3------




$query2 = mssql_init ("sp_HoldRoom");


mssql_bind($query2, "@HotelRoomID", $k1, SQLINT2);

mssql_bind($query2, "@ClientDetailID", $ClientDetailID, SQLINT2);

mssql_bind($query2, "@AvailableFrom",$newdate, SQLVARCHAR);

mssql_bind($query2, "@AvailableTo", $newdates, SQLVARCHAR);

mssql_bind($query2, "@UserName", $UserNames , SQLVARCHAR);

mssql_bind($query2, "RETVAL", $RoomDateID, SQLINT2);

if (($reso = mssql_execute($query2)) == false)
{
    die('Could not execute the query query 3(Hold room)'.$query2);


 						}


                       //    if(isset($RoomDateID) < 1)

//{echo ""; } else {

   	//foreach($RoomDateID as $heldroomsrequest)

                {



The problem starts when i want to output the data i just inputted into the database. What happens is when sometimes it out puts the results and other times it says no results where inputted. As show below is where the data just entered is selected and outputted:



Code: Select all

$holdselect = mssql_init ("sp_selectheldrooms");

	mssql_bind($holdselect, "@RoomDateID", $RoomDateID, SQLINT2);

	if (($resultheld = mssql_execute($holdselect)) == false)
	{
    die('Could not execute the query query 3(Hold room select)'.$holdselect);

	}
}
  $count=mssql_num_rows($resultheld);
//}


										}
					}
	  			{
			}
		}
	}

//-------- Result Set (Held Rooms)-----------




//--------------Result Set(option request)-------

   //if(isset($OptionRequestID) < 1)

//{echo ""; } else {

	//foreach($OptionRequestID as $optionrequest)
  	  //	{
        //
   //	$optionselect = mssql_init ("sp_selectoptionrequest");

 //	mssql_bind($optionselect, "@OptionRequestID", $optionrequest, SQLINT2);

  //	if (($resultoption = mssql_execute($optionselect)) == false)
   //	{
  //  die('Could not execute the query query 3(Option request select)'.$optionselect);

   //	}
//}
  //$counts=mssql_num_rows($resultoption);
// }



?>
<p><font size="+2">The following have either been held on option or been held.</font></p>
<P>
<form action="holdcheck.php" method="get">

  <table width=693 border=0  cellpadding=0 cellspacing=0>
    <tr>
      <td width=89></td>
      <td width=88></td>
      <td width=110></td>
      <td width=96></td>
      <td width=122></td>
      <td width=94></td>
      <td width=94></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <?PHP

if ($count == 0)
  {
echo "<p><br><font size=+2>You have not held any rooms, but if you have made an option request, then the request has gone through.
</p></font><p><input name=button22 type=button onClick=location.href='http://pb-sql/wintersearch.php' value=Back to search>";

}else {


 ?>
    <tr>
      <td colspan="7"><strong><font color="#FF0000" size="7">Rooms held</font></strong></td>
    </tr>
    <tr>
      <td bgcolor="#FFFF00"><strong>Hotel name</strong></td>
      <td bgcolor="#FFFF00"><strong>First name</strong></td>
      <td bgcolor="#FFFF00"><strong>Surname</strong></td>
      <td bgcolor="#FFFF00"><strong>Room type</strong></td>
      <td bgcolor="#FFFF00"><strong>Available From</strong></td>
      <td bgcolor="#FFFF00"><strong>Available To</strong></td>
      <td bgcolor="#FFFF00">&nbsp;</td>
    </tr>
    <tr>
      <?php

while ($row=mssql_fetch_array($resultheld))
{

    echo '<td  bgcolor="#FFFF00" ><input name="HotelName" type="hidden" value="'.$row['HotelName'].'">' . $row['HotelName' ] . '<input name="HotelRoomID" type="hidden" value="'.$row['HotelRoomID'].'"></td>';
	echo '<td  bgcolor="#FFFF00">' . $row['Forename' ] . '<input name="ResortID" type="hidden" value="'.$row['ResortID'].'"></td>';
    echo '<td  bgcolor="#FFFF00">' . $row['Surname' ] . '</td>';
	echo '<td  bgcolor="#FFFF00">' . $row['RoomType' ] . '<input name="Surname" type="hidden" value="'.$row['Surname'].'"></td>';
	echo '<td  bgcolor="#FFFF00"><input name="AvailableFrom" type="hidden" value="'.$row['AvailableFrom'].'">' . $row['AvailableFrom' ] . '</td>';
	echo '<td  bgcolor="#FFFF00"><input name="AvailableTo" type="hidden" value="'.$row['AvailableTo'].'">' . $row['AvailableTo' ] . '<input name="ClientDetailID" type="hidden" value="'.$row['ClientDetailID'].'"></td>';
    echo '<td bgcolor="#FFFF00"><input type="radio" name="RoomDateID" value="' . $row['RoomDateID'] . '" />Select  ' . $row['HotelName'] .' to update </td>';
}

?>
      <td colspan="7"> </td>
    </tr>
    <tr>
      <td colspan="7"> <input name="Confirm" type="submit" value="Confirm"> <input name="flights" type="submit" value="Check for flights">
      </td>
    </tr>
  </table>
 	</form>   <?PHP } ?>
<?PHP


mssql_close()

?>
<?PHP include 'footer.php'; ?>
Really baffled...because when i look into the database i can clearly see the information, but instead ouputs this error message:

Code: Select all

if ($count == 0)
  {
echo "<p><br><font size=+2>You have not held any rooms, but if you have made an option request, then the request has gone through.
</p></font><p><input name=button22 type=button onClick=location.href='http://pb-sql/wintersearch.php' value=Back to search>";

}else {


 ?>
Help please
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

What happens when you run the stored procedure in an sql gui? Does the stored procedure give you the correct results?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you echo out result data along the way to see if there is a bottleneck or perhaps something preventing clean results from coming back?
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Begby wrote:What happens when you run the stored procedure in an sql gui?
When i run it in query analyzer, the querys execute correctly.....
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Found the error, the Stored procedure was returning the wrong value from another table in the database....Thanks for the suggestions
Post Reply