0

hello there,
i have a purchase requisition table in mysql like below:

pr no qty items
1 10 pencil
1 5 ballpen
1 8 eraser

I would like to display them in tabular form and eventually the users should be able to edit.
But my program does not assign the three records to array. Below is my program

`

<?php

    session_start();


    include('Connection.php');

        if( isset($_GET['edit']) )
    {
        $prno = $_GET['edit'];
        $res= mysql_query("SELECT * FROM prdetails WHERE prno='$prno'");
        $row= mysql_fetch_array($res);

        $count=mysql_num_rows($res);


        //echo $count;

        $array=array();
    $i=0;
    while($count+1>$i)
    {



        $array[$i]=$row['quantity'];

        //echo $array[$i];
        //echo $i;

        $i++;
    }
    echo $array[0];
    echo $array[1];



    /*  $array=array();

        foreach($row as $id => $row[0])
        {
            $array[$id]=$row[$id];


            echo " ".$row[3];
        }
        */
    }

    mysql_close($con);

    if(isset($_POST['btnUpdate']))
    {
        include_once("MainClass.php");
        $MainClass= new MainClass;


    }

    if(isset($_POST['btnBack']))
    {
        header('Location:.php');
    }


?>
<form action="createPo.php" method="POST">

<?php
echo "Pr number:".$row[0];
echo "<br/>";
echo "Item:".$row[2];
echo "<br/>";

echo "Quantity:".$row[3];
echo "<br/>";

include_once("MainClass.php");
    $MainClass= new MainClass;

echo "Supplier:";
echo $MainClass -> assignSupplier(); 

echo "<br>";

?>

</select>
<input type="hidden" name="prno" value="<?php echo $row[0];?>" ?/>
<input type="submit" name="btnUpdate"value=" Create Po "/>
<input type="submit" name="btnBack"value=" Back "/>

</form>

`

3
Contributors
2
Replies
26
Views
1 Year
Discussion Span
Last Post by diafol
0

Are you getting any error messages or output you don't expect?
First step is to make sure you're getting something back from your query and then step through from there.
I did notice in your explanatory table you had 'qty' but in your code you use 'quantity' - do the column names match what is in the database?

0
session_start();
//*** you're using mysql_* functions - please don't - they're deprecated ***//
include('Connection.php');

if( isset($_GET['edit']) )
{
    $prno = $_GET['edit'];
    //*** you have just opened the door to SQL injection ***//
    //*** also looks like only max one record retrieved - so use "LIMIT 1" at the end ***//
    //*** you'd be better using a PDO or mysqli prepared statement ***//
    $res= mysql_query("SELECT * FROM prdetails WHERE prno='$prno'");

    //*** this is a little ham-fisted ***//
    $row= mysql_fetch_array($res);
    $count=mysql_num_rows($res);

    //***
    //echo $count;
    $array=array();
    $i=0;
    while($count+1>$i)
    {
        $array[$i]=$row['quantity'];
        //echo $array[$i];
        //echo $i;
        $i++;
    }
    echo $array[0];
    echo $array[1];
    /*  $array=array();
        foreach($row as $id => $row[0])
        {
            $array[$id]=$row[$id];
            echo " ".$row[3];
        }
        */
}

mysql_close($con);


if(isset($_POST['btnUpdate']))
{
    include_once("MainClass.php");
    //*** this 't' will cause an error ***//
    $MainClass= new MainClass;'t'
}

if(isset($_POST['btnBack']))
{
    //*** where the hell is this going??? ***//
    header('Location:.php');
}
?>

<!--*** $row will not exist if the form has not been sent already. This will cause an error ***-->

<form action="createPo.php" method="POST">
    <?php
    echo "Pr number:".$row[0];
    echo "<br/>";
    echo "Item:".$row[2];
    echo "<br/>";
    echo "Quantity:".$row[3];
    echo "<br/>";
    include_once("MainClass.php");
    $MainClass= new MainClass;
    echo "Supplier:";
    echo $MainClass -> assignSupplier();
    echo "<br>";
    ?>
    </select>
    <input type="hidden" name="prno" value="<?php echo $row[0];?>" ?/>
    <input type="submit" name="btnUpdate"value=" Create Po "/>
    <input type="submit" name="btnBack"value=" Back "/>
</form>

There are many issues with this code. You may find the tutorial: https://www.daniweb.com/web-development/php/threads/499320/common-issues-with-mysql-and-php useful. Some of the errors could have been picked up by a decent editor / IDE. Get one, it will save you (and us) a lot of time.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.