Link to home
Start Free TrialLog in
Avatar of peter Ojeda
peter Ojeda

asked on

Two different types of values being stored in SQL

Hi experts, I have a weird situation in my SQL table where values are being placed two different ways.(Please view the picture attached). This data is being inserted by two PHP pages, one performing an insert statement and another performing a modify.

The insert statement is the one displaying the values as centered, but if I used my modify page, the centered value is then aligned to the left.

I have tried to understand what the difference between the two are but have not found out online. The data should be centered, not aligned to the left.
EX_EE_VALUES.PNG
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

need to know:

1. what's your database?

2. how data are being inserted / modify > can you post the codes here?

3. what's the data type of that field?

4. what database client browser are you using here?
Avatar of peter Ojeda
peter Ojeda

ASKER

Sorry yes I am using a MSSQL Database and using php to do the insert/modify area. The field PREV_JOB_PO is a varchar field.
Below is the insert statement. the variable $PONUMBER comes from $result1["PROD_ORDER"], which is pulled from another select statement on submission. This part is working, and the value PREV_JOB_PO is being populated correctly (aligned center)
<?php
$PONUMBER = $result1["PROD_ORDER"];
}
}
	//remove error messages
	ini_set('display_errors', 0);
	$serverName = "XXXXX";
	$userName = "";
	$userPassword = '';
	$dbName = "XXXX";

	$connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);

	$conn = sqlsrv_connect( $serverName, $connectionInfo);

	if( $conn === false ) {die( print_r( sqlsrv_errors(), true));}
	$sql = "INSERT INTO JOBCHANGE_DATA_test (DATE_REC, FEEDER_NO, PROCESS_NUM, PREV_JOB_PO)VALUES ( ?, ?, ?, ?)";

	$params = array($_POST["today"],$_POST["FEEDER_NO"], $_POST["procnumb"], $PONUMBER );

Open in new window


The code for the modify page is below and is also working to an extent. The data changes, but on submission the value in PREV_JOB_PO changes to left-alligned. The values are all being sent to this page from a previous page by $_POST.
$serverName = "XXXXX";
	$userName = "";
	$userPassword = '';
	$dbName = "XXXX";


	$connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);

	$conn = sqlsrv_connect( $serverName, $connectionInfo);

	if( $conn === false ) {
		die( print_r( sqlsrv_errors(), true));
	}

	$sql = "UPDATE JOBCHANGE_DATA_test  SET 
				DATE_REC = ? ,
				FEEDER_NO = ? ,
				PROCESS_NUM = ? ,
				PREV_JOB_PO = ?
				WHERE ID = ? ";
				
$params = array($_POST["DATE_REC"],$_POST["FEEDER_NO"], $_POST["PROCESS_NUM"], $PREVJOBPO,$_POST["ID"]);

	$stmt = sqlsrv_query( $conn, $sql, $params);
	if( $stmt === false ) { die( print_r( sqlsrv_errors(), true));}
	else
	{echo "Thank you. Your update has been submitted.";}
	sqlsrv_close($conn);if(isset($_POST['Submit']) ){

Open in new window

for your update part:

	$sql = "UPDATE JOBCHANGE_DATA_test  SET 
				DATE_REC = ? ,
				FEEDER_NO = ? ,
				PROCESS_NUM = ? ,
				PREV_JOB_PO = ?
				WHERE ID = ? ";
				
$params = array($_POST["DATE_REC"],$_POST["FEEDER_NO"], $_POST["PROCESS_NUM"], $PREVJOBPO,$_POST["ID"]);

Open in new window


can you trace what value being stored in $PREVJOBPO ?
The Value being stored in $PREVJOBPO is being posted from my previous page that has an input box.
I am performing a sql select to get the value $result["PREV_JOB_PO"] and putting it into the text box, then submitting it to the second page that contains the update query
<td><input type="text" name="PREV_JOB_PO" style="width: 80px;"  value="<?php echo $result["PREV_JOB_PO"];?>"></td>

$PREVJOBPO = $_POST["PREV_JOB_PO"];
What makes you think the centred values are being inserted correctly. If your column is varchar, then the only way I can see that the column is 'centered' is if the value has spaces padded at the start (which would appear to be wrong). The values that are modified don't have these spaces which I guess would be correct.

You say you get the INSERT value from another query (you've not shown us that code). Is it possible that another part of your code is doing some manipulation on the value (padding / converting to-from a number etc)
I didn't include why the centered value appears to be correct because I had a hard time explaining it myself. Basically, on another php page I use that centered value in a select statement inside of a while loop. The values that are centered run fine, but I have noticed the values that are not centered is where I have issues.
The code below is where I get the insert value from, then post that value into the insert query.
When the first page is inserted, the value "oldjobnum" goes into a select query, which gets me the po, that is then used in the insert query as $PONUMBER = $result1["PROD_ORDER"];.
	$serverName = "XXXX";
	$userName = "";
	$userPassword = '';
	$dbName = "XXXX";
   $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
   $conn1 = sqlsrv_connect( $serverName, $connectionInfo);
	if( $conn1 === false ) {
		die( print_r( sqlsrv_errors(), true));
	}
    $stmt1 = "SELECT TOP (1) [PROD_ORDER]

  FROM [XXXX].[dbo].[JC]
  WHERE [NEW_JOB_NUMBER] = ?";
  $params1=array($_POST["oldjobnumb"]);
   $query1 = sqlsrv_query($conn1, $stmt1, $params1);
?>
<table width="50" border="1" id="myTable">
  <tr>
	<th width="91" nowrap> <div align="center">PO</div></th>
  </tr>
<?php
while($result1 = sqlsrv_fetch_array($query1, SQLSRV_FETCH_ASSOC))
{
?>
  <tr>
	<td NOWRAP><div align="LEFT"><?php echo $result1["PROD_ORDER"];?></div></td>
  </tr>
<?php
$PONUMBER = $result1["PROD_ORDER"];
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sir you are correct.. I originally did test with adding blank space, but I added 5 blank spaces instead of 6.. Thankyou very much.
No worries. Glad you got it sorted :)