praeto Posted October 31, 2007 Share Posted October 31, 2007 Please help, cant find out why I am getting this error... PHP Notice: Undefined index: submit in C:\webserver\php\2\2.php on line 2 <?php switch ($_GET['submit']) { case 'Button1': print 'Button1 was clicked.'; break; case 'Button2': print 'Button2 was clicked.'; break; case 'Button3': print 'Button3 was clicked.'; break; default: print ' <form> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } // End: switch ($_GET['submit']) # END buttons that do different things example ?> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/ Share on other sites More sharing options...
MadTechie Posted October 31, 2007 Share Posted October 31, 2007 Get was not set $Value = ""; if(isset($_GET['submit'])) { $Value = $_GET['submit']; } switch ($Value) { Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381615 Share on other sites More sharing options...
praeto Posted October 31, 2007 Author Share Posted October 31, 2007 Do I place your code in front of the switch _get?? I tried that but received an error. PHP Parse error: syntax error, unexpected T_SWITCH, expecting T_CASE or T_DEFAULT or '}' So I took out the $Value = $_GET['submit']; and it ran without error however the rest of the code didnt work "print 'Button1 was clicked.'; " <?php $Value = ""; if(isset($_GET['submit'])) { $Value = $_GET['submit']; } switch ($Value) { switch ($_GET['submit']) { case 'Button1': print 'Button1 was clicked.'; break; case 'Button2': print 'Button2 was clicked.'; break; case 'Button3': print 'Button3 was clicked.'; break; default: print ' <form> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } // End: switch ($_GET['submit']) # END buttons that do different things example ?> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381623 Share on other sites More sharing options...
MadTechie Posted October 31, 2007 Share Posted October 31, 2007 switch ($Value) { switch ($_GET['submit']) { should be just switch ($Value) { Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381630 Share on other sites More sharing options...
teng84 Posted October 31, 2007 Share Posted October 31, 2007 <?php if(isset($_GET['submit'])){//check if set switch ($_GET['submit']) { case 'Button1': print 'Button1 was clicked.'; break; case 'Button2': print 'Button2 was clicked.'; break; case 'Button3': print 'Button3 was clicked.'; break; default: print ' <form> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } // End: switch ($_GET['submit']) } # END buttons that do different things example ?> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381642 Share on other sites More sharing options...
praeto Posted October 31, 2007 Author Share Posted October 31, 2007 ok, thats what I experimented with however I am unable to get my case to execute... I think the page just reloads. Here is what I am trying to get to work. I can get it to play 1 sound but I would like to choose what sound to play by use of the button. [code<?php # BEGIN buttons that do different things example $Value = ""; if(isset($_GET['submit'])) { $Value = $_GET['submit']; } switch ($Value) { case 'Button1': print 'Button1 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\Notify.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; case 'Button2': print 'Button2 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\ding.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; case 'Button3': print 'Button3 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\chimes.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; default: print ' <form> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } // End: switch ($_GET['submit']) # END buttons that do different things example ########################################################################### # # PHP Counter script. # # Copyright 2006 Host45.com, Inc. # Web and Email Hosting # http://www.host45.com # ########################################################################### if(!file_exists("counter.txt")) { die("Unable to open the counter.txt file! Please create it and set correct permissions.<br>"); } else { $file = fopen("counter.txt", "r"); $num = fgets($file,4096); $num += 1; fclose($file); $file2 = fopen("counter.txt", "w"); fputs($file2, $num); fclose($file2); } echo "This page has been viewed " . $num . " times."; // Below Adds a IP Logger // today's date and time $dateTime = date('Y/m/d G:i:s'); // open some txt file for reading and writing // the file must be read and writeable by web server $fp = fopen('logger.txt', 'a'); fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\r\n"); fclose($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381648 Share on other sites More sharing options...
teng84 Posted October 31, 2007 Share Posted October 31, 2007 are you using get or post? ok, thats what I experimented with however I am unable to get my case to execute... I think the page just reloads. Here is what I am trying to get to work. I can get it to play 1 sound but I would like to choose what sound to play by use of the button. [code<?php # BEGIN buttons that do different things example $Value = ""; if(isset($_GET['submit'])) { $Value = $_GET['submit']; } switch ($Value) { case 'Button1': print 'Button1 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\Notify.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; case 'Button2': print 'Button2 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\ding.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; case 'Button3': print 'Button3 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\chimes.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; default: print ' <form> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } // End: switch ($_GET['submit']) # END buttons that do different things example ########################################################################### # # PHP Counter script. # # Copyright 2006 Host45.com, Inc. # Web and Email Hosting # http://www.host45.com # ########################################################################### if(!file_exists("counter.txt")) { die("Unable to open the counter.txt file! Please create it and set correct permissions.<br>"); } else { $file = fopen("counter.txt", "r"); $num = fgets($file,4096); $num += 1; fclose($file); $file2 = fopen("counter.txt", "w"); fputs($file2, $num); fclose($file2); } echo "This page has been viewed " . $num . " times."; // Below Adds a IP Logger // today's date and time $dateTime = date('Y/m/d G:i:s'); // open some txt file for reading and writing // the file must be read and writeable by web server $fp = fopen('logger.txt', 'a'); fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\r\n"); fclose($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381649 Share on other sites More sharing options...
praeto Posted October 31, 2007 Author Share Posted October 31, 2007 No buttons display when I tried your code... <?php if(isset($_GET['submit'])){//check if set switch ($_GET['submit']) { case 'Button1': print 'Button1 was clicked.'; break; case 'Button2': print 'Button2 was clicked.'; break; case 'Button3': print 'Button3 was clicked.'; break; default: print ' <form> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } // End: switch ($_GET['submit']) } # END buttons that do different things example ?> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381651 Share on other sites More sharing options...
teng84 Posted October 31, 2007 Share Posted October 31, 2007 because your array index is not set ??? you said click button then i guess it should be post? Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381653 Share on other sites More sharing options...
praeto Posted October 31, 2007 Author Share Posted October 31, 2007 I thought I was using get..... are you using get or post? ok, thats what I experimented with however I am unable to get my case to execute... I think the page just reloads. Here is what I am trying to get to work. I can get it to play 1 sound but I would like to choose what sound to play by use of the button. [code<?php # BEGIN buttons that do different things example $Value = ""; if(isset($_GET['submit'])) { $Value = $_GET['submit']; } switch ($Value) { case 'Button1': print 'Button1 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\Notify.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; case 'Button2': print 'Button2 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\ding.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; case 'Button3': print 'Button3 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\chimes.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; default: print ' <form> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } // End: switch ($_GET['submit']) # END buttons that do different things example ########################################################################### # # PHP Counter script. # # Copyright 2006 Host45.com, Inc. # Web and Email Hosting # http://www.host45.com # ########################################################################### if(!file_exists("counter.txt")) { die("Unable to open the counter.txt file! Please create it and set correct permissions.<br>"); } else { $file = fopen("counter.txt", "r"); $num = fgets($file,4096); $num += 1; fclose($file); $file2 = fopen("counter.txt", "w"); fputs($file2, $num); fclose($file2); } echo "This page has been viewed " . $num . " times."; // Below Adds a IP Logger // today's date and time $dateTime = date('Y/m/d G:i:s'); // open some txt file for reading and writing // the file must be read and writeable by web server $fp = fopen('logger.txt', 'a'); fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\r\n"); fclose($fp); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381654 Share on other sites More sharing options...
teng84 Posted October 31, 2007 Share Posted October 31, 2007 do you want this to be displayed print ' <form> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; and your form dont initialize what method to use get or post <form action='' method='post'> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381656 Share on other sites More sharing options...
praeto Posted October 31, 2007 Author Share Posted October 31, 2007 All I am trying to accomplish is to make a menu to be able to pick from 3 button choices. Once the choice is made and button pressed the command is ran. Currently my webcam page plays a wav file when the page is loaded allerting me that someone is watching my cam. I would like to take it a step further and place buttons on my page with 3 different phrases to say (I will record seperate wave files). I just dont know how to do it in PHP. Somewhere in the code we are working on we should be able to do what I mentioned. Any help is appreciated..... Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381660 Share on other sites More sharing options...
teng84 Posted October 31, 2007 Share Posted October 31, 2007 <?php # BEGIN buttons that do different things example $Value = ""; if(isset($_POST['submit'])) { $Value = $_POST['submit']; } switch ($Value) { case 'Button1': print 'Button1 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\Notify.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; case 'Button2': print 'Button2 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\ding.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; case 'Button3': print 'Button3 was clicked.'; $runCommand = "sndrec32 /play /close C:\\Windows\\Media\\chimes.wav"; $WshShell = new COM("WScript.Shell"); $output = $WshShell->Exec($runCommand)->StdOut->ReadAll; echo "<p>$output</p>"; break; default: print ' <form action="'.$_SERVER['PHP_SELF'].'" method = "post"> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } // End: switch ($_GET['submit']) # END buttons that do different things example ########################################################################### # # PHP Counter script. # # Copyright 2006 Host45.com, Inc. # Web and Email Hosting # http://www.host45.com # ########################################################################### if(!file_exists("counter.txt")) { die("Unable to open the counter.txt file! Please create it and set correct permissions.<br>"); } else { $file = fopen("counter.txt", "r"); $num = fgets($file,4096); $num += 1; fclose($file); $file2 = fopen("counter.txt", "w"); fputs($file2, $num); fclose($file2); } echo "This page has been viewed " . $num . " times."; // Below Adds a IP Logger // today's date and time $dateTime = date('Y/m/d G:i:s'); // open some txt file for reading and writing // the file must be read and writeable by web server $fp = fopen('logger.txt', 'a'); fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\r\n"); fclose($fp); ?> try Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381665 Share on other sites More sharing options...
praeto Posted October 31, 2007 Author Share Posted October 31, 2007 Still does nothing.. Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381666 Share on other sites More sharing options...
teng84 Posted October 31, 2007 Share Posted October 31, 2007 sorry im out of this thread seems like your not doing anything and living it to a forum member again sorry..... Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381674 Share on other sites More sharing options...
praeto Posted October 31, 2007 Author Share Posted October 31, 2007 Im asking for HELP, not leaving it for a forum member as you stated. I have 95 percent of the code already written and just need that extra 5 percent to make it work. I have no knowledge of PHP and turned to the members of PHPFREAKS to help me out. I searched to try to get the answer, I tried your code but it simply didnt work. Please dont give up on my question/issue... Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381779 Share on other sites More sharing options...
MadTechie Posted October 31, 2007 Share Posted October 31, 2007 <?php $Value = ""; if(isset($_POST['submit'])) { $Value = $_POST['submit']; } switch ($Value) { case 'Button1': print 'Button1 was clicked.'; break; case 'Button2': print 'Button2 was clicked.'; break; case 'Button3': print 'Button3 was clicked.'; break; default: print ' <form method="POST"> <input type="submit" name="submit" value="Button1" /> <input type="submit" name="submit" value="Button2" /> <input type="submit" name="submit" value="Button3" /> </form>'; break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381829 Share on other sites More sharing options...
pollofrito Posted October 31, 2007 Share Posted October 31, 2007 All I am trying to accomplish is to make a menu to be able to pick from 3 button choices. Once the choice is made and button pressed the command is ran. Currently my webcam page plays a wav file when the page is loaded allerting me that someone is watching my cam. I would like to take it a step further and place buttons on my page with 3 different phrases to say (I will record seperate wave files). I just dont know how to do it in PHP. Somewhere in the code we are working on we should be able to do what I mentioned. Any help is appreciated..... Praeto - have you explicitly set the method to GET in your HTML form? If not, it will be POSTing and not GETing (as that's the default). In which case, simply change your instances of $_GET to $_POST and you're sorted. Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381834 Share on other sites More sharing options...
praeto Posted October 31, 2007 Author Share Posted October 31, 2007 It seems that my webserver (Webweaver) is to blame for the code not working correctly. I am able to run PHP on it however it wont run this script for some reason. I found this out once I ran the same script on another server program (Apache) and it ran fine. Thanks for all that replied. Quote Link to comment https://forums.phpfreaks.com/topic/75436-solved-php-notice-undefined-index-submit-in/#findComment-381959 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.