Hi, my problem is that I can't insert the value of $branch to my database, because it returns a null value.
I'm still new to PHP and only started using it a couple of days ago, I still don't get much of the functions.

Here's my whole code:

$user = $_SESSION["login_User"];

$result = mysql_query("SELECT * FROM tblaccount WHERE Username='$user'");
        while($row = mysql_fetch_assoc($result))

    //$encodr=$row['FirstName'] . " " . $row['LastName'];

    include "configdb.php";
    $dat=date("F d, Y");
    $b = time (); 
    $tim= date("g:i:s A", $b);

    $result = mysql_query("SELECT * FROM tblproducts WHERE ProdCode='$prodCode' AND Branch='$branch'");

        if($count > 0)
        { header('Location: prodAddErr.php'); 
          $msgs = "There is already an existing record!"; 
            $query="INSERT INTO tblproducts(ProdCode,Brand,ProductName,Category,Quantity,Unit,

            $result = mysql_query($query) or die ("Cannot Execute Query!");
            header('Location: prodAdded.php');


and why is it that when I do this code:

$user = $_SESSION["login_User"];

$connect = mysql_connect("localhost","root","") or die("Couldn't connect to database!");
    mysql_select_db("inventory") or die("Couldn't find database!!");
        $result = mysql_query("SELECT * FROM tblaccount WHERE Username='$user'");
        while($row = mysql_fetch_assoc($result))
        echo $row['FirstName'];
        print " ";
        echo $row['LastName'];
        print "<br/> ";
        echo $row['Branch'];

I get the desired output i want. It really prints the record under those fieldnames, so why is it that it doesn't work when I pass the value to another variable?

thanks in advance for helping me :)

Recommended Answers

All 3 Replies

In your first code snippet there's no DB connection before line 6, where you run your first query.

omg! -_- so simple yet I overlook it. wew, thank you so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.