473,775 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP Notice: Undefined index

52 New Member
Another PHP newbie here, I trolled the boards here trying some of the different solutions but I keep getting the errors over an over. maybe my problem is specific. I keep getting the following when I load my test.php file into the browser.

Expand|Select|Wrap|Line Numbers
  1. PHP Notice: Undefined index: variable in Path to page on line 24
  2.  
The line in question is this

Expand|Select|Wrap|Line Numbers
  1. $query1="insert into tablename ('var','var1','var2','var3','var4','var5','var6') values ('" . $_POST["var"] . "', '" . $_POST["var1"] . "', '" . $_POST["var2"] . "', '" . $_POST["var3"] . "', '" . $_POST["var4"] . "', '" . $_POST["var5"] . "','" . $_POST["var6"] . "')";
  2.  
I'm sure it's something simple, but I can seem to shake it. I have of course changed the variable names, but you get the idea. I get one error for each variable. The page itself displays fine it just these errors at me. Any help would be great.

Thanks

Dean
Nov 29 '07 #1
5 6689
Markus
6,050 Recognized Expert Expert
for the values you don't need to do (' ".$vari." ')

just do ('$vari')

Other than that (which isnt an error) i don't know :(
Nov 29 '07 #2
aym
4 New Member
post the whole code please with your form???
Nov 29 '07 #3
movieking81
52 New Member
I haven't written the form yet. Just a couple of tables and pictures on the page. Is that the problem? Here is the whole page.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <title>Title</title>
  5. <link rel="stylesheet" type="text/css" href="style.asp">
  6. <?php include("javascript.js"); ?>
  7.  
  8. <?php
  9. if ($_POST["function"] = "add")
  10.     {
  11.     $con = odbc_connect('databasename','root','');
  12.  
  13.     $query1="insert into tablename ('var','var1','var2','var3','var4','var5','var6') values ('" . $_POST["var"] . "', '" . $_POST["var1"] . "', '" . $_POST["var2"] . "', '" . $_POST["var3"] . "', '" . $_POST["var4"] . "', '" . $_POST["var5"] . "','" . $_POST["var6"] . "')";
  14.  
  15.     $cr1=odbc_exec($con,$query1); 
  16.  
  17.     odbc_close($con);
  18.     }
  19. ?>
  20. <body>
  21. <table>
  22. <tr>
  23. <td>
  24. Test
  25. </td>
  26. <td>
  27. <img src="whatever.jpg">
  28. </td>
  29. </tr>
  30. </table>
  31. </body>
  32. </html>
  33.  
Nov 29 '07 #4
Markus
6,050 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <title>Title</title>
  5. <link rel="stylesheet" type="text/css" href="style.asp">
  6.  
[php]
<?php include("javasc ript.js"); ?>

<?php
if ($_POST["function"] = "add")
{
$con = odbc_connect('d atabasename','r oot','');

$query1="INSERT INTO `table_name`
(var, var1, var2, var3, var4, var5, var6)
VALUES
('$_POST["var"]',
'$_POST["var1"]',
'$_POST["var2"]',
'$_POST["var3"]',
'$_POST["var4"]',
'$_POST["var5"]',
'$_POST["var6"]')";

$cr1=odbc_exec( $con,$query1);

odbc_close($con );
}
?>
[/php]
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <table>
  3. <tr>
  4. <td>
  5. Test
  6. </td>
  7. <td>
  8. <img src="whatever.jpg">
  9. </td>
  10. </tr>
  11. </table>
  12. </body>
  13. </html>
  14.  
Cleaned it up a little bit there.

Hm..

The only thing i can think of is that it because you haven't opened a connection anywhere, where you state odbc_close it generates an error?

I'm really not sure.
Nov 29 '07 #5
movieking81
52 New Member
Ok, here is what I have now and the new error.

Expand|Select|Wrap|Line Numbers
  1. <?php    
  2.  
  3. if ($_POST["function"] = "add")
  4.     {
  5.     var $var1 = $_POST['var1'];
  6.     var $var2 = $_POST['var2'];
  7.     var $var3 = $_POST['var3'];
  8.     var $var4 = $_POST['var4'];
  9.     var $var5 = $_POST['var5'];
  10.     var $var6 = $_POST['var6'];
  11.     var $var7 = $_POST['var7'];
  12.  
  13.     $con = odbc_connect('databasename','','');
  14.  
  15.     $query1="insert into tablename
  16.     (tablefield1, tablefield2, tablefield3, tablefield4, tablefield5, tablefield6, tablefield7)
  17.              VALUES
  18.     ('$var1',
  19.      '$var2',
  20.      '$var3',
  21.      '$var4',
  22.      '$var5',
  23.      '$var6',
  24.      '$var7')";
  25.  
  26.     $cr1=odbc_exec($con,$query1); 
  27.  
  28.     odbc_close($con);
  29.     }
  30.  
  31. ?>
  32.  
