Problem with switch/case


#1

Hey there…

i have a problem with a switch…there are no errors, but when the form is filled in and accepted, theres is even the message thrown “Sie wurden erfolgreich angemeldet!” -> “signed up successfully” but the the database is empty. theres a new entry…but all fields are empty.

<?php
////////////////////////////////////////////////////////
////	Die notwendigen Includes werden geladen		////
////////////////////////////////////////////////////////

include ("msg.php");
include ("config.php");


////////////////////////////////////////////////////////
////	      Submitvalue wird abgefragt	  ////
////////////////////////////////////////////////////////

$submit =$_POST['submit'];

//////////////////////////////////////////////////////////////////
////  	Wurde das Formular ausgef?llt -> folgender Ablauf  	  ////
//////////////////////////////////////////////////////////////////


if ($submit == "Eintragen")
{
	$S_VName = $_POST['S_VName'];
	$S_NName = $_POST['S_NName'];
	$S_Adr = $_POST['S_Adr'];
	$S_Email = $_POST['S_Email'];
	$S_Tel = $_POST['S_Tel'];
	$S_Studg = $_POST['S_Studg'];
	$S_MatrNr = $_POST['S_MatrNr'];
	$S_Uni = $_POST['S_Uni'];
	$S_Text = $_POST['S_Text'];
	$S_AGB =  $_POST['agb'];

	
switch($_GET['action']){
case proof: 
	if(isset($S_AGB))  // Pr?ft ob AGBS akzeptiert wurden
	{
		if(is_numeric($S_MatrNr) && is_numeric($S_Tel))   //pr?ft ob Matrikelnummer und Telefonnumer aus Zahlen bestehen
		{
 				
				////////////////////////////////////////////////////////
				////	     Ausgabe der eingegebenen Daten			////
				////////////////////////////////////////////////////////
				
				echo '<form id="s_check" name="s_check" method="post" action="studform.php?action=send">
 					  <table width="500" cellpadding="0" cellspacing="0">
  						<tr>
   				 			<td colspan="3">Bitte &uuml;berpr&uuml;fen Sie ihre Daten auf ihre Richtigkeit</td>
 						</tr>
 						<tr>
    						<td>&nbsp;</td>
    						<td>&nbsp;</td>
    						<td>&nbsp;</td>
  						</tr>
  						<tr>
    						<td width="162">Vorname:</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">' .$S_VName. '</td>
  						</tr>
  						<tr>
    						<td width="162">Nachname:</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">'.$S_NName.'</td>
  						</tr>
  						<tr>
    						<td width="162">Adresse:</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">'.$S_Adr.'</td>
  						</tr>
  						<tr>
    						<td width="162">E-Mail:</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">'.$S_Email.'</td>
 						</tr>
  						<tr>
    						<td width="162">Telefon/Handy:</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">'.$S_Tel.'</td>
  						</tr>
  						<tr>
    						<td width="162">Studiengang:</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">'.$S_Studg.'</td>
  						</tr>
  						<tr>
    						<td width="162">Matrikelnummer:</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">'.$S_MatrNr.'</td>
  						</tr>
  						<tr>
    						<td width="162">Universit&auml;t:</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">'.$S_Uni.'</td>
  						</tr>
  						<tr>
    						<td width="162">Warum du?</td>
    						<td width="23">&nbsp;</td>
    						<td width="302">'.$S_Text.'</td>
  						</tr>
  						<tr>
    						<td>&nbsp;</td>
    						<td>&nbsp;</td>
    						<td>&nbsp;</td>
  						</tr>
	  					<tr>
    						<td>&nbsp;</td>
    						<td>&nbsp;</td>
    						<td><input type="button" name="back" value="Falsch, zur&uuml;ck.." onClick="javascript:history.go(-1)" /><input name="submit" type="submit" value="Eintragen" /></td>
 						</tr>
					</table>
					</form> ';
				}
			if(!is_numeric($S_MatrNr))		// Gibt eine Fehlermeldung, wenn MatrNr nicht aus Zahlen besteht
			{
				msg("Falsche Matrikelnummer!!",1);
			}
			if(!is_numeric($S_Tel))			// Gibt eine Fehlermeldung, wenn TelNr nicht aus Zahlen besteht
			{
				msg("Telefonnummer falsch eingegeben!!",1);
			}
		}
	else		// Gibt eine Fehlermeldung, wenn AGBs nicht akzeptiert
		msg("Sie haben die AGB's nicht akzeptiert!!",1);
break;
//////////////////////////////////////////////////////////////////
////  	Wurden Eingaben best?tigt -> in DB eintragen	  	  ////
//////////////////////////////////////////////////////////////////
case send:
	{	
		mysql_connect($server, $dblogin, $pw);

		$sqlab = "INSERT INTO stud_test (`S_VName` , `S_NName` , `S_Adr` , `S_Email` , `S_Tel`,`S_Studg` ,`S_MatrNr` ,`S_Uni` ,`S_Text`  ) VALUES ('$S_VName', '$S_NName', '$S_Adr', '$S_Email', '$S_Tel', '$S_Studg', '$S_MatrNr', '$S_Uni', '$S_Text')";
		$res = mysql_db_query($db, $sqlab);

		if ($res != "1")
			msg("Daten bereits eingetragen!",1);
		else
			msg ("Sie wurden erfolgreich angemeldet!",0);
	}
}
}
////////////////////////////////////////////////////////////
////			Eingabeformular f?r Studenten			////
////////////////////////////////////////////////////////////

