Jump to content

[SOLVED] Undefined Index Errors!!!!


rEhSi_123

Recommended Posts

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:

  Quote

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:

  Quote

<?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

Link to comment
https://forums.phpfreaks.com/topic/146431-solved-undefined-index-errors/
Share on other sites

  Quote

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:

  Quote

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

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:

  Quote

<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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.