phpchick Posted May 13, 2011 Share Posted May 13, 2011 $query = "INSERT INTO contactv3(name,email,msg) VALUES ('$name','$email','$msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } I have this current php snippet inserting the $name and $msg into a mysql db. $name and $msg come from here (a form that the user fills out). <input type="text" size=28 name="name"> <input type="password" size=28 name="msg" > but is it possible to also enter the URL or perhaps a parameter that is appended to the end of the URL into the mysql db into separate column? Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/ Share on other sites More sharing options...
dougjohnson Posted May 13, 2011 Share Posted May 13, 2011 What URL are you talking about? Are you asking about extracting the URL from the browser address area and inserting it into your table? If so, there is a way to do that. Please be more specific. Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215134 Share on other sites More sharing options...
phpchick Posted May 13, 2011 Author Share Posted May 13, 2011 What URL are you talking about? Are you asking about extracting the URL from the browser address area and inserting it into your table? If so, there is a way to do that. Please be more specific. Yes, that is exactly what I mean. sorry about the vagueness Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215135 Share on other sites More sharing options...
dougjohnson Posted May 13, 2011 Share Posted May 13, 2011 Try $_SERVER['HTTP_REFERER'] or $_SERVER['REQUEST_URI'] Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215136 Share on other sites More sharing options...
dougjohnson Posted May 13, 2011 Share Posted May 13, 2011 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215137 Share on other sites More sharing options...
dougjohnson Posted May 13, 2011 Share Posted May 13, 2011 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215139 Share on other sites More sharing options...
phpchick Posted May 13, 2011 Author Share Posted May 13, 2011 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; not sure where that goes, so do i do something like this? if (check_email_address($name) == false) $aError[] = 'Please enter a valid email.'; $query = "INSERT INTO contactv3(name,email,msg) VALUES ('$name','$email','$msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } $pageURL .= $_SERVER["thenameofmyserverhere"].":".$_SERVER["port?"].$_SERVER["REQUEST_URI"] but where is the column for where I want the URL to be inserted? it has to know that at least. For port do you just put in 3306 ? Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215142 Share on other sites More sharing options...
dougjohnson Posted May 13, 2011 Share Posted May 13, 2011 I was just showing you how to get the URL into a variable. Don't CHANGE these! They are environment variables. Use them just as they are: $pageurl = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; Then - $pageurl will contain the users current URL in his/her address bar. Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215146 Share on other sites More sharing options...
phpchick Posted May 13, 2011 Author Share Posted May 13, 2011 I was just showing you how to get the URL into a variable. Don't CHANGE these! They are environment variables. Use them just as they are: $pageurl = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; Then - $pageurl will contain the users current URL in his/her address bar. Ahhh, I got it working. The only problem is that the signin form is in an iframe, is there anyway to have that pageurl affect the URL in the top frame as opposed to the iframe? Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215170 Share on other sites More sharing options...
dougjohnson Posted May 13, 2011 Share Posted May 13, 2011 PHP doesn't know anything about iframes. This ones tricky. I'll do some looking around. Maybe someone else can chime in. Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215175 Share on other sites More sharing options...
phpchick Posted May 13, 2011 Author Share Posted May 13, 2011 Not sure if its related but I did something similar where I had to redirect the iframe to a page on that was on the top frame, I had to use this javascript code, but I'm not sure how to port it over to what we're doing here. if(!isset($_SESSION['SESS_USERID'])||(trim($_SESSION['SESS_USERID']=='admin'))) { echo '<script language="javascript">'; echo 'top.location.href = "http://www.ceofinity.com/404.html";'; echo '</script>'; exit(); } Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215178 Share on other sites More sharing options...
dougjohnson Posted May 13, 2011 Share Posted May 13, 2011 I found this on the web: ///////////////////////////// PHP has no idea about an iframe, it's just served as another page and interpreted by the browser... You could do something like... <iframe src="frame.php?from=<?php echo currentPageURL() ?>"> Then inside the iframe, you can access $_GET['from']. Just make sure you verify, as that would be insecure. Here is the code I typically use to return the current page URL: function currentPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } //////////// I'm not sure if this would work for you??? Link to comment https://forums.phpfreaks.com/topic/236345-inserting-the-current-url-into-the-mysql-db-upon-form-completion/#findComment-1215182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.