if(!$submit)
{
echo '
<form id="supdate" name="supdate" method="post" action="studform.php?action=proof">
  <table width="500" border="0">
    <tr>
      <th width="162" scope="col">&nbsp;</th>
      <th width="23" scope="col">&nbsp;</th>
      <th width="301" scope="col">&nbsp;</th>
    </tr>
    <tr>
      <td>Vorname:</td>
      <td>&nbsp;</td>
      <td><input name="S_VName" type="text" size="30" maxlength="30" />      </td>
    </tr>
    <tr>
      <td>Nachname:</td>
      <td>&nbsp;</td>
      <td><input name="S_NName" type="text" size="30" maxlength="30" /></td>
    </tr>
    <tr>
      <td>Adresse:</td>
      <td>&nbsp;</td>
      <td><input name="S_Adr" type="text" size="30" maxlength="30" /></td>
    </tr>
    <tr>
      <td>E-Mail:</td>
      <td>&nbsp;</td>
      <td><input name="S_Email" type="text" size="30" maxlength="30" /></td>
    </tr>
    <tr>
      <td>Telefon/Handy:</td>
      <td>&nbsp;</td>
      <td><input name="S_Tel" type="text" size="30" maxlength="30" /></td>
    </tr>
    <tr>
      <td>Studiengang:</td>
      <td>&nbsp;</td>
      <td><input name="S_Studg" type="text" size="30" maxlength="30" /></td>
    </tr>
    <tr>
      <td>Matrikelnummer:</td>
      <td>&nbsp;</td>
      <td><input name="S_MatrNr" type="text" size="30" maxlength="30" /></td>
    </tr>
    <tr>
      <td>Universit&auml;t:</td>
      <td>&nbsp;</td>
      <td><input name="S_Uni" type="text" size="30" maxlength="30" /></td>
    </tr>
    <tr>
      <td valign="top">Warum du? </td>
      <td>&nbsp;</td>
      <td><textarea name="S_Text" cols="30" rows="10"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type="checkbox" name="agb" value="agb" />
  Ich habe die AGB's gelesen und bin damit einverstanden</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" value="Eintragen" /></td>
    </tr>
  </table>
</form>';
}

?>
</body>
</html>

sorry…the source is in german…but i think you will understand…


#2

It looks like that you are verifying the results by checking the Resource Id ($res). The resource id will not always be 1 even if successful.

You should check mysql_error() or mysql_errno(). If it’s 0 (zero) then the query executed WITHOUT error.

[php]
$sqlab = “INSERT INTO stud_test (S_VName , S_NName , S_Adr , S_Email , S_Tel,S_Studg ,S_MatrNr ,S_Uni ,S_Text ) VALUES (’$S_VName’, ‘$S_NName’, ‘$S_Adr’, ‘$S_Email’, ‘$S_Tel’, ‘$S_Studg’, ‘$S_MatrNr’, ‘$S_Uni’, ‘$S_Text’)”;
$res = mysql_db_query($db, $sqlab);

  if ($res != "1")
     msg("Daten bereits eingetragen!",1);
  else
     msg ("Sie wurden erfolgreich angemeldet!",0);

}
[/php]