0

this is my main.php

<?php
session_start();
if (!isset($_SESSION['username']))
    {
        header('Location: index.php');
    }
    include("connection/config.php");
?>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>TOM ELOY CONVENIENCE STORE</title>
    <link rel="stylesheet" href="css/design.css" type="text/css" />
    <link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="css/iconic.css" media="screen" rel="stylesheet" type="text/css" />
    <script></script>
</head>
<body>
<div id="wrapper">

<!--header link -->
<div id="sitename" class="clear">
    <?php include_once("header.php"); ?>
</div>

<!--menu navigation -->
<div class="wrap">
<nav>
    <?php include_once("menunav.php"); ?>
    <div class="clearfix"></div>
</nav>
</div>



<div id="body-wrapper">
    <!-- body -->
    <div id="body" class="clear">
        <div class="clear">
            <div id="content"></div>
                <!-- script for pages -->
                <script type="text/javascript" src="js/general.js"></script>
                <script src="js/main.js"></script>
        </div>      
    </div>
</div>


<!--footer link -->
<div id="footer" align="center">
    <?php include_once("footer.php"); ?>
</div>

</div>
</body>
</html>

this is my javascript the main.js

$(document).ready(function () {

$('#content').load('main2.php');

$('ul#nav li a').click(function() {
    var page = $(this).attr('href');
    $('#content').load( page + '.php');
    return false;
}); 

}); 

this is my supplierprofile.php

<?php
session_start();
if (!isset($_SESSION['username']))
    {
        header('Location: index.php');
    }
    include("connection/config.php");
?><html>
<head>
    <link rel="stylesheet" href="css/styles.css" type="text/css" />

    <!-- autorefresh of the table -->
    <script type="text/javascript">
    function Ajax()
    {
        var
            $http,
            $self = arguments.callee;

        if (window.XMLHttpRequest) {
            $http = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            try {
                $http = new ActiveXObject('Msxml2.XMLHTTP');
            } catch(e) {
                $http = new ActiveXObject('Microsoft.XMLHTTP');
            }
        }

        if ($http) {
            $http.onreadystatechange = function()
            {
                if (/4|^complete$/.test($http.readyState)) {
                    document.getElementById('ReloadThis').innerHTML = $http.responseText;
                    setTimeout(function(){$self();}, 0);
                }
            };
            $http.open('GET', 'supplierprofiletable.php' + '?' + new Date().getTime(), true);
            $http.send(null);
        }

    }
    </script>

</head>

<!-- content2 -->
<div id="content">

        <p id="bcp">Browse Supplier Profile</p><br><br>

                <ul id="nav">        
                    <li>
                        <a id="abutton">PRINT</a>
                        <a id="abutton" href="addspform">ADD SUPPLIER</a>
                    </li>
                </ul>


                <!-- autorefresh of the table -->        
                <script type="text/javascript">
                    setTimeout(function() {Ajax();}, 0);
                </script>
                <!-- table to be refresh -->
                <div  id="ReloadThis"><?php include_once("supplierprofiletable.php"); ?></div>          
</div>  

    <? -- script for pages --?>
    <script type="text/javascript" src="js/general.js"></script>
    <script src="js/submain.js"></script>           

this is the supplieprofiletable.php

<table id="spvt" align="center">
<tr>
    <th id="spvth">SUPPLIER NAME</th>
    <th id="spvth">TERMS DAY</th>
    <th id="spvth">VAT</th>
    <th id="spvth">MODIFY</th>
    <th id="spvth">DELETE</th>
</tr>

<?php
    include("connection/config.php");
    $sql = "select * from SUPPLIER_PROFILE ORDER BY SP_NAME";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
        {
            echo "<tr id='spvtr'>";
            echo "<td id='spvtd' style='text-align:left;'>" . $row['SP_NAME'] . "</td>";
            echo "<td id='spvtd'>" . $row['SP_TERMS_DAY'] . "</td>";
            echo "<td id='spvtd'>" . $row['SP_VAT'] . "</td>";
            echo "<td id='spvtd'><a href =\"spmodifyform.php?id=" . $row['SP_NO'] . "\">MODIFY SUPPLIER</a></td>";
            echo "<td id='spvtd'><a href =\"spdelete.php?id=" . $row['SP_NO'] . "\">DELETE SUPPLIER</a></td>";
            echo "</tr>";
        }
?>                  

this is the addspform.php

