Моля помогнете ми с този if

C++ JAVA
Post Reply
lqbo123
Турист
Турист
Posts: 265
Joined: Mon Nov 30, 2009 6:19 pm

Моля помогнете ми с този if

Post by lqbo123 » Tue Jun 22, 2010 9:11 pm

Здравйете вижте сега като напиша този if

Code: Select all

if($user == NULL && $pass == NULL) {
       echo "0";
      }
Като остава user празно ми изписва 0 но като е попълнено и $пасс е празно не ми показва 0 а трябва защо какво бъркам ?

User avatar
MontefuckeR
Шаман
Шаман
Posts: 3783
Joined: Tue Mar 20, 2007 5:26 pm
Answers: 158

Post by MontefuckeR » Tue Jun 22, 2010 9:13 pm

if($user == NULL || $pass == NULL) {
echo "0";
}

когато едно от полетата е празно ще покаже 0, ти беше написал, ако и двете полета са празни тогава да покаже 0.

lqbo123
Турист
Турист
Posts: 265
Joined: Mon Nov 30, 2009 6:19 pm

Post by lqbo123 » Tue Jun 22, 2010 9:32 pm

пак не става като паролата е празна пак не показва нищо ето целият код

Code: Select all

<form action='register.php' method='post'><table><tbody>
        <tr><td>Потребителско име </td><td><input type='text' name='user' value='$_POST&#91;user&#93;' /></td></tr>
        <tr><td>Парола </td><td><input type='password' name='pass' value='$_POST&#91;pass&#93;' /></td></tr>
        <tr><td>Повтори паролата </td><td><input type='password' name='pass2' value='$_POST&#91;pass2&#93;' /></td></tr>
        <tr><td>Е-майл </td><td><input type='text' name='email' value='$_POST&#91;email&#93;' /></td></tr>
        <tr><td>Адрес 1 </td><td><input type='text' name='adress1' value='$_POST&#91;adress1&#93;' /></td></tr>
        <tr><td>Адрес 2 </td><td><input type='text' name='adress2' value='$_POST&#91;adress2&#93;' /></td></tr>
        <tr><td>Трите имена </td><td><input type='text' name='three_names' value='$_POST&#91;three_names&#93;' /></td></tr>
        <tr><td>Рожденна дата </td><td>
            <select name='otdo'>
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option>
<option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option>
<option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option>
<option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option>
<option>29</option><option>30</option><option>31</option>
            </select>

            <select name='mesec'>
<option>1</option><option>2</option><option>3</option><option>4</option>5<option>6</option>7<option>8</option>9<option>10</option><option>11</option>
<option>12</option>
            </select>

            <select name='year'>
<option>1970</option><option>1971</option><option>1972</option><option>1973</option><option>1974</option><option>1975</option><option>1976</option>
<option>1977</option><option>1978</option><option>1979</option><option>1980</option><option>1981</option><option>1982</option><option>1983</option>
<option>1984</option><option>1985</option><option>1986</option><option>1987</option><option>1988</option><option>1989</option><option>1990</option>
<option>1991</option><option>1992</option><option>1993</option><option>1994</option><option>1995</option><option>1996</option><option>1997</option>
<option>1998</option><option>1999</option><option>2000</option><option>2001</option><option>2002</option><option>2003</option><option>2004</option>
<option>2005</option><option>2006</option><option>2007</option><option>2008</option><option>2009</option><option>2010</option>
        </select></td></tr>

    <tr><td>Град </td><td><input type='text' name='grad' value='$_POST&#91;grad&#93;' /></td></tr>
    <tr><td><input type='submit' name='register' value='Регистрирай Ме' /></td><td><input type='reset' value='Изчисти' /></td></tr>
    </tbody></table></form</p>";

    if&#40;$_POST&#91;'register'&#93;&#41; &#123;
      echo "<div id='error'>";

      $user = htmlspecialchars&#40;trim&#40;$_POST&#91;'user'&#93;&#41;&#41;;
      $pass = md5&#40;$_POST&#91;'pass'&#93;&#41;;
      $pass2 = md5&#40;$_POST&#91;'pass2'&#93;&#41;;
      $email = trim&#40;$_POST&#91;'email'&#93;&#41;;
      $adress1 = htmlspecialchars&#40;trim&#40;$_POST&#91;'adress1'&#93;&#41;&#41;;
      $adress2 = htmlspecialchars&#40;trim&#40;$_POST&#91;'adress2'&#93;&#41;&#41;;
      $three_names = htmlspecialchars&#40;trim&#40;$_POST&#91;'three_names'&#93;&#41;&#41;;
      $roj_dana = $_POST&#91;'otdo'&#93;."-".$_POST&#91;'mesec'&#93;."-".$_POST&#91;'year'&#93;;
      $grad = htmlspecialchars&#40;trim&#40;$_POST&#91;'grad'&#93;&#41;&#41;;

      if&#40;$user == NULL || $pass == NULL&#41; &#123;
       echo "0";
      &#125;

