NameSilo

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

Spaceship Spaceship
Watch

RoTE

Established Member
Impact
0
Hey guys...
I'm working on a small PHP file
PHP:
<?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'>
<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:
$yoururl = "http://www.gonzolicious.com/redir.php?rid=".$usedid;

I know the syntax for that line is correct... I tested with
PHP:
<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)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Your problem:

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

Change it to:

PHP:
    $addtodb = @mysql_query("INSERT into redirects (link,thumb) VALUES ('".$newurl."','".$thumburl."'");
 
0
•••
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:
0
•••
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.
 
0
•••
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
 
0
•••
peter@flexiwebhost said:
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.


xrvel said:
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..

Thanks again.
Juan
 
0
•••
RoTE said:
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 :tu:

- Kurniawan
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back