We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,610 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion
Page 2 of Article: php session_start
i'm using php 5.4.3, I'm wondering if it's possible to use function session_start(). my idea is to have a login page, then use the username in all pages of the site, the problem is that the $username is not visible in the second page... index.php <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta…

thanks..
i really have a ginormous error..

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Use of undefined constant username - assumed 'username' in C:\wamp\www\sermail db\entrada.php on line 3
Call Stack

Time Memory Function Location

1 0.0005 170280 {main}( ) ..\entrada.php:0

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: username in C:\wamp\www\sermail db\entrada.php on line 3
Call Stack

Time Memory Function Location

1 0.0005 170280 {main}( ) ..\entrada.php:0

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined index: username in C:\wamp\www\sermail db\entrada.php on line 17
Call Stack

Time Memory Function Location

1 0.0005 170280 {main}( ) ..\entrada.php:0

 <?php
session_start();
$_SESSION[username];
    //conecção ao servidor
    $conn = mysql_connect("localhost", "root")or die("sem conecção ao servidor");
    $db = mysql_select_db("sermail")or die("Base de dados não foi encontrada");
    // VAr
    //table ordem
    $data = date("dmY");
    $nordem = $_POST['nordem'];
    $guian = $_POST['guian'];
    $ncliente = $_POST['ncliente'];
    $cliente = $_POST['cliente'];
    $fornecedor = $_POST['fornecedor'];
    $nordem_n = $_POST['nordem'];
    $obs= $_POST['obs'];
    $username= $_POST['username'];

   //$query= "select nordem from ordem where nordem='".$nordem."'"; 
  //  $query1=mysql_query($query);
//    if ($_POST['nordem'] == $query1) include("common.php");
  //      $msg = "Nº. ordem já inserido!";
    //    confirm($msg);;


     $sql="INSERT INTO ordem(data, nordem, fornecedor, guian, ncliente, cliente, obs, username)
    VALUES( '".$data."', '".$nordem."', '".$fornecedor."', '".$guian."', '".$ncliente."', '".$cliente."', '".$obs."', '".$username."')";
    echo "</br>";
    mysql_query ($sql) or die(mysql_error());

    $sql2a = 'INSERT INTO entrada ( nordem_n, lote, val, designacao,filtro, familiamarca, quantguia, quantconf, atado, posicao, codprod) VALUES';
    for ($i=0; $i<count($_POST['check']); $i++) {
     if ($_POST['check'][$i] == 0) continue;
     $sql2a .= '('.$nordem.',\'' . $_POST['lote'][$i] . '\', \'' . $_POST['val'][$i] . '\', \'' . $_POST['designacao'][$i] . '\', \'' . $_POST['filtro'][$i] . '\', \'' . $_POST['familiamarca'][$i] . '\', \'' . $_POST['quantguia'][$i] . '\', \'' . $_POST['quantconf'][$i] . '\', \'' . $_POST['atado'][$i] . '\', \'' . $_POST['posicao'][$i] . '\', \'' . $_POST['codprod'][$i] . '\')';
    if ($i<count($_POST['check']) - 1) {
    $sql2a .= ',';
    } 
    } 

    mysql_query($sql2a) or die(mysql_error());
    // pagina inicial, Furmolario.html
    Echo "<a href='formulario.html'>Nova ficha de entrada</a>";

    ?>
    <?php
    mysql_close();

    ?>

is the code correct? anyway, I will read the code until find the error....

Stardemos
Junior Poster
104 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

No, it's not. You just copied what I mentioned blindly into your code. It was not for use as is, it was just to direct you in the right direction. I suggest you first read the manual.

pritaeas
Posting Prodigy
Moderator
9,533 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,494
Skill Endorsements: 98

actualy, i've read it earlyer, but i have a lot of doubts about it, so much i cannot understand..

Stardemos
Junior Poster
104 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Just a small and brief session 101:

  1. In every script you want to use session, put session_start() at the top, before any output is sent to the browser.

  2. After your user is correctly logged in store it in the session like this: $_SESSION['username'] = $username;

  3. In any other script, where you want to output the session user: echo $_SESSION['username']; or put it back into a variable with: $username = $_SESSION['username'];

The code you put in the above snippet is missing the single/double quotes around usernames, that's why you got the undefined constant notice.

That's it for this thread (for me).

pritaeas
Posting Prodigy
Moderator
9,533 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,494
Skill Endorsements: 98

Thanks, it's much easyer for me (as a noob) to understand this that way.
still get some errors but eventualy, i'll find a way to do it.

Stardemos
Junior Poster
104 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 8 Months Ago by pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.3230 seconds using 2.72MB