www.webdeveloper.com
Results 1 to 2 of 2

Thread: Session Not Working Properly

  1. #1
    Join Date
    Jun 2007
    Posts
    191

    Exclamation Session Not Working Properly

    Can someone let me know if I have something wrong.
    index.php
    PHP Code:
    <?php session_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Call Log</title>
    </head>

    <body>
        <?php
            $error 
    $_SESSION['error'];
            if(
    $error == 1)
                echo 
    "<p>Lead already called.</p>";
            else 
                echo 
    "";
        
    ?>
        <form name='start_call' action='insertlead.php' method='post'>
          <table>
              <tr>
                  <td valign='top'>Company Name<br /><input type='text' name='company' /></td>
                  <td>Company Phone<br /><input type='text' name='phone' /></td>
              </tr>
              <tr>
                  <td><input type='submit' value='Insert Lead' /></td>
              </tr>
          </table>
        </form>
        <p><a href="startcalls.php">Start Calls</a></p>
    </body>
    </html>
    insertlead.php
    PHP Code:
    <?php
            session_start
    ();
            
    $phone $_POST['phone'];
            
    $company $_POST['company'];
            
            
    $phone preg_replace("![^0-9]!"""$phone); 
        
            ** 
    Database Connection **
            
            
    $query "SELECT phone FROM call_log";
            
    $result mysql_query($query)
                or die (
    "Couldn't query data" mysql_error());
            
            
    $row mysql_fetch_array($result);
            
            if(
    $phone == $row['phone']) {
                
    $_SESSION['error'] = 1;
                echo 
    "<script type='text/javascript'>
                <!--
                window.location = 'index.php'
                //-->
                </script>  "
    ;
            }
            else {
                
    mysql_query("INSERT INTO call_log (company, phone) VALUES ('$company', '$phone')");
                echo 
    "<script type='text/javascript'>
                <!--
                window.location = 'index.php'
                //-->
                </script>  "
    ;
            }
    ?>
    The script catches the duplicate phone number but does not set the error.

  2. #2
    Join Date
    Sep 2010
    Location
    England
    Posts
    36
    PHP Code:
    <?php 
            session_start
    (); 
            
    $phone $_POST['phone']; 
            
    $company $_POST['company']; 
             
            
    $phone preg_replace("![^0-9]!"""$phone); 
         
            \** 
    Database Connection **\
             
            
    $query "SELECT phone FROM call_log"
            
    $result mysql_query($query
                or die (
    "Couldn't query data" mysql_error()); 
             
            
    $row mysql_fetch_array($result); 
             
            if(
    $phone == $row['phone']) { 
                
    $_SESSION['error'] = "1"
                
    header("Location: index.php");
                exit();
            } 
            else { 
                
    mysql_query("INSERT INTO call_log (company, phone) VALUES ('$company', '$phone')"); 
                
    header("Location: index.php");
                exit();
            } 
    ?>
    I have changed a few things on insertlead.php try that

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles