Tasnim Azam
Tasnim Azam

Reputation: 45

Auto populate data from mysql database and insert into a new table

Hello I want to auto populate my data from database. Its works fine but I got an error which is "Notice: Undefined index: search in C:\xampp\htdocs\diu\Payments_Entry.php on line 37.

Any suggestion? Please help me out to solve this problem.. I tried but I didnt get any solution. Help needed.

Here is my code `

<?php

    require("connection/connect.php");

    $search=$_POST['search'];

    $data = 'SELECT * FROM `stu_tbl` WHERE `reg` = "'.$search.'"';
    $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
    $datas = mysql_fetch_array($query);

?>

<form name="form" method="POST" action="">
    <input type="text" class="form-control" name="search" placeholder="Search" title="Enter name for search " class="search" autocomplete="off"/>
    <button type="submit" class="btn btn-primary"name="btnsearch" value="submit" />Search</button>
</form>



<!-- form to display record from database -->

<form name="form" method="POST" name="btn_sub">
    Name: <input type="text"  name="s_name" value="<?php echo $datas['s_name']?>"/> <br>
    Reg: <input class="form-control" type="text"  name="reg" value="<?php echo $search ?>"/> <br>
    Faculty: <input type="text"  name="factxt" value="<?php echo $datas['program']?>"/><br><br>
    <input type="hidden" name="stu_id" value="<?php echo $datas['stu_id']?>"> 
    Semester: <select name="semtxt" class="form-control">
        <option selected="">Select</option>
        <option>1st</option>
        <option>2nd</option>
        <option>3rd</option>
        <option>4th</option>
        <option>5th</option>
        <option>6th</option>
        <option>7th</option>
        <option>8th</option>
        <option>9th</option>
        <option>10th</option>
        <option>11th</option>
        <option>12th</option>
    </select><br>
    Payment Category: <select name="papytxt" id="textbox" class="form-control">
        <option>Select</option>
        <?php
            $subject=mysql_query("SELECT * FROM payment");
            while ($row=mysql_fetch_array($subject)) {
                if($row['payment_name']==$rs_upd['payment_name'])
                    $iselect="selected";
                else
                    $iselect="";
        ?>
                <option value="<?php echo $row['payment_name'];?>" <?php echo $iselect ;?> >
                    <?php echo $row['payment_name'];?>
                </option>
        <?php      
            }
        ?>
    </select><br>
    Total Pay:  <input type="text" name="tptxt"><br>
    <input type="submit"  value="submit" name="btn_sub"><br>
</form>

<?php

if (isset($_POST['btn_sub'])) {
    $stu_id=$_POST['stu_id'];
    $semester=$_POST['semtxt'];
    $s_name=$_POST['s_name'];
    $reg=$_POST['reg'];
    $fa_name=$_POST['factxt'];
    $pay_name=$_POST['papytxt'];
    $totalpay=$_POST['tptxt'];

    $data = "INSERT INTO payment_all 
               VALUES(
                 NULL,
                 '$stu_id',
                 '$semester',
                 '$s_name',
                 '$reg',
                 '$fa_name' ,
                 '$pay_name',
                 '$totalpay'
               )";

    $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());


}

?>


</body>

</html>`

Upvotes: 0

Views: 975

Answers (2)

GrumpyToaster
GrumpyToaster

Reputation: 335

I don't see anything near line 37 that could throw the error. However your line that says:

$search=$_POST['search'];

Should say:

$search = (isset($_POST['search']) ? $_POST['search'] : '');

Doing that should prevent your error.

Upvotes: 2

Cody
Cody

Reputation: 2649

You need to this $search=$_POST['search']; line in if statement so that php tries to access after form has been submitted

E.g

if(isset($_POST['submit']))
{
   // now apply your business logic here
}

Upvotes: 0

Related Questions