473,587 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Undefined index error after submitting the form

36 New Member
This is the code to display the details (postfunction.ph p)
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     // Connection data (server_address, database, username, password)
  4.     $dbhost = 'localhost';
  5.     $dbname = 'posting';
  6.     $dbuser = 'root';
  7.     $dbpass = '';
  8.  
  9.     // Display message if successfully connect, otherwise retains and outputs the potential error
  10.  
  11.     try {
  12.         $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $dbuser, $dbpass);
  13.                  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  14.     }
  15.  
  16.     catch(PDOException $e) 
  17.         {
  18.             echo $e->getMessage();
  19.         }
  20.  
  21.     try 
  22.         {
  23.             $query = $conn->prepare("SELECT * FROM review WHERE pid = :pid");
  24.             $query->execute(array(':pid' => $_GET['pid'],)); 
  25.         }
  26.  
  27.     catch (PDOException $e) 
  28.         {
  29.             error_log($e->getMessage());
  30.             die($e->getMessage());
  31.         }    
  32.  
  33.  
  34.     while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
  35.         //Details..
  36.         }
  37.     $conn=null;
  38.  
Theres a form in that page to submit the review .
When i submit the form it displays an error saying :Undefined index: pid in C:\wamp\www\New \signup\postfun c.php on line 25

Heres the form
Expand|Select|Wrap|Line Numbers
  1. <form action="ins.php" method="post">
  2.    <input type="hidden" name="pid" value="<? . $row['pid'] . ?>" />
  3.    <input type="hidden" name="id" value="<? . $row['id'] . ?>" />
  4.    <input type="text" name="review" />
  5.    <input name="submit" type="submit" value="Submit"/>
  6. </form>
  7.  
Line 25 is : $query->execute(array( ':pid' => $_GET['pid'],));

I have used $_GET['pid'] because on my other page there are links . When i click on those , they get displayed in this page (postfunction.ph p) by getting the pid of those links .

What am i missing ?
Jan 26 '13 #1
2 2523
Anas Mosaad
185 New Member
You are trying to retrieve data from a get request while your form is POST not get.
Jan 26 '13 #2
yateesh
36 New Member
The code for inserting form data is below :
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     // Connection data (server_address, database, username, password)
  4.     $dbhost = 'localhost';
  5.     $dbname = 'posting';
  6.     $dbuser = 'root';
  7.     $dbpass = '';
  8.  
  9.     // Display message if successfully connect, otherwise retains and outputs the potential error
  10.  
  11.     try 
  12.         {
  13.             $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $dbuser, $dbpass);
  14.             echo 'Connected to database';
  15.             $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16.         }
  17.  
  18.     catch(PDOException $e) 
  19.         {
  20.             echo $e->getMessage();
  21.         }
  22.  
  23.     try 
  24.         {
  25.             $query = $conn->prepare("INSERT INTO `comment` (review,pid,id) VALUES (:review, :pid,:id)");
  26.  
  27.             $query->execute(
  28.                             array(
  29.                                     'review'  => $_POST['review'],
  30.                                     'pid'     => $_POST['pid'],
  31.                                     'id'      => $_POST['id'],
  32.                                     )); 
  33.         }
  34.  
  35.     catch (PDOException $e) 
  36.         {
  37.             error_log($e->getMessage());
  38.             die($e->getMessage());
  39.         }
  40.  
  41.    $dbh = null;    
  42.  
  43.     header('location: post.php');
  44.  
  45.     exit(); 
  46.  
  47. ?>
  48.  
I want to insert form data into this table

Expand|Select|Wrap|Line Numbers
  1. rid   -  //id of review table
  2. review   -   //review text entered by user
  3. pid   -   //id from review table
  4. id   -   //id from user table
  5.  
So when i submit , it displays that error .
postfunction.ph p is only for displaying the details of the review . There is no form for that .
How do i solve this . I am confused in linking these .
Jan 26 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
498
by: Chris | last post by:
I have a simple search feature that searches 3 fields in 3 separate tables in a MySQL db, and I'm getting an 'undefined index' error, but only in the first section (first table)of the results. The undefined index is tied to the docs.projID in the "if ($row_search == 1)". This if statement is there to control to format of the link as pages...
1
1773
by: shalini11 | last post by:
Hello, I am using a page that has a dropdown list. when the user selects an item from the list and click on submit button, it opens a new page and displays the selected item. I've used as method in my form. and request to retrieve the selected value: <form method="POST" name="frmcriteria" action="test.php" target="_blank" onsubmit="return...
6
20844
by: jsgoodrich | last post by:
I am looking for some help if anyone can lend a hand. I have a simple php website that displays a table from my mysql database. To prep for my MCSE I moved my home server to Windows 2003 Standard, I installed mysql and php 5 to run some of my databases and websites. Under Linux the site worked fine, under windows I keep getting Notice...
3
2056
by: JJM0926 | last post by:
I've got a contact form with a submit button where users have to enter their support information. Some fields are required some are not. When I test out the form if I leave everything blank I get these two undefined index error : Notice: Undefined index: CurrentCustomer in E:\WebSites\mysite\www \contactus.php on line 9 Notice:...
7
1389
by: ridgedale | last post by:
I wonder if anyone can help resolve an issue I've come across in making a customer's website live when it has tested fine in my own hosting space. I am getting the following errors: Notice: Undefined index: vartalk For reference I provide the following links: My hosting space (where everything appears to be working fine):...
7
2525
by: Philth | last post by:
Hey there, it has to be said that I am a complete novice in PHP, I know this is a common error and has probably been covered to some degree already - but my head really does hurt - so I couldn't stand trawling through anymore forums hunting for the right answer. Anyway - here goes. The page I'm having trouble with is a simple edit row type...
1
1620
by: jason1987 | last post by:
I keep getting the undefined index error on the bottom two rows of my code simparent and equtype - the other two work fine yet there is no difference in my code. equtypeid is even from the same table as the top two $equid=$HTTP_POST_VARS; $fromuserid=$HTTP_POST_VARS; $simparent=$HTTP_POST_VARS; $equtype=$HTTP_POST_VARS; these are...
6
1630
by: nadomt | last post by:
Happy friday to all! I am getting the below error when visiting my user filter page. i have gone to line 68, but cant see what the problem is...can anyone assist? advanced THANK YOU! Error: E_NOTICE URL: http://mysite.com/admin/users_filter.php File: /home1/mysite/public_html/admin/users_filter.php Line: 68
3
3319
by: furqi | last post by:
hi i am actually having problem in this code i am trying to check the value in the if condition in the very last lines of the code but i am facing an error of "undefined index" can anybody tell me so that i can solve my problem. <html> <body> <form method="GET" action="switchcases.php"> <input type='text' name='furqan' > <?php...
3
2023
by: mediator | last post by:
Hello I have a php contact email form on my a ecommerce shop website ! I am getting a Undefined index error messages coming from the top of the php code, the email form its self works fine, HERE IS THE ERROR MESSAGES Notice: Undefined index: Name in E:\domains\t\tools2diy.co.uk\user\htdocs\contact.php on line 13 Notice: Undefined...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.