Jump to content

[SOLVED] phantom colon...


ag3nt42

Recommended Posts

*sighhh*

 

ok.. well this is my third question today lol...sry.

 

I have some how come across a phantom colon.

 

Now I have checked, and triple checked my code for a place where this colon would be snaking into my outputs but never do I see such an outlet.

 

the code:

<?php
if(!(isset($_POST['dbusername'])))
{
$dbUsername="";
}
else
{
$dbUsername = $_POST['dbusername']; //Username for database
}

if(!(isset($_POST['dbpassword'])))
{
$dbPassword= "";
}
$dbPassword = $_POST['dbpassword'];	//Password for database


if(!(isset($_POST['dblocation'])))
{
$dblocation= "";
}
$dblocation = $_POST['dblocation'];	//Database Server Name

if(!(isset($_POST['dbport'])))
{
$dbport = "";
}
else
{
$dbport = ":" . $_POST['dbport']; //Port for database server /* WHERE THE COLON SHOULD BE
}                                                             But, only if dbport is set.


if(!(isset($_POST['dbport'])))
{
$dblocport=$dblocation;
}
else
{
$dblocport=$dblocation . $dbport;
}

$con = mssql_connect($dblocport,$dbUsername,$dbPassword);
?>

 

now logically if dbport is not set. there should never be a colon created yes??no??

 

but there is...

 

please help me defeat the phantom colon!!

 

thankx everyone,

ag3nt42

 

(edited by kenrbnsn to add the


tags)

Link to comment
https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/
Share on other sites

This code can be shortened considerably by using the ternary operators "?:":

<?php
  $dbUsername = (isset($_POST['dbusername']) && strlen(trim(stripslashes($_POST['dbusername']))) > 0)?$_POST['dbusername']:'';
  $dbPassword = (isset($_POST['dbpassword']) && strlen(trim(stripslashes($_POST['dbpassword']))) > 0)?$_POST['dbpassword']:'';
  $dblocation = (isset($_POST['dblocation']) && strlen(trim(stripslashes($_POST['dblocation']))) > 0)?$_POST['dbpassword']:'';
  $dbport = (isset($_POST['dbport']) && strlen(trim(stripslashes($_POST['dbport']))) > 0)?':' . $_POST['dbport']:'';
  $dblocport = (isset($_POST['dbport']) && strlen(trim(stripslashes($_POST['dbport']))) > 0)?$dblocation . $dbport:$dblocation;

$con = mssql_connect($dblocport,$dbUsername,$dbPassword);
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-555972
Share on other sites

whats weird to me is that this is exactly what i was saying before only in a different manner.

the output should have been the same. Sounds like a php glitch to me

 

No, it's not the same. If you had done a

<?php
echo '<pre>' . print_r($_POST,true) . '</pre>';
?>

to see what was being returned to your code from the form, you would have seen that the fields are all defined, even if there is nothing in them. That's why your code didn't work.

 

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-555975
Share on other sites

This code can be shortened considerably by using the ternary operators "?:":

<?php
 $dbUsername = (isset($_POST['dbusername']) && strlen(trim(stripslashes($_POST['dbusername']))) > 0)?$_POST['dbusername']:'';
 $dbPassword = (isset($_POST['dbpassword']) && strlen(trim(stripslashes($_POST['dbpassword']))) > 0)?$_POST['dbpassword']:'';
 $dblocation = (isset($_POST['dblocation']) && strlen(trim(stripslashes($_POST['dblocation']))) > 0)?$_POST['dbpassword']:'';
 $dbport = (isset($_POST['dbport']) && strlen(trim(stripslashes($_POST['dbport']))) > 0)?':' . $_POST['dbport']:'';
 $dblocport = (isset($_POST['dbport']) && strlen(trim(stripslashes($_POST['dbport']))) > 0)?$dblocation . $dbport:$dblocation;

$con = mssql_connect($dblocport,$dbUsername,$dbPassword);
?>

 

Ken

 

this looks like the same amount of code to me just on one line

 

if(!(isset($_POST['dbpassword']))){$dbPassword= "";}else{$dbPassword = $_POST['dbpassword'];}

$dbPassword = (isset($_POST['dbpassword']) && strlen(trim(stripslashes($_POST['dbpassword']))) > 0)?$_POST['dbpassword']:'';

Link to comment
https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-555981
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.