And the new error

Expand|Select|Wrap|Line Numbers
  1. PHP Parse error: syntax error, unexpected T_VAR in C:\yada\yada\yada\test.php on line 12
  2.  
Line 12 being...
Expand|Select|Wrap|Line Numbers
  1.     var $var1 = $_POST['var1'];
  2.  
In addition I checked the version of PHP via phpinfo() and it's 5.2.1, so no problem there. I know I'm just getting something wrong in the syntax.
Nov 30 '07 #6

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

Similar topics

6
20855
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 Undefined Index error on line 67
3
5504
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice: Undefined index: FriendName in D:\Yan\Over_8\SendEmail.php on line 4, Notice: Undefined index: FriendEmail in D:\Yan\Over_8\SendEmail.php on line 5, Notice: Undefined index: Name in D:\Yan\Over_8\SendEmail.php on line 6, Notice: Undefined index: Email...
2
10634
by: Reggie | last post by:
am trying to create a a upload file.am uploading files ok but i recieve this message. Notice: Undefined variable: uploaded_size in /home/fhlinux169/c/ clashoff.co.uk/user/htdocs/upload.php on line 7 Notice: Undefined variable: uploaded_type in /home/fhlinux169/c/ clashoff.co.uk/user/htdocs/upload.php on line 14 Notice: Undefined index: uploadedfile in /home/fhlinux169/c/
3
3876
by: sickboy | last post by:
$channels=$_GET; if (empty($channels)) { $channels='blank'; } changechannels($channels); $theatre=$_GET; if (empty($theatre)) { $theatre='splash'; } changetheatre($theatre); $info=$_GET; if (empty($info)) { $info='noinfo'; } changeinfo($info); Hey everyone, I keep getting an error regarding the above code. These are the errors: Notice: Undefined index: channels in /home/forcefed/public_html/index.php on line 5
5
7366
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : $http_ref= $HTTP_REFERER; $prog = $_COOKIE;
1
2744
by: francsutherland | last post by:
Notice: Undefined index: send in D:\Domains\workingdata.co.uk\wwwroot\contact_text.php on line 7 Hi, I've started getting this error in the contact page form of my website. The web hosting company did an upgrade and it seems to coincide with that. The Notice is at the top of the page, but the rest of the page displays normally and form still works. I don't get the Notice when I test the page on the local Apache server in the XAMPP...
10
3272
by: FutureShock | last post by:
I have since recently turned up my error reporting on a production site to E_ALL to ensure I am using 'best practices' when writing out code. So far it has helped me discipline myself with initializing my variables. I am running into a problem with my $_POST array though. I am self-referencing a form page for processing, so at the beginning I am looking for the existence of certain $_POST variables for processing. I am setting an...
11
6759
by: stealthmode666 | last post by:
New to .php so need script help. I want to know how to stop this being displayed when I click submit. Notice: Undefined index: homeowner in E:\domains\r\...\user\htdocs\...\form.php on line 166 I have an array which takes filled in fields and blank fields and sends them via email. I DON'T need the user to fill in all the fields which is resulting in this notice on every field that is not filled in. I do need the fields to be sent tho'...
4
2908
by: complearn | last post by:
Do you know why I got these errors for status_bar.php in some webhost, but work perfectly on other webhost? Whats wrong? here are the codes from line 18, our webhost is running php5. $dmg = ($_GET == 0 || $_GET == '22') ? $_GET : $_GET+$_GET;
2
4588
by: Smellydog | last post by:
I'm having a strange issue with PHP version 5.2.8 running on Windows Vista with Lighttpd. I receive a Notice that says the following: Notice</b>: Undefined index: name in <b>E:\LightTPD\htdocs\go\go\form.php</b> on line <b>160</b> Here is the odd part. No matter what I do, no matter how many times I change the script, add lines, remove lines, the notice keeps referencing the same file and line number. Even when I comment out the line,...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10107
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10048
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9916
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5360
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4017
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
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.