I'll try to explain this as easily as possible.
I'm working on making a little link shortener site just for fun/practice as a beginner with php.
I originally used the source code 'lilurl' as a base to start out, but now I'm adding stuff to it for actual practice.
I need some help though.
I have two files, my index and my external php file. The external file is called on at the beginning of the index with require_once.
The user submits a url into the PHP_SELF form and a url is returned, and it works all great. Now I'm trying to add the option to make a custom url suffix.
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<fieldset>
<label for="longurl">Enter a URL:</label>
<input type="text" name="longurl" id="longurl" />
<input type="text" name="suffix" id="suffix" />
<input type="submit" name="submit" id="submit" value="Shrink!" />
</fieldset>
</form>
[/code]
The form looks like this. I added the 'suffix' textbox.
So after the user submits the code, it goes back up to the top (phpself).
A variable is set for the url the user has inputted as "$longurl", like this.
$longurl = trim(mysql_escape_string($_POST['longurl']));
So I added this.
$suffix = ($_POST['suffix']);
And to check if it worked, I went down the the bottom of the index and had it echo the suffix variable. When I entered in code into the suffix text box, it would be echoed at the bottom of the page, so the variable did receive the value.
So here's where the external file comes in.
It is called on by require_once at the very beginning of the index. It is full of functions. One of the functions generates a random string of numbers (that I coded) to be used as the url suffix (uses the $id variable). So my plan was to erase the $id = $rand1 . blah blah stuff and put $id = $suffix. $suffix being the variable from the index that the user inputted. Make sense? Well whenever I try it, it always acts the like the variable is empty, even when I echo it on the index it returns the value of the textbox. Does anyone know what I'm doing wrong? Could it be because since I call on $suffix in the external file, and it's only been declared in the index that it's treating it like a new/empty variable?