xXSebaSXx Posted March 28, 2008 Share Posted March 28, 2008 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=", "]", "[/url]"); $small = array("[url=", "[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=","]",$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 Quote Link to comment Share on other sites More sharing options...
JD* Posted March 28, 2008 Share Posted March 28, 2008 I'm not sure, but try changing $_POST[submit] to $_POST['submit'] Quote Link to comment Share on other sites More sharing options...
xXSebaSXx Posted March 28, 2008 Author Share Posted March 28, 2008 Tried that... still no entries into the DB. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 i would put some debug echo's through the code to see what values are where and whether your if ($newurl != '') is ever TRUE. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 28, 2008 Share Posted March 28, 2008 Start by removing the @ signs from the mysql_xxxxx() function calls. Then add some error checking to the mysql_query() function call. The examples in the php manual show how to use error checking (or you could read or search the forum as there are thousands of posts where adding error checking to a mysql_query() provided the reason why the query failed.) Quote Link to comment Share on other sites More sharing options...
timmy0320 Posted March 28, 2008 Share Posted March 28, 2008 Also I'm assuming your database connection is in your config file. Try putting your connection on the query like: mysql_query(query, connection); Instead of mysql_query(query) Quote Link to comment Share on other sites More sharing options...
xXSebaSXx Posted March 28, 2008 Author Share Posted March 28, 2008 Thank you very much guys... I think the problem that the script has is that this part is never evaluating to "True". if ($newurl != '') So that is making the whole DB writhing function get skipped. I'm sure that the problem stems from here: for ($i = 0; $i <= sizeof($urls)-1; $i += 1) { $newurl = TextBetween("[url=","][img]",$urls[$i]); $thumburl = TextBetween("[img=","]",$urls[$i]); More specifically the $urls[$i] part. So here is what I wanted to achieve with this script. 1. I submit data in this format . 2. The scripts cycles though the data organizing so that each BBCODE is in its own separate line. 3. The organized BBCODES are stored to the $urls variable and converted to lowercase. This part is all OK.... After this... My intention was to have the script do the following: 4. Cycle through each line in $urls and eliminate the BBCODE tags. storing the url part to the $newurl variable and the thumb url to the $thumburl variable. 5. It should then check $newurl, if it's not empty... then it should write the two variables to the respective columns in the DB. 6. It should then cycle back and continue down the list of BBCODES in $urls. That second part is what is throwing everything off... I guess I'm just gonna have to go back to reading a lot more before I can set this up. Thanks Juan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.