ag3nt42 Posted June 2, 2008 Share Posted June 2, 2008 *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 More sharing options...
metrostars Posted June 2, 2008 Share Posted June 2, 2008 Maybe you should try if($_POST['dbport'] == '') instead. As it may still be set as the form has been submitted, but has beeen set to blank. Link to comment https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-555946 Share on other sites More sharing options...
ag3nt42 Posted June 2, 2008 Author Share Posted June 2, 2008 i'll give that a shot. Link to comment https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-555956 Share on other sites More sharing options...
ag3nt42 Posted June 2, 2008 Author Share Posted June 2, 2008 i got it working with this code if($_POST['dbport']=="") { $dbport = ""; } else { $dbport = ":" . $_POST['dbport']; //Port for database server } nice look metrostars... thanx for your reply. Link to comment https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-555966 Share on other sites More sharing options...
ag3nt42 Posted June 2, 2008 Author Share Posted June 2, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-555967 Share on other sites More sharing options...
kenrbnsn Posted June 2, 2008 Share Posted June 2, 2008 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 More sharing options...
kenrbnsn Posted June 2, 2008 Share Posted June 2, 2008 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 More sharing options...
ag3nt42 Posted June 2, 2008 Author Share Posted June 2, 2008 i did do a return to see what it was outputing and it was outputting nothing.. then when i outputted the first variable by itself without the colon part attached. the colon was still showing up. Link to comment https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-555979 Share on other sites More sharing options...
ag3nt42 Posted June 2, 2008 Author Share Posted June 2, 2008 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 More sharing options...
discomatt Posted June 2, 2008 Share Posted June 2, 2008 Phantom Colon... priceless Link to comment https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-556012 Share on other sites More sharing options...
ag3nt42 Posted June 3, 2008 Author Share Posted June 3, 2008 Phantom Colon... priceless lol no one ever said we couldn't have fun with our topic names lol Link to comment https://forums.phpfreaks.com/topic/108442-solved-phantom-colon/#findComment-556557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.