PHP Error

can somebody tel me whats wrong with this line?

Error:
QuoteNotice: Undefined index: submit in /home/mazlum/domains/onlinestereo.org/public_html/add_news.php on line 7


Line:
Quoteif($_POST['submit'] && $_POST['title'] && $_POST['writer'] && $_POST['text']){
Comments
12
I think you got some Undefined index @ line 7 from add_news
what does this tell u
Quote by code
if($_POST['submit'])
if($_POST['title'])
if($_POST['writer'])
if($_POST['text']) {


and maybeu wrote smth wrong in ur html form
use isset() to check it before
what the two above me said
$_POST['submit'] and so on don't return 'true' or 'false' so u cant just use them right away in your if statement, just use isset() like the guys above said.
what do u want 2 to ?
checking if its empty/set ?

if($_POST['submit'] == ''){
echo 'fu';
}

or != '' ofc
Quote<?php
include('config.php');

mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_database);

if($_POST['submit'] && $_POST['title'] && $_POST['writer'] && $_POST['text']){
$sql = "SELECT * FROM news";
$result = mysql_query($sql);
$num = mysql_num_rows($result);

if($num == 0){
$id = 0;
}else{
$id = $num;
}

$title = $_POST['title'];
$writer = $_POST['writer'];
$text = $_POST['text'];
echo $text."<br>";
$date = date("d-m-Y H:i");

$fn = $id.$file_ext;
$fp = fopen($file_url.$fn, 'a');
fputs($fp, $text);
fclose($fp);

$sql = "INSERT INTO news (id, title, writer, posted_at, text_url) VALUES ('".$id."', '".$title."', '".$writer."', '".$date."', '".$file_url.$fn."')";
mysql_query($sql);
mysql_close();

echo '<meta http-equiv="Refresh" content="3;url=news.php">';
}else{
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="100">Title</td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td valign="top" width="100">Writer</td>
<td><input type="text" name="writer"></td>
</tr>
<tr>
<td valign="top" width="100">Your news</td>
<td><textarea cols="75" rows="15" name="text"></textarea></td>
</tr>
<tr>
<td colspan="2"><input name="submit" type="submit" value="Add news"></td>
</tr>
</table>
</form>
<?php
}
?>
Parent
you can ignore it (error_reporting(E_ALL ^ E_NOTICE); in the beginnnig of the file), because nothing is really broken (just a "notice"), or you fix it by doing it like this:

if(!empty($_POST['submit']) && !empty($_POST['title']) && !empty($_POST['writer']) && !empty($_POST['text'])){
Thq its working LOVE FOR YOU(L)(K)
Parent
you can also work with: <?php if(($_POST['submit'] !="") && ($_POST['title'] != "") && ($_POST['writer'] != "") && ($_POST['text' !=""])){..}
Parent
will throw the exact same notices.
Parent
k , sorry did not saw you used the error reporting 0.o
Parent
Back to top