Jump to content

inserting the current URL into the MYSQL db upon form completion


phpchick

Recommended Posts

	$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
Share on other sites

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
Share on other sites

$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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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