fullyloaded Posted November 24, 2011 Share Posted November 24, 2011 hi i been working on this code witch will add what ever text i want to my database all is working great but what i am having problems with is inserting a url in the same field as vidID it will look like this in the database hxxp://xxx.mysitehere.com/index.php?vid=vidID hope you guys know what im talking about im having a hard time explaining it sorry. <?php $host="xxxxx"; $username="xxxxxxx"; $password="xxxxxxx"; $db_name="xxxxxxx"; $tbl_name="xxxxxxx"; $message = strtoupper(trim($_REQUEST['message'])); $sender = strtoupper(trim($_REQUEST['sender'])); $email = strtolower(trim($_REQUEST['email'])); $vidID =$_REQUEST['vidID']; mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="INSERT INTO $tbl_name(message,sender,email,vidID)VALUES('$message','$sender', '$email', '$vidID')"; $result=mysql_query($sql); ?> Quote Link to comment https://forums.phpfreaks.com/topic/251710-adding-a-url/ Share on other sites More sharing options...
teynon Posted November 24, 2011 Share Posted November 24, 2011 My guess is the column vidID in mysql is of the INT type. Which it should be. If you want to use a URL, then you should make a varchar URL column in the mysql table. Quote Link to comment https://forums.phpfreaks.com/topic/251710-adding-a-url/#findComment-1290888 Share on other sites More sharing options...
fullyloaded Posted November 24, 2011 Author Share Posted November 24, 2011 i have everything in the database setup correct i want to insert text in the same column as vidID text being a url so if i view vidID in the database i would see URLHEREvidID Thanks for the reply. Quote Link to comment https://forums.phpfreaks.com/topic/251710-adding-a-url/#findComment-1290896 Share on other sites More sharing options...
teynon Posted November 24, 2011 Share Posted November 24, 2011 Show us your database table structure. You can copy and paste it from PHPMyAdmin or run this query: SHOW COLUMNS FROM TABLENAMEHERE Quote Link to comment https://forums.phpfreaks.com/topic/251710-adding-a-url/#findComment-1290898 Share on other sites More sharing options...
QuickOldCar Posted November 24, 2011 Share Posted November 24, 2011 Are you asking why the link starts with hxxp://? To answer that, is people out there that do hxxp:// versus any proper protocol like http://,https,etc... to show that it's link but hide that it is a link for bots or chats. I for one do not this at all. If it's you that are pasting the links as hxxp in this forum..not sure why are doing that. I'm not sure where you are getting this data from, but you can run these through a case insensitive string replace function to change hxxp to http. //list of urls $url_array = array("hxxps://xxx.mysitehere.com/index.php?vid=vidID", "hxxps://mysitehere.com/index.php?vid=vidID","hxxp://xxx.mysitehere.com/index.php?vid=vidID", "hxxp://mysitehere.com/index.php?vid=vidID"); //replace function function replaceHxxp($url){ $url = str_ireplace(array("hxxps://xxx.","hxxps://","hxxp://xxx.","hxxp://"), array("https://www.","https://","http://www.","http://"), trim($url)); return $url; } //looping urls through the function foreach($url_array as $urls){ echo replaceHxxp($urls) . "<br />"; } results of the urls would now be: https://www.mysitehere.com/index.php?vid=vidID https://mysitehere.com/index.php?vid=vidID http://www.mysitehere.com/index.php?vid=vidID http://mysitehere.com/index.php?vid=vidID You should also look into sanitizing/escaping any data inserted into mysql Some reading material for you. http://php.net/manual/en/function.mysql-real-escape-string.php http://php.net/manual/en/function.urlencode.php http://www.php.net/manual/en/function.urldecode.php http://www.php.net/manual/en/function.rawurlencode.php http://www.php.net/manual/en/function.rawurldecode.php Quote Link to comment https://forums.phpfreaks.com/topic/251710-adding-a-url/#findComment-1290900 Share on other sites More sharing options...
QuickOldCar Posted November 24, 2011 Share Posted November 24, 2011 Well after writing that function, which is useful for what I did it for. I do believe you would like to append your sites url to an assigned vidid. It's better to just on displaying to append your sites domain/location just on display. Less data in database, may switch domains or the file locations. Really is no need to do that unless you yourself will be doing it your self from different domains. but can do this if what i said is correct. $vidID = "hxxp://xxx.mysitehere.com/index.php?vid=" . $_REQUEST['vidID']; Quote Link to comment https://forums.phpfreaks.com/topic/251710-adding-a-url/#findComment-1290902 Share on other sites More sharing options...
fullyloaded Posted November 24, 2011 Author Share Posted November 24, 2011 thanks everyone for your help QuickOldCar thats it that code worked out great again thanks. Quote Link to comment https://forums.phpfreaks.com/topic/251710-adding-a-url/#findComment-1290903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.