User avatar
kulov
Потребител
Потребител
Posts: 1156
Joined: Sat Apr 03, 2010 1:08 pm
Answers: 133

Post by kulov » Tue Jun 22, 2010 9:56 pm

Code: Select all

 <form action='register.php' method='post'><table><tbody>
        <tr><td>Потребителско име </td><td><input type='text' name='user' value='$_POST&#91;user&#93;' /></td></tr>
        <tr><td>Парола </td><td><input type='password' name='pass' value='$_POST&#91;pass&#93;' /></td></tr>
        <tr><td>Повтори паролата </td><td><input type='password' name='pass2' value='$_POST&#91;pass2&#93;' /></td></tr>
        <tr><td>Е-майл </td><td><input type='text' name='email' value='$_POST&#91;email&#93;' /></td></tr>
        <tr><td>Адрес 1 </td><td><input type='text' name='adress1' value='$_POST&#91;adress1&#93;' /></td></tr>
        <tr><td>Адрес 2 </td><td><input type='text' name='adress2' value='$_POST&#91;adress2&#93;' /></td></tr>
        <tr><td>Трите имена </td><td><input type='text' name='three_names' value='$_POST&#91;three_names&#93;' /></td></tr>
        <tr><td>Рожденна дата </td><td>
            <select name='otdo'>
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option>
<option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option>
<option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option>
<option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option>
<option>29</option><option>30</option><option>31</option>
            </select>

            <select name='mesec'>
<option>1</option><option>2</option><option>3</option><option>4</option>5<option>6</option>7<option>8</option>9<option>10</option><option>11</option>
<option>12</option>
            </select>

            <select name='year'>
<option>1970</option><option>1971</option><option>1972</option><option>1973</option><option>1974</option><option>1975</option><option>1976</option>
<option>1977</option><option>1978</option><option>1979</option><option>1980</option><option>1981</option><option>1982</option><option>1983</option>
<option>1984</option><option>1985</option><option>1986</option><option>1987</option><option>1988</option><option>1989</option><option>1990</option>
<option>1991</option><option>1992</option><option>1993</option><option>1994</option><option>1995</option><option>1996</option><option>1997</option>
<option>1998</option><option>1999</option><option>2000</option><option>2001</option><option>2002</option><option>2003</option><option>2004</option>
<option>2005</option><option>2006</option><option>2007</option><option>2008</option><option>2009</option><option>2010</option>
        </select></td></tr>

    <tr><td>Град </td><td><input type='text' name='grad' value='$_POST&#91;grad&#93;' /></td></tr>
    <tr><td><input type='submit' name='register' value='Регистрирай Ме' /></td><td><input type='reset' value='Изчисти' /></td></tr>
    </tbody></table></form</p>";

    if&#40;$_POST&#91;'register'&#93;&#41; &#123;
      echo "<div id='error'>";

      $user = htmlspecialchars&#40;trim&#40;$_POST&#91;'user'&#93;&#41;&#41;;
      $pass = md5&#40;$_POST&#91;'pass'&#93;&#41;;
      $pass2 = md5&#40;$_POST&#91;'pass2'&#93;&#41;;
      $email = trim&#40;$_POST&#91;'email'&#93;&#41;;
      $adress1 = htmlspecialchars&#40;trim&#40;$_POST&#91;'adress1'&#93;&#41;&#41;;
      $adress2 = htmlspecialchars&#40;trim&#40;$_POST&#91;'adress2'&#93;&#41;&#41;;
      $three_names = htmlspecialchars&#40;trim&#40;$_POST&#91;'three_names'&#93;&#41;&#41;;
      $roj_dana = $_POST&#91;'otdo'&#93;."-".$_POST&#91;'mesec'&#93;."-".$_POST&#91;'year'&#93;;
      $grad = htmlspecialchars&#40;trim&#40;$_POST&#91;'grad'&#93;&#41;&#41;;

      if&#40;empty&#40;$user&#41; || empty&#40;$pass&#41;&#41; &#123;
       echo "0";
      &#125;

