Registration -> in Tabelle schreiben = Problem

mareikiii

Grünschnabel
Hallo,

mein Problem liegt darin, dass dieses Registrationsskript nichts in die Tabelle schreibt. Er geht springt irgendwie nie in den case "switch". Das Ausfüllen des Formulars klappt einwandfrei. Doch dann macht er nichts und es gibt auch keine Einträge in der Tabelle.

Ich habe mal zum testen bei case 'switch' einfach nur einen echo Befehl eingebaut um zu schauen ob er überhaupt dort reinspringt. Macht er aber nicht. Der Kommentar ist die eigentliche Zeile, die dort stehen sollte.

Jemand eine Idee? Hier nun der kkomplette Code:


PHP:
<script>

function perevirka(){
        if (document.getElementById('login').value=='') var eror=1;
        if (document.getElementById('password').value=='') var eror=1;
        if (document.getElementById('password2').value=='') var eror=1;
        if (document.getElementById('first_name').value=='') var eror=1;
        if (document.getElementById('last_name').value=='') var eror=1;
        if (document.getElementById('email').value=='') var eror=1;
        if (document.getElementById('login').value=='') var eror=1;
        
        if ((document.getElementById('password').value)!==(document.getElementById('password2').value)) var eror=2;
        
                
        if  (eror==1) alert('<?=_FILL_ALL_FIELDS ?>');
        else if  (eror==2) alert('<?=_INCOR_PASS_CONF ?>');
        else {
            document.getElementById('register').value="yes";
            document.register_cus.submit();
            }    
    
    }    
</script>

<?php

mysql_connect($sysConfig_host, $sysConfig_db_user, $sysConfig_db_password) or die ("Can`t connect to DB");
mysql_select_db($sysConfig_db) or die ("Can`t select DB `$sysConfig_db`");

