NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP Parse error... Can't find where...

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-28-2008, 07:33 AM THREAD STARTER               #1 (permalink)
New Member
Join Date: Jan 2008
Posts: 21
RoTE is an unknown quantity at this point
 



PHP Parse error... Can't find where...


Hey guys...
I'm working on a small PHP file
PHP Code:
<?php 
include ("config.php");

function 
TextBetween($s1,$s2,$s)
{
$s1 strtolower($s1);
$s2 strtolower($s2);
$L1 strlen($s1);
$scheck strtolower($s);
    if(
$L1>0)
    {
$pos1 strpos($scheck,$s1);} 
        else 
        {
$pos1=0;}
            if(
$pos1 !== false)
            {
            if(
$s2 == '') return substr($s,$pos1+$L1);
            
$pos2 strpos(substr($scheck,$pos1+$L1),$s2);
            if(
$pos2!==false) return substr($s,$pos1+$L1,$pos2);
            }
return 
$result;
}


if (
$_POST[submit])
{
$find = array("\n""\r""[/url]");
$replace = array("""""[/url]\n");
$finalreplace = array("""""[/url]");
$urls $_POST['urls'];
$large = array("[URL=""[IMG]""[/IMG]""[/URL]"); 
$small = array("[url=""[img]""[/img]""[/url]"); 
$urls str_replace($large$small$urls); 
$urls str_replace($find$replace$urls);

for (
$i 0$i <= sizeof($urls)-1$i += 1
{
$newurl TextBetween("[url=","][img]",$urls[$i]);
$thumburl TextBetween("[img]","[/img]",$urls[$i]);

if (
$newurl != '')
    {
    
$addtodb = @mysql_query("INSERT into redirects (link,thumb) VALUES ('".$newurl."','".$thumburl."');
    
$usedid = @mysql_insert_id();
    
$yoururl = "http://www.gonzolicious.com/redir.php?rid=".$usedid;
    
$newurls $newurls."".trim($urls[$i]);
    
$newurls str_replace($newurl$yoururl$newurls);
        if (
$break == '3')
        {
        
$newurls $newurls."\n";
        
$break 0;
        }
            else
            {
            
$break $break 1;
            }

    }

}
echo 
"<form action='index.php' method='post' name='mainform'>
<textarea rows='20' cols='90' name='urls' readonly>"
.$newurls."</textarea>
</form>"
;
}
else
{
echo 
"<form action='index.php' method='post' name='mainform'>
????: NamePros.com http://www.namepros.com/programming/450273-php-parse-error-cant-find-where.html
<textarea rows='20' cols='90' name='urls'></textarea><br />
<input type='submit' name='submit' id='submit' value='Submit'></form>"
;
}
?>
That code is giving me a Parse error "Unexpected T_String...." on index.php line 44.

Line 44 in the code is
PHP Code:
$yoururl "http://www.gonzolicious.com/redir.php?rid=".$usedid
I know the syntax for that line is correct... I tested with
????: NamePros.com http://www.namepros.com/showthread.php?t=450273
PHP Code:
<html>
<head></head>
<body>
<?php
$usedid 
111;
$yoururl "http://www.gonzolicious.com/redir.php?rid=".$usedid;
echo 
$yoururl;
?>
</body>
</html>
And that prints http://www.gonzolicious.com/redir.php?rid=111" to the browser.

I've been going crazy trying to find where the error is coming from.

Any assistance would be greatly appreciated.
Thanks
Sebastian (RoTE)
RoTE is offline  
Old 03-28-2008, 07:48 AM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Your problem:

PHP Code:
    $addtodb = @mysql_query("INSERT into redirects (link,thumb) VALUES ('".$newurl."','".$thumburl."'); 
Change it to:

PHP Code:
    $addtodb = @mysql_query("INSERT into redirects (link,thumb) VALUES ('".$newurl."','".$thumburl."'"); 
????: NamePros.com http://www.namepros.com/showthread.php?t=450273
Eric is offline  
Old 03-28-2008, 08:00 AM THREAD STARTER               #3 (permalink)
New Member
Join Date: Jan 2008
Posts: 21
RoTE is an unknown quantity at this point
 



Man... thanks a lot... that did it...
I would have never found that missing "...
Thank you again.

EDIT
Any insight as to why the script would not write to the database?
Last edited by RoTE; 03-28-2008 at 09:11 AM.
RoTE is offline  
Old 03-28-2008, 03:37 PM   #4 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
most likely invalid sql.

Try echoing out mysql_error() after the mysql_query line. Also why are you putting the mysql_query command within a variable. You are never using the variable.

Also you should be sanitizing the data before entering into the database. Use a function such as mysql_real_escape_string() on the data before entering it.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 03-28-2008, 10:18 PM   #5 (permalink)
i love automation
 
xrvel's Avatar
Join Date: Nov 2007
Location: xrvel.com
Posts: 1,620
xrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant future
 




Since the ID is numeric, don't forget to filter it
Code:
$usedid = 78;
$usedid = intval(preg_replace('/([^0-9]+)/', '', $usedid));

// Now you can use the clean $usedid
__________________
xrvel is offline  
Old 03-29-2008, 09:38 AM THREAD STARTER               #6 (permalink)
New Member
Join Date: Jan 2008
Posts: 21
RoTE is an unknown quantity at this point
 



Originally Posted by peter@flexiwebhost
most likely invalid sql.

Try echoing out mysql_error() after the mysql_query line. Also why are you putting the mysql_query command within a variable. You are never using the variable.

Also you should be sanitizing the data before entering into the database. Use a function such as mysql_real_escape_string() on the data before entering it.

Originally Posted by xrvel
Since the ID is numeric, don't forget to filter it
Code:
$usedid = 78;
$usedid = intval(preg_replace('/([^0-9]+)/', '', $usedid));

// Now you can use the clean $usedid

Thanks guys... I figured it out with all your help and some other assistance.
The observation about sanitizing the data and cleaning the id... I'll have to implement those as well..

????: NamePros.com http://www.namepros.com/showthread.php?t=450273
Thanks again.
Juan
RoTE is offline  
Old 03-29-2008, 07:10 PM   #7 (permalink)
i love automation
 
xrvel's Avatar
Join Date: Nov 2007
Location: xrvel.com
Posts: 1,620
xrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant future
 




Originally Posted by RoTE
Thanks guys... I figured it out with all your help and some other assistance.
The observation about sanitizing the data and cleaning the id... I'll have to implement those as well..

Thanks again.
Juan
You're welcome. Good luck
????: NamePros.com http://www.namepros.com/showthread.php?t=450273

- Kurniawan
__________________
xrvel is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 06:25 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger