Current location: Hot Scripts Forums » Programming Languages » PHP » User Text Based Redirect Script - Need Helop - My first original script ever!


User Text Based Redirect Script - Need Helop - My first original script ever!

Reply
  #1 (permalink)  
Old 09-18-05, 05:37 PM
skipcollege skipcollege is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up User Text Based Redirect Script - Need Helop - My first original script ever!

Hello, I am attempting to write my very first script. It is a simple one but I'm having some issues.

I'm attempting to make a script that upon a user submitting text in a html form, it checks to see if that text exists as in a mysql database and if it does then redirect the user to www.domain.com/'user_submitted_text'. If not then give an error prompt.

I submitted a script request but had no luck with finding an existing script that did this. See that thread here: http://www.programmingtalk.com/showthread.php?t=22348

My mysql database has one table named users that has two columns of user_id and username.

When running the code in a browser I get this...
"Parse error: parse error, unexpected T_ECHO in /home/.../affiliate.php on line 12"

Here is my code...

PHP Code:



<?php

$query 
"SELECT username FROM users WHERE username = ‘$_POST[‘username’]’";
if (
$_POST['submit'] == 1) {
        
$dbc=mysql_connect ("localhost""user""password") or die ('I cannot connect to the database because: ' mysql_error());
        
mysql_select_db ("database");
    
$result = @mysql_query ($query); // Run the query.
    
if (mysql_num_rows($result) == 0) {
    echo 
"$_POST[‘username’] is not a valid Affiliate ID";
    } else {
    
$url "http://www.domain.com/ . $_POST[‘username’];"
    
echo "<html><head><meta http-equiv=\'refresh\' content=\'4;URL=$url\'></head><body>you are being redirected</body></html>";
    }
} else {
echo 
"
<p align='center'>
    <form action='affiliate.php' method='post' enctype='multipart/form-data'>
        <p><input type='text' name='username'></p>
        <p><input type='submit' name='submit' value='Submit'></p>
    </form>
</p>"
; }

?>
Thank you.
Reply With Quote
  #2 (permalink)  
Old 09-18-05, 07:22 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
I am also new to php, so somebody might have better code. Try it.
PHP Code:

<?php

if ($_POST['submit'] == true) {
    
$host "localhost";
    
$user "";
    
$pass "";
    
$dbConn mysql_connect($host$user$pass);
    
$database "database";
    
mysql_select_db($database$dbConn); 
    
$query_tbl sprintf("SELECT * FROM users WHERE username = '".$_POST['username']."'");
    
$query mysql_query($query_tbl$dbConn) or die(mysql_error());
    if (
mysql_num_rows($query) == false) {
    echo (
''.$_POST['username'].' is not a valid Affiliate ID, please use you browsers back button and try again');
    } if (
mysql_num_rows($query) == true){
    echo 
"<html><head><meta http-equiv=\"refresh\" content=\"4;URL=http://www.domain.com/".$_POST['username']."\"></head><body>you are being redirected</body></html>";
    }
}
 else {
echo 
'
<p align="center">
    <form action="affiliate.php" method="post">
        <p><input type="text" name="username"></p>
        <p><input type="submit" name="submit" value="Submit"></p>
    </form>
</p>'
; }

?>
Reply With Quote
  #3 (permalink)  
Old 09-18-05, 07:26 PM
skipcollege skipcollege is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
I solved that line 12 error...My ; was behind the quote.

I also changed line 12 from

PHP Code:

echo "<html><head><meta http-equiv=\'refresh\' content=\'4;URL=$url\'></head><body>you are being redirected</body></html>"
to
PHP Code:

echo "<html><head><meta http-equiv=\'refresh\' content=\'4;URL=" $url "\'></head><body>you are being redirected</body></html>"
because I thought the $url variable wouldn't work the other way.

Now my form does show but when I submit a text string it just goes to the same page showing the blank form again

My database is blank, would that cause a problem? I'll try adding info in it to see.

Any help would be appreciated!
Reply With Quote
  #4 (permalink)  
Old 09-18-05, 07:27 PM
skipcollege skipcollege is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Trying your code dead-poetic....
Reply With Quote
  #5 (permalink)  
Old 09-18-05, 11:30 PM
skipcollege skipcollege is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
dead-poetic your revision worked! thank you!

Not totally complete though...Now I need to make the have a condition for the text people can submit to the script. All text must be lowercase - no UPPERCASE letters. Because the script sends the user to www.domain.com/TEXT when all caps are entered on the form. They should go to www.domain.com/text. My linux server treats them as seperate directories.

I have no idea how to do this so any help would be appreciated. I will do some searches as to how to do this as well. Thank you.
Reply With Quote
  #6 (permalink)  
Old 09-19-05, 01:24 AM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
replace the lines
PHP Code:

    } if (mysql_num_rows($query) == true){

    echo 
"<html><head><meta http-equiv=\"refresh\" content=\"4;URL=http://www.domain.com/".$_POST['username']."\"></head><body>you are being redirected</body></html>";
    } 
with
PHP Code:

    } if (mysql_num_rows($query) == true){

    
$user strtolower($_POST['username']);
    echo 
"<html><head><meta http-equiv=\"refresh\" content=\"4;URL=http://www.domain.com/".$user."\"></head><body>you are being redirected</body></html>";
    } 
Reply With Quote
  #7 (permalink)  
Old 09-19-05, 05:07 AM
skipcollege skipcollege is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Awesome! Works! thank you so much dead-poetic!

As far as I know this script is complete. I'll probably attempt a small script where I can input the data into the database ("user_id" and "username") later this week.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Redirect Script based on User Text Field skipcollege Script Requests 7 09-18-05 11:03 AM
2 flash websites for sale metamorph General Advertisements 5 01-09-05 10:03 PM
Login and Redirect user script alistairgd Script Requests 4 01-03-05 03:30 PM
need a User ID based voting script PoggiPJ Script Requests 2 10-12-04 11:33 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


All times are GMT -5. The time now is 06:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.