|
-
Feb 3rd, 2007, 09:46 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Looping through POST data going wrong
Well, I have the code below, and its probably not very nice, but it works if someone submits only one line, such as
123.123.123.1 123.123.123.2 123.123.123.3 123.123.123.4 123.123.123.5
but if there are line breaks;
123.123.123.1
123.123.123.2
123.123.123.3
123.123.123.4
123.123.123.5
it doesnt work.
It also skips the first explode from the post data.
Can anyone help me with these two probelms, thanks
Page for example( http://greyfyre.info/Submit.php )
PHP Code:
$counterMax = substr_count($_POST['IP']," ");
for ( $counter = 0; $counter <= $counterMax; $counter += 1) {
$sql = mysql_connect($GLOBALS["dbhost"], $GLOBALS["dbuser"], $GLOBALS["dbpass"]);
$dbHandle = mysql_select_db($GLOBALS["dbname"]);
$IP = explode(' ',$_POST['IP']);
$EMAIL = mysql_real_escape_string($_POST['EMAIL']);
$REASON = mysql_real_escape_string($_POST['REASON']);
$LOG = mysql_real_escape_string($target_path);
$SPARE = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$NewIP = mysql_real_escape_string($IP[$counter]);
$sql = "INSERT INTO `$DB` ( `IP` , `Email` , `Reason` , `Log` , `spare` )
VALUES (
'$NewIP', '$EMAIL', '$REASON', '$LOG', '$SPARE'
);";
$result = mysql_query($sql);
mysql_close($sql);
if (is_resource($rows)) {
} else {
echo mysql_error();
}
}
-
Feb 3rd, 2007, 09:56 PM
#2
Hyperactive Member
Re: Looping through POST data going wrong
PHP Code:
$IP = explode(' ',$_POST['IP']); != $IP = explode('\n',$_POST['IP']);
-
Feb 3rd, 2007, 10:10 PM
#3
Thread Starter
Addicted Member
Re: Looping through POST data going wrong
-
Feb 3rd, 2007, 10:41 PM
#4
Hyperactive Member
Re: Looping through POST data going wrong
 Originally Posted by Jazz00006
doesnt work.
i know...i assumed you knew the difference between a whitespace and a newline.
it isn't code.
it is a statement that means you need to explode '\n' which is a newline.
' ' != '\n'. When you explode ' ' you are only exploding whitespace is ascii 0x20 and newline is like 0xA. In other words if you hit enter after each ip address you are putting in '\n' so when you explode ' ' it fails because '\n' != ' '
Although even if you explode '\n' you aren't exploding newline.
Look into
http://us2.php.net/manual/en/function.preg-split.php
Last edited by superbovine; Feb 3rd, 2007 at 10:45 PM.
-
Feb 3rd, 2007, 10:44 PM
#5
Thread Starter
Addicted Member
Re: Looping through POST data going wrong
ah, you were being sneaky should have noticed
ill try and fix up my code with this new info, cheers
-
Feb 3rd, 2007, 11:59 PM
#6
Thread Starter
Addicted Member
Re: Looping through POST data going wrong
cheers, it ended up being something like
PHP Code:
<?PHP
$str = 'new
line';
$chars = preg_split("/[\n,]+/", $str, -1, PREG_SPLIT_OFFSET_CAPTURE);
echo $chars[0][0];
echo '<BR>';
echo $chars[1][0];
?>
to split by new lines (if anyone else wants it)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|