function save_registration()
{
 global $sysConfig_live_site;

 $email=$_REQUEST['email'];
 $login=$_REQUEST['login'];
 $pass=md5($_REQUEST['password']);
 $f_name=$_REQUEST['first_name'];
 $l_name=$_REQUEST['last_name'];
 $company=$_REQUEST['company'];
 $position=$_REQUEST['position'];
 $adress=$_REQUEST['adress'];
 $zip=$_REQUEST['zip'];
 $city=$_REQUEST['city'];
 $phone=$_REQUEST['phone'];
 $mobile=$_REQUEST['mobile'];
 $fax=$_REQUEST['fax'];
 $timezone=$_REQUEST['timezone'];
 $countries=$_REQUEST['countries'];

 if (check_login($login))
  echo("<script>alert('"._LOGIN_EXISTS."'); history.go(-1);</script>");
 else
 {

 $query=("
  SELECT `user_id` FROM `users` ORDER BY `user_id` DESC LIMIT 1 
 ");
 
 $id_result=mysql_query($query);
 $id=mysql_result($id_result, 0)+1;
 
 $query=("
  INSERT INTO `users` ( `user_id` , `user_group`, `login`, `password`, `email` ) VALUES ( '$id', '2', '$login', '$pass', '$email')
 ");
 
 $result_cats=mysql_query($query);


 $query=("
  INSERT INTO `customers` ( `customer_id` , `first_name` , `last_name` , `company` , `position` , `adress` , `zip` , `city`, `phone`, `mobile`, `fax`, `timezone` , `country` )
  VALUES ( '$id', '$f_name', '$l_name', '$company', '$position', '$adress', '$zip', '$city', '$phone', '$mobile', '$fax' , '$timezone' , '$countries'
  )
 ");
 
 $result=mysql_query($query);
 
 if (!$result)
 {
  echo '<script>alert("'.mysql_error($result).'");</script>';
  exit;
 }
 
  reg_mail($login); 

 return $result;
 
 } // else
}

switch($task)
{
    case 'save':
    echo 'Funktioniert';  //    if (save_registration()) echo (_USER_ADDED); else echo ('error while adding');
    break;

    default:
    
?>

<form name="register_cus" action="<?=$sysConfig_live_site ?>/register_cus/save" method="POST">
 <?=_LOGIN ?>: <br><input type="text" name="login" id="login" />&nbsp;*<br><br> 
 <?=_PASSWORD ?>: <br><input type="password" name="password" id="password" />&nbsp;*<br><br> 
 <?=_PASSWORD_CONFIRM ?>: <br><input type="password" name="password2" id="password2" />&nbsp;*<br><br> 
 <?=_EMAIL ?>: <br><input type="text" name="email" id="email" />&nbsp;*<br><br>
 <?=_FNAME ?>: <br><input type="text" name="first_name"  id="first_name"/>&nbsp;*<br><br>
 <?=_LNAME ?>: <br><input type="text" name="last_name" id="last_name" />&nbsp;*<br><br>
 <?=_COMPANY ?>: <br><input type="text" name="company" /><br><br>
 <?=_POSITION ?>: <br><input type="text" name="position" /><br><br>
 <!--<?=_ADRESS ?>: <br><textarea name="adress"></textarea><br><br>-->
 <?=_COUNTRIES ?>:<br>
 <select name="countries" style="width:120px;">
  <?php
    $countries=get_countries();
    for ($i=0; $i<count($countries); $i++)
     {
        echo "<option value='".$countries[$i]['id_countri']."'>".$countries[$i]['country_eng']."</option>";
     }
  ?>
 </select><br><br>
 
 
 <?=_TIMEZONE ?>:<br>
 <select name='timezone' id='timezone' style='width:120px;'>
    <option value='-12'>Eniwetok (GMT-12)</option>
    <option value='-11'>Samoa (GMT-11)</option>
    <option value='-10'>Hawaii (GMT-10)</option>
    <option value='-9'>Alaska (GMT-9)</option>
    <option value='-8'>Pacific Time (GMT-8)</option>
    <option value='-7'>Mountain Time (GMT-7)</option>
    <option value='-6'>Central Time (GMT-6)</option>
    <option value='-5'>Eastern Time (GMT-5)</option>
    <option value='-4'>Atlantic Time (GMT-4)</option>
    <option value='-3'>Brazilia (GMT-3)</option>
    <option value='-2'>Mid-Atlantic (GMT-2)</option>
    <option value='-1'>Azores (GMT-1)</option>
    <option value='0'>Greenwich Mean Time (GMT)</option>
    <option value='1'>Rome (GMT +1)</option>
    <option value='2'>Israel (GMT +2)</option>
    <option value='3'>Moscow (GMT +3)</option>
    <option value='4'>Baku (GMT +4)</option>
    <option value='5'>New Delhi (GMT +5)</option>
    <option value='6'>Dhakar (GMT +6)</option>
    <option value='7'>Bangkok (GMT +7)</option>
    <option value='8'>Hong Kong (GMT +8)</option>
    <option value='9'>Tokyo (GMT +9)</option>
    <option value='10'>Sydney (GMT +10)</option>
    <option value='11'>Magadan (GMT +11)</option>
    <option value='12'>Wellington (GMT +12)</option>
</select><br><br>

 <?=_CITY ?>: <br><input type="text" name="city" /><br><br>
 <?=_STREET ?>: <br><input type="text" name="adress" id="adress" /><br><br>
 
 <?=_ZIP ?>: <br><input type="text" name="zip" /><br><br>
 
 <?=_PHONE ?>: <br><input type="text" name="phone" /><br><br>
 <?=_MPHONE ?>: <br><input type="text" name="mobile" /><br><br> 
 <input type="hidden" name="register" id="register" value="">
 <?=_FAX ?>: <br><input type="text" name="fax" /><br><br> 
 <input type="button" value="OK" onclick="perevirka();" /> 
</form>

<?php
    break;
}

?>


Danke schonmal
 
Meine Vermutung Sind Register globals off oder on
eventuel $_GET['task'] in das formular als hidden field.
und so per switch überprüfen

Weil ich sehe nicht wo $task eingebunden bzw übergeben wird,
das man es auswerten kann.
 
Zuletzt bearbeitet:
Ohne mir den Code genauer angeschaut zu haben, empfehle ich Dir bei solchen Problem von Debug-Ausgaben (sofern Du keinen Debugger bereits in Deiner Entwicklungsumgebung benutzt).

Im Prinzip ähnlich zu dem was Du im Case-Zweig "save" gemacht hast. Wenn Du keine Ausgabe als auch keinen erfolgreichen INSERT in die Datenbank hin bekommst, kippt das Skript schon vorher um. Um die Stelle zu finden, setze ein paar gezielte echo 's um zu schauen wie weit das Skript kommt.

Außerdem solltest Du Dir abgewöhnen, Super-Globals ($_REQUEST, $_GET, $_POST) ungeprüft in Deine SQL Queries zu übernehmen -> Stichwort SQL Injection
 
Hallo nochmal,

also ich hab das Skript mal umgeschrieben (anhand einiger Tutorials) und komme trotzdem nicht weiter.:

PHP:
<form name="register_cus" action="<?=$sysConfig_live_site ?>/register_cus.php?try=true" method="POST">
 <?=_LOGIN ?>: <br><input type="text" name="login" id="login" />&nbsp;*<br><br> 
 <?=_PASSWORD ?>: <br><input type="password" name="password" id="password" />&nbsp;*<br><br> 
 <?=_PASSWORD_CONFIRM ?>: <br><input type="password" name="password2" id="password2" />&nbsp;*<br><br> 
 <?=_EMAIL ?>: <br><input type="text" name="email" id="email" />&nbsp;*<br><br>
 <?=_FNAME ?>: <br><input type="text" name="first_name"  id="first_name"/>&nbsp;*<br><br>
 <?=_LNAME ?>: <br><input type="text" name="last_name" id="last_name" />&nbsp;*<br><br>
 <?=_COMPANY ?>: <br><input type="text" name="company" /><br><br>
 <?=_POSITION ?>: <br><input type="text" name="position" /><br><br>
 <!--<?=_ADRESS ?>: <br><textarea name="adress"></textarea><br><br>-->
 <?=_COUNTRIES ?>:<br>
 <select name="countries" style="width:120px;">
  <?php
    $countries=get_countries();
    for ($i=0; $i<count($countries); $i++)
     {
        echo "<option value='".$countries[$i]['id_countri']."'>".$countries[$i]['country_eng']."</option>";
     }
  ?>
 </select><br><br>
 
 
 <?=_TIMEZONE ?>:<br>
 <select name='timezone' id='timezone' style='width:120px;'>
    <option value='-12'>Eniwetok (GMT-12)</option>
    <option value='-11'>Samoa (GMT-11)</option>
    <option value='-10'>Hawaii (GMT-10)</option>
    <option value='-9'>Alaska (GMT-9)</option>
    <option value='-8'>Pacific Time (GMT-8)</option>
    <option value='-7'>Mountain Time (GMT-7)</option>
    <option value='-6'>Central Time (GMT-6)</option>
    <option value='-5'>Eastern Time (GMT-5)</option>
    <option value='-4'>Atlantic Time (GMT-4)</option>
    <option value='-3'>Brazilia (GMT-3)</option>
    <option value='-2'>Mid-Atlantic (GMT-2)</option>
    <option value='-1'>Azores (GMT-1)</option>
    <option value='0'>Greenwich Mean Time (GMT)</option>
    <option value='1'>Rome (GMT +1)</option>
    <option value='2'>Israel (GMT +2)</option>
    <option value='3'>Moscow (GMT +3)</option>
    <option value='4'>Baku (GMT +4)</option>
    <option value='5'>New Delhi (GMT +5)</option>
    <option value='6'>Dhakar (GMT +6)</option>
    <option value='7'>Bangkok (GMT +7)</option>
    <option value='8'>Hong Kong (GMT +8)</option>
    <option value='9'>Tokyo (GMT +9)</option>
    <option value='10'>Sydney (GMT +10)</option>
    <option value='11'>Magadan (GMT +11)</option>
    <option value='12'>Wellington (GMT +12)</option>
</select><br><br>

 <?=_CITY ?>: <br><input type="text" name="city" /><br><br>
 <?=_STREET ?>: <br><input type="text" name="adress" id="adress" /><br><br>
 
 <?=_ZIP ?>: <br><input type="text" name="zip" /><br><br>
 
 <?=_PHONE ?>: <br><input type="text" name="phone" /><br><br>
 <?=_MPHONE ?>: <br><input type="text" name="mobile" /><br><br> 
 <?=_FAX ?>: <br><input type="text" name="fax" /><br><br> 
 <input type="submit" value="register" /> 
</form>

<?php


mysql_connect($sysConfig_host, $sysConfig_db_user, $sysConfig_db_password) or die ("Can`t connect to DB");
mysql_select_db($sysConfig_db) or die ("Can`t select DB `$sysConfig_db`");
// If ?=true in the url?

if (isset($_GET['try'])) {

        if(empty($_POST['login']) OR 
            empty($_POST['password']) OR 
            empty($_POST['password2'])    OR
            empty($_POST['email']) OR 
            empty($_POST['first_name'])    OR 
            empty($_POST['last_name'])            ) {

            echo 'You haven\'t filled in all the fields. Please do it again.';
}
else {

    $username = mysql_real_escape_string($_POST['login']);
    $password = MD5($_POST['password']);
    $email = mysql_real_escape_string($_POST['email']);
    $f_name=$_POST['first_name'];
    $l_name=$_POST['last_name'];
    $company=$_POST['company'];
    $position=$_POST['position'];
    $adress=$_POST['adress'];
    $zip=$_POST['zip'];
    $city=$_POST['city'];
    $phone=$_POST['phone'];
    $mobile=$_POST['mobile'];
    $fax=$_POST['fax'];
    $timezone=$_POST['timezone'];
    $countries=$_POST['countries'];



$query = mysql_query("SELECT COUNT(id) FROM users 
   WHERE username = '" . $username . "' 
   OR email = '" . $email . "' ") or die(mysql_error());

    list($count) = mysql_fetch_row($query);
 
        if($count == 0) {

     
 mysql_query("
  INSERT INTO `users` ( `user_id` , `user_group`, `login`, `password`, `email` ) VALUES ( '$id', '2', '$login', '$pass', '$email')
 ")or die(mysql_error());


 mysql_query("
  INSERT INTO `customers` ( `customer_id` , `first_name` , `last_name` , `company` , `position` , `adress` , `zip` , `city`, `phone`, `mobile`, `fax`, `timezone` , `country` )
  VALUES ( '$id', '$f_name', '$l_name', '$company', '$position', '$adress', '$zip', '$city', '$phone', '$mobile', '$fax' , '$timezone' , '$countries'
  )
 ");
 
    echo 'You are successfully registered!';
} else {
 
            // Username or Email already taken
            echo 'Username or Email address already taken!';
 
        }

    
}
}

 
 
?>



nur funktioniert (denke aufgrund der .htaccess) das nicht...

htaccess:

RewriteEngine On
RewriteBase /


RewriteCond %{SCRIPT_FILENAME} !^.*\.(css|gif|jpg|jpeg|js)$ [NC]
RewriteRule ^(/*) index.php



Was kann ich da ändern damit das funktioniert
 
Zurück