Copy link to clipboard
Copied
Thank you for your understanding, I hope I am in the right place.
I am trying to generate about 30 unique pages to be visited by recipients of a piece of mail.
I am planning to use .htaccess to redirect the visitor to the unique, shortened url.
I cannot figure out how to get this to all work together. Please help
Copy link to clipboard
Copied
I think if you're a bit more specific about what you're trying to do you will get more help... your description is very vague.
Copy link to clipboard
Copied
I am trying to implement a personalized url (purl) to print on a mail piece. I have created a mysql database and a form that places some unique information about the visitor using php.
I have successfully linked the page to the database and I believe the scripts for mailing responses will work, based on earlier successes. I did the binding to link the correct field from the database to the url. But now what?
My problem is that I have never generated a unique page and I cannot figure out how to do that. I am thinking that I need some piece of php script to create the dynamic page.
Copy link to clipboard
Copied
Okay, tell me if I understand you correctly.
You've got a mail piece going out, and each person will have a different URL. So, Person A would go to: www.mydomain.com/persona; and Person B would go to www.mydomain.com/personb - is that about right? And you want the page to display info from the DB without having to make 30 different static pages to do it?
If that's what you're doing, the way *I* would do it is like this:
I would create a subdomain for each person (to make it easy for the person) and forward it to a page that uses a $_GET parameter to call the record from the database.
For example:
I would set-up subdomains like:
JSmith.mydomain.com
and
MFarese.mydomain.com
Then, I would forward those domains to:
www.mydomain.com/mypage.php?id=1
and
www.mydomain.com/mypage.php?id=2
Then, on the page you create, you add the WHERE statement to your SQL query... you can do this in "simple" mode by adding the filter WHERE id = URL PARAMETER id.
That's it. When the page is called with the extra "?id=1" at the end of the URL it will call the record from the DB with the ID value of 1.
Make sense?
I'm sorry if that's not what you're asking - that's what I got from your question.
Copy link to clipboard
Copied
Hi Michael:
Thank you so much for your rapid responses. I tried your suggestions. No luck. I have tried many other interations too.
I am able to get the page to properly load the information from the first record. These scripts are at the very top of the page before the head and html:
<?php require_once('../Connections/seeds.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_seeds, $seeds);
$query_Recordset1 = "SELECT * FROM seeds";
$Recordset1 = mysql_query($query_Recordset1, $seeds) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
This script is at the very end of the page after the closing </html>:
<?php
mysql_free_result($Recordset1);
?>
Copy link to clipboard
Copied
[...] Stand-by.
Message was edited by: Michael Farese
Copy link to clipboard
Copied
Okay, I'll try to break it down. (Is this live on the net? Can you provide a link? That would help a lot.)
You will need to choose a field in your database to act as your primary key that you will use to select the record. In my example, I used "id" - that would require you to add a column to your db table called "id" and number each record 1, 2, 3, 4, etc... You could use some other column with unique data if you wanted... but generally speaking, you'll want all your tables to have some sort of unique identifier that auto-increments as you add new records.
Then, your recordset (on your page it looks like you're using the default name "Recordset1") should be worded something like this (you can type this in manually in the advanced pane):
SELECT *
FROM table_name
WHERE id=colname
Then, click the + button next to where it says "variables" and fill out the info like this:
Name: colname
Type: Interger
Default Value: -1
Runtime Value: $_GET['id'] (it's hard to see, but there are single quotes around 'id' inside the [brackets] .)
This is assuming that you use the id column in your database and in your URL. If you use a different column, replace 'id' with that.
Now, if you bind your dynamic text on the page to this recordset, you should be able to load each user's individual page by going to the URL with each person's id number in the URL, like:
http://www.mysite.com/my_page.php?id=1
http://www.mysite.com/my_page.php?id=2
http://www.mysite.com/my_page.php?id=3
etc...
See if you can that that much to work. Don't forget, to follow this example, you'll need to have a field in your database table called id... and the value of id should be 1, 2, 3, 4, etc. for each record (until you get to 30, or however many you have.)
Copy link to clipboard
Copied
Hi Michael:
I made some progress. I did create a field called "index" that used incremental values. I changed that field to"id" to work with your suggestions.
Thanks to you, there is progress.
When I type the address with this at the end "seeds.php?id=4". I get the information from the first record only. It does not matter which id number I use, I still get only the first record information.
This is a link to a default page without the variable personalized information. http://www.deansmailing.com/seeds/
This is the new beginning script:
<?php require_once('../Connections/seeds.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$id_Recordset1 = "-1";
if (isset($_GET['id'])) {
$id_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_seeds, $seeds);
$query_Recordset1 = sprintf("SELECT * FROM seeds WHERE %s=%s", GetSQLValueString($id_Recordset1, "int"),GetSQLValueString($id_Recordset1, ""));
$Recordset1 = mysql_query($query_Recordset1, $seeds) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
Copy link to clipboard
Copied
Try a couple things...
First, it looks like you didn't use "colname" as your variable name when setting up the query. Go back and fix that. The NAME of the variable should be literally
colname
Then, on the line that says:
$query_Recordset1 = sprintf("SELECT * FROM seeds WHERE %s=%s", GetSQLValueString($id_Recordset1,
change the FIRST %s to id. So it would read:
$query_Recordset1 = sprintf("SELECT * FROM seeds WHERE id=%s", GetSQLValueString($id_Recordset1,
On this line:
$query_Recordset1 = sprintf("SELECT * FROM seeds WHERE id=%s", GetSQLValueString($id_Recordset1, "int"),GetSQLValueString($id_Recordset1, ""));
delete the part past the close parenthesis after "int" all the way up to the last parenthisis... so it would read:
$query_Recordset1 = sprintf("SELECT * FROM seeds WHERE id=%s", GetSQLValueString($id_Recordset1, "int"));
Save this as a different page name, in case any of it breaks something you can just revert back to the old page and we can work from there. Maybe "index2.php"... then test it on that page "http://www.deansmailing.com/seeds/index2.php?id=3" Try these changes and see what happens. Let me know...
Copy link to clipboard
Copied
Thank you for all your help!!! It works.
What did it was your instructions about the "colname". But I had to keep going back to fix the query. Every time I did anything the bindings got messed up.
Something is still wrong because it is taking forever to connect with the database but it still works!!
Copy link to clipboard
Copied
Cool. I ask enough questions around here... it's cool to be able to help someone every now and then. 🙂
Go ahead and mark this thread as "ANSWERED."
Copy link to clipboard
Copied
Sorry.
I think I spoke too soon. I got the page to load the way I wanted it to, but I could not get the htaccess rewrite to work. I think I need to go back to the mySQL statement. I don't think I can use the "id" field. I think I need to use a field called "pageaddress" it is a longer text field that I plan to print on the mail piece.
I tried to vary the statement you suggested, but it yielded an error and messed up the whole recordset.
Copy link to clipboard
Copied
I'm not really sure why you want to use .htaccess for this. In fact, I'm not really sure how you are going to use .htaccess for this. Just my opinion, but I think the easiest way to do this is to create a cool subdomain for each person and forward it to the URL that you want (like I mentioned earlier in the thread.) WAYYYY easier.
Also, if you want a really easy way to secure the pages without requiring a log-in, you can add one more field to the table called, say, "secure." Then in your WHERE statement, require the id field AND secure field match. A person would have to change the id in the url AND guess the corresponding "secure" integer to access someone else's page. Just a thought.
Copy link to clipboard
Copied
Hi Michael:
I finally got it. This is the section of relevant code that worked.
$colname_rsSeeds = "a";
if (isset($_GET['pageaddress'])) {
$colname_rsSeeds = (get_magic_quotes_gpc()) ? $_GET['pageaddress'] : addslashes($_GET['pageaddress']);
Thank you so much for your rapid responses and giving me hope to keep going.