Hello all... new here. Just now starting to learn PHP and MySQL.
I've started my journey with a this little 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.sfbyp.com/show.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>";
}
?>
In my limited knowledge of this matter... I would expect the code to take the data sent via the submission form, process it via the TextBetween() function and write the results from that process to my DB... after that it would display the processed data into the same form...
For some reason... submitting the form doesn't write to the database or display anything afterwards.
Any idea where I may be messing it up?
Thanks,
Juan