rEhSi_123 Posted February 22, 2009 Share Posted February 22, 2009 Hello Everybody! I have been trying out a tutorial on http://www.phpeasystep.com/phptu/12.html and have run into few issues...... The issues are in my add_topic.php file which are creating Undefined Index errors on the web page which have got me abit confused. Errors: Notice: Undefined index: Topic in C:\wamp\www\Social_Networking\add_topic.php on line 13 Notice: Undefined index: Detail in C:\wamp\www\Social_Networking\add_topic.php on line 14 Notice: Undefined index: Name in C:\wamp\www\Social_Networking\add_topic.php on line 15 Notice: Undefined index: Email in C:\wamp\www\Social_Networking\add_topic.php on line 16 add_topic.php: <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="forum_question"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get data that sent from form $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_POST['name']; $email=$_POST['email']; $datetime=date("d/m/y h:i:s"); //create date time $sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime)VALUES('$topic', '$detail', '$name', '$email', '$datetime')"; $result=mysql_query($sql); if($result){ echo "Successful<BR>"; echo "<a href=main_forum.php>View your topic</a>"; } else { echo "ERROR"; } mysql_close(); ?> Also I have double checked if the feilds are present in my tables and matter of fact they do! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/ Share on other sites More sharing options...
Philip Posted February 22, 2009 Share Posted February 22, 2009 Above: $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_POST['name']; $email=$_POST['email']; put this: echo '<pre>'; print_r($_POST); echo '</pre>'; // post fields here... And copy/paste what that outputs Quote Link to comment https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/#findComment-768780 Share on other sites More sharing options...
ambo Posted February 22, 2009 Share Posted February 22, 2009 I just Used the same tutorial and mine works let me see what i changed Quote Link to comment https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/#findComment-768784 Share on other sites More sharing options...
ambo Posted February 23, 2009 Share Posted February 23, 2009 Make sure that <form id="form1" name="form1" method="post" action="path/to/add_topic.php"> is correct in create_topic.php Quote Link to comment https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/#findComment-768787 Share on other sites More sharing options...
rEhSi_123 Posted February 23, 2009 Author Share Posted February 23, 2009 Above: $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_POST['name']; $email=$_POST['email']; put this: echo '<pre>'; print_r($_POST); echo '</pre>'; // post fields here... And copy/paste what that outputs Dont know If I did it right.....as I am a Newbie.... it returned: Notice: Undefined index: topic in C:\wamp\www\Social_Networking\add_topic.php on line 15 Notice: Undefined index: detail in C:\wamp\www\Social_Networking\add_topic.php on line 16 Notice: Undefined index: name in C:\wamp\www\Social_Networking\add_topic.php on line 17 Notice: Undefined index: email in C:\wamp\www\Social_Networking\add_topic.php on line 18 Array ( ) Quote Link to comment https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/#findComment-768788 Share on other sites More sharing options...
Philip Posted February 23, 2009 Share Posted February 23, 2009 You're not getting any POST data, from the user. That's why they are "undefined index" errors. How are you submitting the data to that page? Quote Link to comment https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/#findComment-768790 Share on other sites More sharing options...
rEhSi_123 Posted February 23, 2009 Author Share Posted February 23, 2009 You're not getting any POST data, from the user. That's why they are "undefined index" errors. How are you submitting the data to that page? I think I know what you mean mate! Well I send the data from this page create_topic.php: <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form id="form1" name="form1" method="post" action="add_topic.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3" bgcolor="#E6E6E6"><strong>Create New Topic</strong> </td> </tr> <tr> <td width="14%"><strong>Topic</strong></td> <td width="2%">:</td> <td width="84%"><input name="topic" type="text" id="topic" size="50" /></td> </tr> <tr> <td valign="top"><strong>Detail</strong></td> <td valign="top">:</td> <td><textarea name="detail" cols="50" rows="3" id="detail"></textarea></td> </tr> <tr> <td><strong>Name</strong></td> <td>:</td> <td><input name="name" type="text" id="name" size="50" /></td> </tr> <tr> <td><strong>Email</strong></td> <td>:</td> <td><input name="email" type="text" id="email" size="50" /></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </table> </td> </form> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/#findComment-768804 Share on other sites More sharing options...
rEhSi_123 Posted February 23, 2009 Author Share Posted February 23, 2009 Right found the problem and It was really a silly one...... I should have named the file as index.php instead of main_forum.php Anways thanks for helping out Quote Link to comment https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/#findComment-768819 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.