Jump to content

[SOLVED] PHP Notice: Undefined index: submit in .......


Recommended Posts

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

?>

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

?>

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

?>

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

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

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

?>

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

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

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

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

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

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

?>

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.

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. 

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.