<head>
<link rel="stylesheet" href="css/design.css" type="text/css" />
<link href="style.css" media="screen" rel="stylesheet" type="text/css" />
<link href="iconic.css" media="screen" rel="stylesheet" type="text/css" />
<script type = "text/javascript">
    <!--
    var run1 = function()
    {
        var x1 = document.addsp.spname.value.length;
        if(x1 == 0)
        {
            alert("SUPPLIER NAME SHOULD NOT BE EMPTY");
            return(false);
        }
        else 
            return(true);
    }
    var run2 = function()
    {
        var x1 = document.addsp.spadd.value.length;
        if(x1 == 0)
        {
            alert("SUPPLIER ADDRESS SHOULD NOT BE EMPTY");
            return(false);
        }
        else 
            return(true);
    }
    var run3 = function()
    {
        var x1 = document.addsp.sptd.value.length;
        if(x1 == 0)
        {
          alert("SUPPLIER TERMS DAY SHOULD NOT BE EMPTY");
          return(false);
        }
        else
           return(true);
    }
    var run4 = function()
    {
        var x1 = document.addsp.spvat.value.length;
        if(x1 == 0)
        {
          alert("SUPPLIER VAT SHOULD NOT BE EMPTY");
          return(false);
        }
        else
           return(true);
    }

    function checkall()
    {
        if(run1() == false)
        {
            addsp.spname.focus();
            return(false);
        }
        if(run2() == false)
        {
            addsp.spadd.focus();
            return(false);
        }
        if(run3() == false)
        {
            addsp.sptd.focus();
            return(false);
        }
        if(run4() == false)
        {
            addsp.spvat.focus();
            return(false);
        }
        if(/^[0-9]+$/i.test(addsp.sptd.value) == false)
        {
          alert("invalid Terms Day");
          addsp.sptd.focus();
          return(false);
        }
        else
        {

            return(true);
        }
    }
    -->
</script>

</head>
<!-- body -->
<div id="content">
    <div class="clear">
        <p id="bcp">ADD Supplier</p><br><br>

            <ul id="nav">
                <li>
                    <a id="abutton" href="supplierprofile">VIEW SUPPLIER</a>
                </li>
            </ul>
            <br>    
                <form id="aft" name ="addsp" action = "addsp.php" method = "post" onsubmit = "return checkall();">
                    <fieldset>
                    <legend>SUPPLIER FORM (NEW)</legend>
                    <table>
                        <tr><td>
                            <span style = "width: 50px;" >Supplier Name</span> 
                        </td><td>
                            <input size="100" type = "text" name = "spname" onkeyup = "this.value = this.value.toUpperCase();" value =""/><br />
                        </td></tr>
                        <tr><td>
                            <span style = "width: 100px;">Address</span> 
                        </td><td>
                            <input size="100" type = "text" name = "spadd" value = "" /><br />
                        </td></tr>
                        <tr><td>
                            <span style = "width: 120px;">Telephone No.</span> 
                        </td><td>
                            <input size="100" type = "text" name = "sptelno" value = "" /><br />
                        </td></tr>
                        <tr><td>
                            <span style = "width: 100px;">Terms Day</span> 
                        </td><td>
                            <input size="100" type = "text" name = "sptd" value = "" /><br />
                        </td></tr>
                        <tr><td>
                            <span style = "width: 100px;">VAT</span> 
                        </td><td>
                            <select name="spvat">
                            <option id="o1"> </option>
                            <option id="o2">INCLUSIVE</option>
                            <option id="o3">EXCLUSIVE</option>          
                            </select>
                        </td></tr>
                        <tr><td></td><td>
                            <input class="afbutton" type = "submit" name = "ADD" value = "ADD" id="ADD"/>
                        </td></tr>
                        <tr><td>
                    </table>
                    </fieldset>
                </form>

    </div>  
</div>
    <? -- script for pages --?>
    <script type="text/javascript" src="js/general.js"></script>
    <script src="js/submain.js"></script>

this is the addsp.php

<html>
<head>
    <script type="text/javascript">
    <!--
    function direct()
    {
        window.alert("Suppler has been added");
        w = window || document
        w.location.reload();
    }
    -->

    </script>
</head>

