Jump to content

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:

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

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

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

(

)

 

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.