lqbo123
Турист
Турист
Posts: 265
Joined: Mon Nov 30, 2009 6:19 pm

Post by lqbo123 » Tue Jun 22, 2010 10:09 pm

пак не става ?

User avatar
kulov
Потребител
Потребител
Posts: 1156
Joined: Sat Apr 03, 2010 1:08 pm
Answers: 133

Post by kulov » Tue Jun 22, 2010 10:13 pm

Защо всяко поле има стойност $_POST ?

Code: Select all

<form action='register.php' method='post'><table><tbody>
        <tr><td>Потребителско име </td><td><input type='text' name='user' value='' /></td></tr>
        <tr><td>Парола </td><td><input type='password' name='pass' value='' /></td></tr>
        <tr><td>Повтори паролата </td><td><input type='password' name='pass2' value='' /></td></tr>
        <tr><td>Е-майл </td><td><input type='text' name='email' value='' /></td></tr>
        <tr><td>Адрес 1 </td><td><input type='text' name='adress1' value='' /></td></tr>
        <tr><td>Адрес 2 </td><td><input type='text' name='adress2' value='' /></td></tr>
        <tr><td>Трите имена </td><td><input type='text' name='three_names' value='' /></td></tr>
        <tr><td>Рожденна дата </td><td>
            <select name='otdo'>
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option>
<option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option>
<option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option>
<option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option>
<option>29</option><option>30</option><option>31</option>
            </select>

            <select name='mesec'>
<option>1</option><option>2</option><option>3</option><option>4</option>5<option>6</option>7<option>8</option>9<option>10</option><option>11</option>
<option>12</option>
            </select>

            <select name='year'>
<option>1970</option><option>1971</option><option>1972</option><option>1973</option><option>1974</option><option>1975</option><option>1976</option>
<option>1977</option><option>1978</option><option>1979</option><option>1980</option><option>1981</option><option>1982</option><option>1983</option>
<option>1984</option><option>1985</option><option>1986</option><option>1987</option><option>1988</option><option>1989</option><option>1990</option>
<option>1991</option><option>1992</option><option>1993</option><option>1994</option><option>1995</option><option>1996</option><option>1997</option>
<option>1998</option><option>1999</option><option>2000</option><option>2001</option><option>2002</option><option>2003</option><option>2004</option>
<option>2005</option><option>2006</option><option>2007</option><option>2008</option><option>2009</option><option>2010</option>
        </select></td></tr>

    <tr><td>Град </td><td><input type='text' name='grad' value='' /></td></tr>
    <tr><td><input type='submit' name='register' value='Регистрирай Ме' /></td><td><input type='reset' value='Изчисти' /></td></tr>
    </tbody></table></form</p>";

    if&#40;isset&#40;$_POST&#91;'register'&#93;&#41;&#41; &#123;
      echo "<div id='error'>";

      $user = htmlspecialchars&#40;trim&#40;$_POST&#91;'user'&#93;&#41;&#41;;
      $pass = md5&#40;$_POST&#91;'pass'&#93;&#41;;
      $pass2 = md5&#40;$_POST&#91;'pass2'&#93;&#41;;
      $email = trim&#40;$_POST&#91;'email'&#93;&#41;;
      $adress1 = htmlspecialchars&#40;trim&#40;$_POST&#91;'adress1'&#93;&#41;&#41;;
      $adress2 = htmlspecialchars&#40;trim&#40;$_POST&#91;'adress2'&#93;&#41;&#41;;
      $three_names = htmlspecialchars&#40;trim&#40;$_POST&#91;'three_names'&#93;&#41;&#41;;
      $roj_dana = $_POST&#91;'otdo'&#93;."-".$_POST&#91;'mesec'&#93;."-".$_POST&#91;'year'&#93;;
      $grad = htmlspecialchars&#40;trim&#40;$_POST&#91;'grad'&#93;&#41;&#41;;

      if&#40;empty&#40;$user&#41; || empty&#40;$pass&#41;&#41; &#123;
       echo "0";
      &#125;	