<body>
    <?php
                include("connection/config.php");
                $spname = $_POST['spname'];
                $spadd = $_POST['spadd'];
                $sptelno = $_POST['sptelno'];
                $sptd = $_POST['sptd'];
                $spvat = $_POST['spvat'];

                if(!$_POST['ADD'])
                {
                  echo "Please fill out the form";
                  header('Location: addspform.php');
                }
                else
                {
                    $query = "SELECT * FROM supplier_profile WHERE sp_name = '$spname'";

                    $result = mysql_query($query)or die(mysql_error());
                    $counter = 0;
                    while($supplier = mysql_fetch_array($result))
                    {
                        $counter = $counter + 1;
                    }
                    if($counter == 0)
                    {
                      mysql_query("INSERT INTO supplier_profile(`SP_NAME`,`SP_ADDRESS`, `SP_TELNO`,`SP_VAT`,`SP_TERMS_DAY`)
                                   VALUES('$spname','$spadd','$sptelno','$spvat','$sptd')") or die(mysql_error());
                      echo '<script type="text/javascript">
                            direct();
                            </script>';
                    }
                }
    ?>
</body>

sorry about the previous information. Now if i click the add button to the addspform.php all i want after the javascript that pop-up and click ok is to direct the supplierprofile.php inside in the main.php

4 Answers 4

1

make your addsp.php like this

<?php
                session_start();
                include("connection/config.php");
                $spname = $_POST['spname'];
                $spadd = $_POST['spadd'];
                $sptelno = $_POST['sptelno'];
                $sptd = $_POST['sptd'];
                $spvat = $_POST['spvat'];

                if(!$_POST['ADD'])
                {
                  $_SESSION['msg'] = "Please fill form";
                  header('Location: addspform.php');
                  exit;


                }
                else
                {
                    $query = "SELECT * FROM supplier_profile WHERE sp_name = '$spname'";

                    $result = mysql_query($query)or die(mysql_error());
                    $counter = 0;
                    while($supplier = mysql_fetch_array($result))
                    {
                        $counter = $counter + 1;
                    }
                    if($counter == 0)
                    {
                      mysql_query("INSERT INTO supplier_profile(`SP_NAME`,`SP_ADDRESS`, `SP_TELNO`,`SP_VAT`,`SP_TERMS_DAY`)
                                   VALUES('$spname','$spadd','$sptelno','$spvat','$sptd')") or die(mysql_error());
                       $_SESSION['msg'] = "form has been submitted successfully";
                       header('Location: addspform.php');
                       exit;
                    }
                }
    ?>

you can use header function of php to redirect on some page. use session as msg and print it on your form page as follows

<?php
session_start();
if(isset($_SESSION['msg']))
{
    echo $_SESSION['msg'];
     unset($_SESSION['msg']);
}
?>

<form id="aft" name ="addsp" action = "addsp.php" method = "post" onsubmit = "return checkall();">
                    <fieldset>
                    <legend>SUPPLIER FORM (NEW)</legend>
                    <table>
                        <tr><td>
                            <span style = "width: 50px;" >Supplier Name</span> 
                        </td><td>
                            <input size="100" type = "text" name = "spname" onkeyup = "this.value = this.value.toUpperCase();" value =""/><br />
                        </td></tr>
                        <tr><td>
                            <span style = "width: 100px;">Address</span> 
                        </td><td>
                            <input size="100" type = "text" name = "spadd" value = "" /><br />
                        </td></tr>
                        <tr><td>
                            <span style = "width: 120px;">Telephone No.</span> 
                        </td><td>
                            <input size="100" type = "text" name = "sptelno" value = "" /><br />
                        </td></tr>
                        <tr><td>
                            <span style = "width: 100px;">Terms Day</span> 
                        </td><td>
                            <input size="100" type = "text" name = "sptd" value = "" /><br />
                        </td></tr>
                        <tr><td>
                            <span style = "width: 100px;">VAT</span> 
                        </td><td>
                            <select name="spvat">
                            <option id="o1"> </option>
                            <option id="o2">INCLUSIVE</option>
                            <option id="o3">EXCLUSIVE</option>          
                            </select>
                        </td></tr>
                        <tr><td></td><td>
                            <input class="afbutton" type = "submit" name = "ADD" value = "ADD" id="ADD"/>
                        </td></tr>
                        <tr><td>
                    </table>
                    </fieldset>
                </form>
Sign up to request clarification or add additional context in comments.

Comments

1

redefine direct as:

    function direct(){
    window.alert("Suppler has been added");
    w = window || document
    w.location.reload();
}

4 Comments

it actually work but it doesn't load the supplierprofile.php to the <div id="content"></div> in the main.php
you cannot load whole page inside a div unless you create a child iframe tag inside div. create an iframe in "content" div and load supplierprofile.php in that iframe.
but it works..when i click the button to show the addspform.php. it actually load to the div.
is there a way that i can reload the <div>
0

Just do a redirect in addsp.php

if (test){
       //do something
       echo '<META HTTP-EQUIV="Refresh" Content="0; URL=yourpage.php">';//This causes the browser to open the new page after 0 seconds, i.e immediately.
    }  else {
       return false;
    } 

http://php.about.com/od/learnphp/ht/phpredirection.htm

Comments

0
//addsp.php
function direct()
    {
        window.alert("Suppler has been added");
        document.location.href = "main.php?page='pagenamewhichlastloaded'&redirect=1";
    }

//main.php  
$(function(){
    if($("#redirect").val() == 1){
        var page = $("#page").val();
        $('#content').load( page + '.php');
    }
    $('ul#nav li a').click(function() {
        var page = $(this).attr('href');
        $('#content').load( page + '.php');
        return false;
    });
});

<div id="content"></div>
<input type="hidden" id="page" value="<?php if(isset($_POST['page'])){ echo $_POST['page']; }?>" />
<input type="hidden" id="redirect" value="<?php if(isset($_POST['redirect'])){ echo $_POST['redirect']; }?>" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.