I can't open my index.php page after insert php code


 
Thread Tools Search this Thread
Top Forums Web Development I can't open my index.php page after insert php code
# 1  
Old 09-21-2009
Question I can't open my index.php page after insert php code

Hello guys,
Does anyone can help me?
I've just made my simple index.php without any code, but after insert session code to check if any user is authenticated, my index.php doesn't work anymore.
Any fresh eyes could help me to see what and where the code is wrong?
Code:
<?
                    if ($_POST['entrar']=='Entrar!')
                       {
                        @session_start();
                        $result = mysql_query('select log_nome,senha from usuarios where log_nome="'.trim($nome).'";',$conexao);
                        if (mysql_num_rows($result)>0)
                        {
                         $usuSenha = mysql_result($result,0,senha);
                        else
                        {
                         $usuSenha = 'notuser';
                        }
                         if ($result and ($senha==$usuSenha) and ($usuSenha<>'notuser'))
                         {
                          @session_register($nome);
                          echo '<p align="center">';
                          echo '<font style="Tahoma" size=4>';
                          echo $nome.'</font><BR>';
                          echo '<font style="Tahoma" size=2>';
                          echo 'Você está on-line</font>';
                          echo '</p>';
                         }
                         else
                         {
                          echo 'Usuário não autorizado';
                         }
                        }
                        else
                        {
                         echo '<form method="post" name="logar" action="">
                         <font style="Tahoma" size=1>
                               Nome: <input type="text" name="nome" value="" size="15"><BR>
                               Senha: <input type="text" name="senha" value="" size="15"><BR>
                         </font>
                         <p align="center">
                         <input onmouseover=this.style.cursor="hand" type="submit"
                         name="entrar" value="Entrar!" STYLE="border:0; height:18;
                         width=50; background:#E8F3FD">
                         </p>
                               </form>';
                        }
                    ?>

I'll apreciate any kind of help.
Thanks
# 2  
Old 09-21-2009
Where is the file that sets this variable?

Code:
  if ($_POST['entrar']=='Entrar!')

What is 'Entrar!' ?

Maybe you want something like?

Code:
  if ($_POST['entrar'] !='Entrar')

?
# 3  
Old 09-22-2009
Neo,
Thanks for your answer. I guess I´ve forgot to put the entire code.
Well, maybe now, with the entire index.php code it'll become easier to understand.
PHP Code:
<? include "base.php"; ?>
<html>
<head>
<title>Example</title>
</head>
<body>
  <table border="0" width="100%" colspacing = 0>
  <tr>
  <td width = 150>
  <IFRAME  name=banner1 frameborder=0 src="banner1.php" scrolling=no height="110" width="100%">
  Your browser doesn´t support frames
  </IFRAME>
  </td>
   <td bgcolor = "#FFFFC0" align = "center">
   <font style = "Tahoma" color="#0000FF" size = 6>
   Example
   </font>
   </td>
    <td width = 150>
    <IFRAME  name=banner2 frameborder=0 src="banner2.php" scrolling=no height="110" width="100%">
    Your browser doesn´t support frames
    </IFRAME>
    </td>
    </tr>
     <tr>
     <td valign = "top">
     <table border="0" width="100%">
      <tr>
      <td align = "center" bgcolor = "#C0C0FF">
      <font style = "Tahoma" size = 2>Login
      </font>
      </td>
      </tr>
      <tr>
       <td bgcolor = "#D0D0D0">
       <?
       if ($_POST['entrar']=='Entrar!')
       {
        @session_start();
        $result = mysql_query('select log_nome,senha from usuarios where log_nome="'.trim($nome).'";',$conexao);
        if (mysql_num_rows($result)>0)
        {
         $usuSenha = mysql_result($result,0,senha);
        else
        {
         $usuSenha = 'notuser';
        }
         if ($result and ($senha==$usuSenha) and ($usuSenha<>'notuser'))
         {
          @session_register($nome);
          echo '<p >';
          echo '<font style="Tahoma" size=4>';
          echo $nome.'</font><BR>';
          echo '<font style="Tahoma" size=2>';
          echo 'You are on-line</font>';
          echo '</p>';
         }
         else
         {
          echo 'User not authorized';
         }
        }
        else
        {
         echo '<form method="post" name="logar" action=""><font style="Tahoma" size=1>
         Name: <input type="text" name="nome" value="" size="15"><BR>
         Password: <input type="text" name="senha" value="" size="15"><BR>
         </font>
         <p >
         <input onmouseover=this.style.cursor="hand" type="submit" name="entrar" value="Entrar!" STYLE="border:0; height:18; width=50; background:#E8F3FD">
          </p>
          </form>';
         }
         ?>
        </td>
        </tr>
        </table>
        <table border="0" width="100%">
        <tr>
         <td  bgcolor="#C0FFFF">
         <font style="Tahoma" size=2>
         About us
         </font>
         </td>
         </tr>
          <tr>
          <td  bgcolor="#C0FFFF">
          <font style="Tahoma" size=2>
          Talk to us
          </font>
          </td>
          </tr>
           <tr>
           <td  bgcolor="#C0FFFF">
           <font style="Tahoma" size=2>
           Images
           </font>
           </td>
           </tr>
           </table>
           </td>
           <td>
           <IFRAME  name=Display src="quemsomos.php" frameborder=0 scrolling=1 height="280" width="100%">
           Your browser doesn´t support frames
           </IFRAME>
           </td>
           <td valign = "top">
           <table border="0" width="100%">
           <tr>
            <td  bgcolor="#C0C0FF">
            <font style="Tahoma" size=4>
            News
            </font>
            </td>
            </tr>
           <?
           $result = mysql_query('select titulo,conteudo from noticias;',$conexao);
           $quantos = mysql_num_rows($result);
           $i=0;
           for ($i==0; $i<$quantos; $i++)
           {
            echo '<tr><td bgcolor="#C0FFFF">';
            echo '<span style="font-size:8.0pt; font-family:Verdana; color:#000080">';
            echo '<a target= "Display" href="conteudo.php?texto='.mysql_result($result,$i,conteudo).'">';
            echo mysql_result($result,$i,titulo);
            echo '</a></td></tr>';
           }
           ?>
           <tr>
            <td  bgcolor="#C0FFFF">
            <font style="Tahoma" size=2>
            Weather
            </font>
            </td>
            </tr>
             <tr>
             <td  bgcolor="#FFFFDD">
             <font style="Tahoma" size=2>
             Test test test test <BR>
             test test test test <BR>
             test test test test
             </font>
             </td>
            </tr>
           </table>
          </td>
         </tr>
        </table>
      </body>
</html>
PS.: "Entrar!" is the action to perform login. You can consider login=entrar
The exclamation mark before the "=" works?
# 4  
Old 09-23-2009
Your first line has a syntax error.

Do you see it?
# 5  
Old 09-23-2009
Here?
PHP Code:
<? include "base.php"; ?>
But I have this include in my other pages and they work fine.
Now, I don´t know where in the 3 php scripts in my index.php are the mistakes.
My base.php code is this:
PHP Code:
<?
  $conexao = mysql_connect('localhost','root','root') or die (mysql_error());
  mysql_select_db("criandosites");
?>
# 6  
Old 09-25-2009
What are the errors in the web server log files when you run this?
# 7  
Old 09-25-2009
I can´t believe it !!! I´ve just found my stupid mistake!!

Code:
<?
       if ($_POST['entrar']=='Entrar!')
       {
        @session_start();
        $result = mysql_query('select log_nome,senha from usuarios where log_nome="'.trim($nome).'";',$conexao);
        if (mysql_num_rows($result)>0)
        {
         $usuSenha = mysql_result($result,0,senha);
        else
        {
         $usuSenha = 'notuser';
        }
...

Now, look what I´ve forgot to insert or better... finnish !!

Code:
<?
       if ($_POST['entrar']=='Entrar!')
       {
        @session_start();
        $result = mysql_query('select log_nome,senha from usuarios where log_nome="'.trim($nome).'";',$conexao);
        if (mysql_num_rows($result)>0)
        {
         $usuSenha = mysql_result($result,0,senha);
        }
        else
        {
         $usuSenha = 'notuser';
        }
...

I forgot to finnish the code ( { } ).
Anyway, thanks for your patience Neo.
regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test Server - Forum Code Changes for PHP 5.3.10 to PHP 7

Here is some docs of my ongoing work to port this forum PHP code which is running on 5.3.10, to PHP 7. Motivation: Unfortunately, every thing that has a beginning must have an end. PHP 5.6 active support ended January 19, 2017. It will receive security support until December 31, 2018. #1 ... (7 Replies)
Discussion started by: Neo
7 Replies

2. Shell Programming and Scripting

Running php index.php as shell in webpage

so i have a bit of a unique situation. i have an encrypted index.php file that that can't be run the normal way that a web browser would run it. if it is run the normal way, the php script will show only gibberish on the web browser, instead of the actual php code. when run from the command... (8 Replies)
Discussion started by: SkySmart
8 Replies

3. UNIX for Dummies Questions & Answers

Integrating bash script into php (page)

I have written a bash script...now i need to call the script from php page. Can you give me an example to demonstrate how it is done?:( (1 Reply)
Discussion started by: xerox
1 Replies

4. Shell Programming and Scripting

PHP:page.php?id= ????

Hi, i have this script to read from mysql (layout below) and the script will display the course title, and a url to the id, but when i click on the url it just goes back to that page(displaying all the course titles)but when u click on a course title i want it to read from detail table in php and... (1 Reply)
Discussion started by: perleo
1 Replies

5. Shell Programming and Scripting

PHP: problem with index.php

iam geting a error with this index script. heres the error Parse error: parse error in c:\phpdev\www\dev\compulearn\in work\index.php on line 39 Whats wrong?? ------------------------ <?php //display header and left bars include ('header.php'); include ('left.php'); //connect... (13 Replies)
Discussion started by: perleo
13 Replies
Login or Register to Ask a Question