raiden
Гуру
Гуру
Posts: 2182
Joined: Fri Dec 08, 2006 8:13 am
Answers: 190
Location: Варна

Post by raiden » Tue Jun 22, 2010 11:05 pm

първо проверяваш паролата дали е празна и тогава я минаваш през md5

slideR
Потребител
Потребител
Posts: 1291
Joined: Sat Dec 26, 2009 6:37 pm
Answers: 117

Post by slideR » Wed Jun 23, 2010 6:08 am

Да паролата дори и да е празна пак се обръща в md5. Затова направи каквото ти каза @Raiden

User avatar
heminei
Потребител
Потребител
Posts: 723
Joined: Fri Feb 01, 2008 8:30 pm
Answers: 61
Location: Велико Търново

Post by heminei » Wed Jun 23, 2010 8:52 am

echo"
<form action='register.php' method='post'><table><tbody>
<tr><td>Потребителско име </td><td><input type='text' name='user' value='$_POST[user]' /></td></tr>
<tr><td>Парола </td><td><input type='password' name='pass' value='$_POST[pass]' /></td></tr>
<tr><td>Повтори паролата </td><td><input type='password' name='pass2' value='$_POST[pass2]' /></td></tr>
<tr><td>Е-майл </td><td><input type='text' name='email' value='$_POST[email]' /></td></tr>
<tr><td>Адрес 1 </td><td><input type='text' name='adress1' value='$_POST[adress1]' /></td></tr>
<tr><td>Адрес 2 </td><td><input type='text' name='adress2' value='$_POST[adress2]' /></td></tr>
<tr><td>Трите имена </td><td><input type='text' name='three_names' value='$_POST[three_names]' /></td></tr>
<tr><td>Рожденна дата </td><td>
<select name='otdo'>
<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option>
<option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option>
<option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option>
<option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option>
<option>29</option><option>30</option><option>31</option>
</select>

<select name='mesec'>
<option>1</option><option>2</option><option>3</option><option>4</option>5<option>6</option>7<option>8</option>9<option>10</option><option>11</option>
<option>12</option>
</select>

<select name='year'>
<option>1970</option><option>1971</option><option>1972</option><option>1973</option><option>1974</option><option>1975</option><option>1976</option>
<option>1977</option><option>1978</option><option>1979</option><option>1980</option><option>1981</option><option>1982</option><option>1983</option>
<option>1984</option><option>1985</option><option>1986</option><option>1987</option><option>1988</option><option>1989</option><option>1990</option>
<option>1991</option><option>1992</option><option>1993</option><option>1994</option><option>1995</option><option>1996</option><option>1997</option>
<option>1998</option><option>1999</option><option>2000</option><option>2001</option><option>2002</option><option>2003</option><option>2004</option>
<option>2005</option><option>2006</option><option>2007</option><option>2008</option><option>2009</option><option>2010</option>
</select></td></tr>

<tr><td>Град </td><td><input type='text' name='grad' value='$_POST[grad]' /></td></tr>
<tr><td><input type='submit' name='register' value='Регистрирай Ме' /></td><td><input type='reset' value='Изчисти' /></td></tr>
</tbody></table></form</p>";

if($_POST['register']) {
echo "<div id='error'>";

$user = htmlspecialchars(trim($_POST['user']));
$pass = $_POST['pass'];
$pass2 = $_POST['pass2'];
$email = trim($_POST['email']);
$adress1 = htmlspecialchars(trim($_POST['adress1']));
$adress2 = htmlspecialchars(trim($_POST['adress2']));
$three_names = htmlspecialchars(trim($_POST['three_names']));
$roj_dana = $_POST['otdo']."-".$_POST['mesec']."-".$_POST['year'];
$grad = htmlspecialchars(trim($_POST['grad']));

if($user==NULL || $pass==NULL)
{
echo "0";
}
else
{
$pass = md5($_POST['pass']);
$pass2 = md5($_POST['pass2']);
}

Това е кода, като съм го променил както каза @raiden :)

lqbo123
Турист
Турист
Posts: 265
Joined: Mon Nov 30, 2009 6:19 pm

Post by lqbo123 » Wed Jun 23, 2010 9:14 am

мерси @raiden а на въпроса защо всеки инпоут има $_POST това съм го направил да не се губи информация като дадена някаква грешка да не се губи написаното от потребителите :)

Post Reply