I have my WHILE conditional inside the ELSE conditional...is that legit?
Printable View
I have my WHILE conditional inside the ELSE conditional...is that legit?
It is, but you need to remember that loops need brackets too. You're missing brackets around your loop.
I figured it out. The mssql_fetch_row() function returns only an enumerated array, not an associative array like the mssql_fetch_array() function does. In my WHILE loop I defined variables as $line['barcode'] (associatively) for example rather than enumerated...i.e. $line[0]. I needed to either change the function to mssql_fetch_array() and specify the MSSQL_ASSOC parameter (which is not valid with the mssql_fetch_row() function) of reassign the variables to reflect their enumerated values. I chose the enumerated value designations and now the form fields are populating as they should...
example:
while ($line = mssql_fetch_row($result)) {
$bc = $line[0];
$sn = $line[1];
$loc = $line[2];
$man = $line[3];
$mod = $line[4];
$item = $line[5];
$it = $line[6];
$pr = $line[7];
$war = $line[8];
$we = $line[9];
$cn = $line[10];
$pn = $line[11];
$dr = $line[12];
$ex = $line[13];
$ed = $line[14];
$xha = $line[15];
$xhb = $line[16];
$xhc = $line[17];
}
e
Hey Chris, if you still feel like looking at this...
Everything is gooing alright now, but I can't get the update query to run correctly. The process is as follows:
1. The page loads with a pre-specified variable edit.php?id=<barcode>
2. The ELSE portion of the conditional executes and populates the form fields with the current information.
3. The user changes informatin about the object then hits the "Submit" button.
4. The edit.php page processes itself, but this time the IF portion of the conditional executes because $submit holds a value.
5. The fields submitted are assigned variables identical to the variables in the ELSE statement so the same form processes each part of the conditional identically.
6. The UPDATE query is run updating the MSSQL fields.
7. The form populates itself with the new user-specified information.
OK, the form populates itself with the proper updated informatin after the "Submit" button is hit so I know the variables it the IF segment are getting assigned correctly. The problem is that the UPDATE query is not updating the actual db fields. I am not getting a "failed query" error either so I'm a bit lost. Do you think I should run the UPDATE query using the $_POST variables then assign form-friendly variables afterwards? Little help...well, lots of help!
E
I stuck the mssql_num_rows() function that you gave me earler after the query execution in the IF statement.
$num = mssql_num_rows($result);
echo $num;
I returned the following error:
Warning: mssql_num_rows(): supplied argument is not a valid MS SQL-result resource in ....
Do you think I have the mssql_query() syntax correct? Maybe there is a problem with the query being a query that UPDATEs rather than GETs...???
try:
But for all of the columns. Notice I've added quotes around the variables. I haven't been following what's been happening, so I may be wrong.PHP Code:
UPDATE invtemp SET location = '$loc', barcode='$bc' WHERE barcode = '$bc';
Dang! I thought that was going to be it...no go though. Here is the entire if () statement...
if (isset ($submit)){
$bc = $_POST['barcode'];
$sn = $_POST['serial_number'];
$loc = $_POST['location'];
$man = $_POST['manufacturer'];
$mod = $_POST['model'];
$item = $_POST['item'];
$it = $_POST['item_type'];
$pr = $_POST['price'];
$war = $_POST['warranty'];
$we = $_POST['warranty_expiration'];
$cn = $_POST['contract_number'];
$pn = $_POST['part_number'];
$dr = $_POST['date_received'];
$ex = $_POST['excess'];
$ed = $_POST['excess_date'];
$xha = $_POST['xtra_hardware_a'];
$xhb = $_POST['xtra_hardware_b'];
$xhc = $_POST['xtra_hardware_c'];
$query = "UPDATE invtemp SET serial_number = '$sn', location = '$loc', manufacturer = '$man', model = '$mod', item = '$item', item_type = '$it', price = '$pr', warranty = '$war', warranty_expiration = '$we', contract_number = '$cn', part_number = '$pn', date_received = '$dr', ecxcess = '$ex', excess_date = '$ed', xtra_hardware_a = '$xha', xtra_hardware_b = '$xhb', xtra_hardware_c = '$xhc' WHERE barcode = '$bc';";
$result = @mssql_query ($query);
}
Oh by the way, Chromate...you answered my original question way back in the beginning of this thread...so thanx...
This is the third roadblock that I have run into. I kept the same thread alive as all the issues are related. It's nice ot have another few pairs of eyes. Mine keep seeing things the same way, you know?
E
remove the "@" from the front of the mssql_query function. I believe that is supressing an error message.
right after where you set the value of $query do an echo $query to see exactly what the sql statement looks like.
Do you have direct access to the database or through phpMyAdmin or the like? If so, run the query from the command line and see what error it comes up with.
Also get rid of the @ infront of mysql_query($query). This way it wont suppress the errors.
actually, cancel that bit about phpMyAdmin. Didn't realise you were using MS SQL Server.
I've seen the error...
You've put ecxcess='$ex' instead of excess='$ex' :)
You know you all are daggone geniouses...
I took out the @ and did return an error.
For some reason the data type of the "price" column wasn't working well. It had a data type of MONEY (MS Access), but was somehow getting updated with a char data type. I had to go into the db (which was upsized through MS's automatic data coversion tool from Access to MSSQL2K) and change the money type to char. Now everything works great! Thanks everyone for your input...I'm sure there will be more...lol...
E
Some database systems do not like quotes around variables of certain data types.
Generally numerical or date datatypes are like this.
If you were using MySQL it wouldn't be an issue, but MS products are a little different.
Actually, it can even cause problems in MySQL putting everything in quotes. It's not ideal having money as a char really.