Ok ... I have tried to work on this problem for a few hours now and can't find an answer. See if this has happened to anyone else.
Here is the setup. I have a script that includes a database connection script. I know it works because I use it through the whole site. That is NOT the problem. Here IS the problem. When I run the code below it will work on some cases. But not work all the time. I tested the outputed SQL statements through Enterprise Manager (MSSQL admin suite) (phpmyadmin for MySQL) and ran the statement. It worked fine. So I know it is something with the code. Just can't find out what is causing it not to work!
$build_ids[0] = "";
$check_buildids = str_replace(",","",$build_ids);
if(strlen(trim($check_buildids)) < 1)
{
// This is where it will build what SQL statement to send MSSQL.
$update_wallplatea = "UPDATE smithch.wallplates SET wallplate_tele_id='1' WHERE wallplate_id='$wpid'";
echo "$update_wallplatea<br>";
}else{
// This is where it will built what SQL statement to send MSSQL.
$update_wallplatea = "UPDATE smithch.wallplates SET wallplate_tele_id='$build_ids' WHERE wallplate_id='$wpid'";
echo "$update_wallplatea<br>";
}
$update_wallplate = "SELECT * FROM smithch.wallplates";
$update_wallplate_result = mssql_query($update_wallplate);
echo "Result = $update_wallplate_result<br>";
exit();
Browser Output:
UPDATE smithch.wallplates SET wallplate_tele_id='843,' WHERE wallplate_id='180'
Result = Resource id #6
The top part works but this one doesn't!
$build_ids[0] = "";
$check_buildids = str_replace(",","",$build_ids);
if(strlen(trim($check_buildids)) < 1)
{
// This is where it will build what SQL statement to send MSSQL.
$update_wallplate = "UPDATE smithch.wallplates SET wallplate_tele_id='1' WHERE wallplate_id='$wpid'";
echo "$update_wallplate<br>";
}else{
// This is where it will built what SQL statement to send MSSQL.
$update_wallplate = "UPDATE smithch.wallplates SET wallplate_tele_id='$build_ids' WHERE wallplate_id='$wpid'";
echo "$update_wallplate<br>";
}
$update_wallplate_result = mssql_query($update_wallplate);
echo "Result = $update_wallplate_result<br>";
exit();
Browser Output:
UPDATE smithch.wallplates SET wallplate_tele_id='843,' WHERE wallplate_id='180'
Result =
I even did this and it didn't work:
$build_ids[0] = "";
$check_buildids = str_replace(",","",$build_ids);
if(strlen(trim($check_buildids)) < 1)
{
$tele_id_value = "1";
}else{
$tele_id_value = "$build_ids";
}
$update_wallplate = "UPDATE smithch.wallplates SET wallplate_tele_id='$tele_id_value' WHERE wallplate_id='$wpid'";
$update_wallplate_result = mssql_query($update_wallplate);
echo "Result = $update_wallplate_result<br>";
exit();
echo "<meta http-equiv='refresh' content='0; URL=edit.wallplate.php?wpid=$wpid&option=2'>";
exit();
Browser Output:
Result =
Can anyone figure out why my update statement wouldn't do what it should! I have no idea. This is the first time this has ever happened to me in 7 years of work. Really quite frustrating. Thanks!
Chad R. Smith