shkura
Новичок
переменная NULLтся 2
Я решил свою проблему, добавив в скрытое поле формы ту самую перменную, которая просто так нулится. Но вопрос остался, какая связь между той перменной и формой была, показываю на примере кода:
Я решил свою проблему, добавив в скрытое поле формы ту самую перменную, которая просто так нулится. Но вопрос остался, какая связь между той перменной и формой была, показываю на примере кода:
файл notepad.txt:<?
ini_set('display_errors',1);
error_reporting(E_ALL);
?>
<form id="form1" name="form1" method="post" action="">
<input type="hidden" name="note" value="submit"/>
<table>
<tr>
<td><input name="np_name" type="text" id="np_name" /></td>
</tr>
<tr>
<td><input name="np_email" type="text" id="np_email" /></td>
</tr>
<tr>
<td><textarea name="np_msg" id="np_msg"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="reset" name="Reset" value="Очистить" /> <input type="submit" name="Submit" value="Написать" /></td>
</tr>
</table>
</form>
<?
include('notepad.txt');
// GET POST DATA
$post_note = $_POST['note'];
$post_name = strip_tags(trim($_POST['np_name']));
$post_email = strip_tags(trim($_POST['np_email'])); $post_email = str_replace('@', '(@)', $post_email); $post_email = str_replace('.', '(.)', $post_email);
$post_msg = strip_tags(trim($_POST['np_msg']));
$post_date = date("m.d.y g:i");
if(isset($np_msg)){$numb = count($np_msg);} else {$numb = 0;}
//echos
var_dump($numb);
if($post_note == 'submit'){
$file_notepad = fopen('notepad.txt', 'r+');
while (!feof($file_notepad)) {
$a .= fread($file_notepad, 9999999);
}
fclose($file_notepad);
if($file_notepad = fopen('notepad.txt', 'w+')){
$a = str_replace('?>', "\$np_date[{$numb}]='{$post_date}'; \$np_name[{$numb}]='{$post_name}'; \$np_email[{$numb}]='{$post_email}'; \$np_msg[{$numb}]='{$post_msg}';\n\r ?>", $a);
fwrite($file_notepad, $a);
fclose($file_notepad);
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
exit;
} else { $error .= 'Невозможно добавить сообщение<br>'; }
}
/*
$np_msg = unserialize(file_get_contents('notepad.txt'));
echo $np_msg;
file_put_contents('notepad.txt', serialize($np_msg));*/
?>
если из файла php удалить, выделенное чёрным, работает как надо, если оставить как я уже говорил - перменная $numb нулится.<?
$np_date[0]='10.09.07 9:08'; $np_name[0]=''; $np_email[0]=''; $np_msg[0]='';
$np_date[1]='10.09.07 9:08'; $np_name[1]=''; $np_email[1]=''; $np_msg[1]='';
$np_date[2]='10.09.07 9:17'; $np_name[2]='jhgjgh'; $np_email[2]='table(@)yandex(.)ru'; $np_msg[2]='gjhjhу!';
?>