Jump to content

badmash

New Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by badmash

  1. i just want that after the updation (changes) it must be store in database , code is below plz help me as soon as possible in this topic

     

     

    <?php

     

    include("connect-db.php");

     

    function renderForm($clientname = '', $address ='', $city = '', $telephoneno ='', $mobileno ='', $email = '', $sno ='', $userid = '')

    { ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    <html>

    <head>

    <title>

    <?php if ($userid != '') { echo "Edit Record"; } else { echo "New Record"; } ?>

    </title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    </head>

    <body>

    <h1><?php if ($userid != '') { echo "Edit Record"; } else { echo "New Record"; } ?></h1>

    <?php if ($error != '') {

    echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error

    . "</div>";

    } ?>

     

    <form action="" method="post">

    <div>

    <?php if ($userid != '') { ?>

    <input type="hidden" name="userid" value="<?php echo $userid; ?>" />

     

    <?php } ?>

     

    <table cellpadding="10" cellspacing="10" width="59%" align="center" border="0">

    <tr>

    <td>Client Name:</td>

    <td><input type="text" name="clientname"

    value="<?php echo $clientname; ?>"/></td>

    </tr>

    <br/>

    <tr>

    <td>Adress:</td>

    <td> <input type="text" name="address"

    value="<?php echo $address; ?>"/></td>

    </tr>

    <tr>

    <td>City:</td>

    <td><input type="text" name="city"

    value="<?php echo $city; ?>"/></td>

    </tr>

    <tr>

    <td>Telephone no:</td>

    <td> <input type="text" name="phoneno"

    value="<?php echo $telephoneno; ?>"/></td>

    </tr>

    <tr>

    <td>Mobile no:</td>

    <td><input type="text" name="mobileno"

    value="<?php echo $mobileno; ?>"/></td>

    </tr>

    <tr>

    <td>Email:</td>

    <td><input type="text" name="email"

    value="<?php echo $email; ?>"/></td>

    </tr>

    <tr>

    <td>Sno:</td>

    <td> <input type="text" name="sno"

    value="<?php echo $sno; ?>"/></td>

    </tr>

    <tr>

    <td></td>

    <td><input type="submit" name="submit" value="Submit" /></td>

    </tr>

    </table>

    </div>

    </form>

    </body>

    </html>

     

    <?php }

     

     

     

    /*

     

    EDIT RECORD

     

    */

    // if the 'id' variable is set in the URL, we know that we need to edit a record

    if (isset($_GET['userid']))

    {

    // if the form's submit button is clicked, we need to process the form

    if (isset($_POST['submit']))

    {

    // make sure the 'id' in the URL is valid

    if (is_numeric($_POST['userid']))

    {

    // get variables from the URL/form

    $userid = $_POST['userid'];

    $clientname = htmlentities($_POST['clientname'], ENT_QUOTES);

    $address = htmlentities($_POST['address'], ENT_QUOTES);

    $city = htmlentities($_POST['city'], ENT_QUOTES);

    $telephoneno = htmlentities($_POST['phoneno'], ENT_QUOTES);

    $mobileno = htmlentities($_POST['mobileno'], ENT_QUOTES);

    $email = htmlentities($_POST['email'], ENT_QUOTES);

    $sno = htmlentities($_POST['sno'], ENT_QUOTES);

     

     

    if ($clientname == '' || $address == '' || $city == '' || $telephoneno == '' || $mobileno == '' || $email == '' || $sno)

    {

    $error = 'ERROR: Please fill in all required fields!';

    renderForm($clientname, $address, $city, $telephoneno, $mobileno, $email, $sno, $error, $userid );

    }

    else

    {

    // if everything is fine, update the record in the database

    if ($stmt = $mysqli->prepare("UPDATE addclient SET clientname=$clientname, address=$address, city=$city, telephoneno=$telephoneno, mobileno=$mobileno, email=$email, sno=$sno WHERE userid=$userid"))

    {

    $stmt->bind_param("ssi", $clientname, $address, $city, $telephoneno, $mobileno, $email, $sno, $userid);

    $stmt->execute();

    $stmt->close();

    }

    // show an error message if the query has an error

    else

    {

    echo "ERROR: could not prepare SQL statement.";

    }

     

     

    header("Location: view.php");

    }

    }

     

    }

    // if the form hasn't been submitted yet, get the info from the database and show the form

    else

    {

    // make sure the 'id' value is valid

    if (is_numeric($_GET['userid']) && $_GET['userid'] > 0)

    {

    // get 'id' from URL

    $userid = $_GET['userid'];

     

    // get the recod from the database

    if($stmt = $mysqli->prepare("SELECT * FROM addclient WHERE userid= ?"))

    {

    $stmt->bind_param("i", $userid);

    $stmt->execute();

     

    $stmt->bind_result($clientname, $address, $city, $telephoneno, $mobileno, $email, $sno,$userid);

    $stmt->fetch();

     

    // show the form

    renderForm($clientname, $address, $city, $telephoneno,$mobileno,$email, $sno, NULL, $userid);

     

    $stmt->close();

    }

    // show an error if the query has an error

    else

    {

    echo "Error: could not prepare SQL statement";

    }

    }

    // if the 'id' value is not valid, redirect the user back to the view.php page

    else

    {

    header("Location: view.php");

    }

    }

    }

     

     

     

    /*

     

    NEW RECORD

     

    */

    // if the 'id' variable is not set in the URL, we must be creating a new record

    else

    {

    // if the form's submit button is clicked, we need to process the form

    if (isset($_POST['submit']))

    {

    // get the form data

    $clientname = htmlentities($_POST['clientname'], ENT_QUOTES);

    $address = htmlentities($_POST['address'], ENT_QUOTES);

    $city = htmlentities($_POST['city'], ENT_QUOTES);

    $telephoneno = htmlentities($_POST['phoneno'], ENT_QUOTES);

    $mobileno = htmlentities($_POST['mobileno'], ENT_QUOTES);

    $email = htmlentities($_POST['email'], ENT_QUOTES);

    $sno = htmlentities($_POST['sno'], ENT_QUOTES);

     

    // check that all fields are not empty

    if ($clientname == '' || $address == '' || $city == '' || $telephoneno == '' || $mobileno == '' || $email == '' || $sno )

    {

    // if they are empty, show an error message and display the form

    $error = 'ERROR: Please fill in all required fields!';

    renderForm($clientname, $address, $city, $telephoneno, $mobileno, $email, $sno, $error);

    }

    else

    {

    // insert the new record into the database

    if ($stmt = $mysqli->prepare("INSERT addclient (clientname, address, city, telephoneno, mobileno, email, sno) VALUES (?, ?, ?, ?, ?, ?, ?) where userid=?"))

    {

    $stmt->bind_param("ss", $clientname, $address, $city, $telephoneno, $mobileno, $email, $sno);

    $stmt->execute();

    $stmt->close();

    }

    // show an error if the query has an error

    else

    {

    echo "ERROR: Could not prepare SQL statement.";

    }

     

    // redirec the user

    header("Location: view.php");

    }

     

    }

    // if the form hasn't been submitted yet, show the form

    else

    {

    renderForm($clientname, $address, $city, $telephoneno, $mobileno, $email, $sno);

    }

    }

     

    // close the mysqli connection

    $mysqli->close();

    ?>

  2. How we use the sqlquery please tell me there was no error in this code but it does not fetch the data from database why ????

    <?php

    $myconnect=mysql_connect("localhost","root","")or die("does not connect to mysql");

    $db=mysql_select_db('billsystem') or die('does not connect to database');

    $result="select clientname from addclient";

    $query=mysql_query($result,$myconnect);

    ?>

    <form action="searchbyclientbillform11.php" method="post" style="margin-left:20px">

    clientname:

    <select name="clientname">

    <?php

    while($res=mysql_fetch_row($query))

    {

    foreach($res as $field)

    {

    //echo $field;

    ?>

    <?php

    //echo$field('month');?>

    <option value="<?php echo $field; ?>"><?php echo $field; ?> </option>

    <?php

    }

    echo"<br>";

     

    //echo $res

    }

    ?>

    </select>

    <input type="submit" name="sub" width="30%" value="show" />

    </form>

    <?php

    $clientname=$_GET['clientname'];

    $myconnect=mysql_connect("localhost","root","")or die("does not connect to mysql");

    $db=mysql_select_db('billsystem')or die("does not connect to database");

    $result="select addclient.userid,addclient.sno,addnewbill.userid,addnewbill.invoiceno,addnewbill.amount,

    addnewbill.date,addnewbill.orderno,addnewbill.descripition,addnewbill.rate,

    monthlystatement.userid,monthlystatement.totalamount,monthlystatement.servicetax

    ,monthlystatement.grandtotal from addclient,addnewbill,

    monthlystatement WHERE addclient.clientname='clientname'";

    $query=mysql_query($result,$myconnect);

    echo "<table border='1'>";

    echo"<tr><th>userid</th><th>Client Name</th><th>SNO</th><th>invoiceno</th><th>amount</th><th>Date</th><th>Orderno</th><th>Descripition</th><th>Rate</th><th>totalamount</th><th>servicetax</th><th>grandtotal </th></tr>";

    while($row=mysql_fetch_row($query))

    {

    // Print out the contents of each row into a table

    echo "<tr>";

    echo "<td>" . $row->userid . "</td>";

    echo "<td>" . $row->clientname . "</td>";

    echo "<td>" . $row->sno . "</td>";

    echo "<td>" . $row->invoiceno . "</td>";

    echo "<td>" . $row->amount . "</td>";

    echo "<td>" . $row->date . "</td>";

    echo "<td>" . $row->orderno . "</td>";

    echo "<td>" . $row->descripition. "</td>";

    echo "<td>" . $row->rate . "</td>";

    echo "<td>" . $row->totalamount . "</td>";

    echo "<td>" . $row->servicetax . "</td>";

    echo "<td>" . $row->grandtotal . "</td>";

    echo "<td><a href='recordshiform.php?userid=" . $row->userid . "'>GO TO FORM</a></td>";

     

    }

    echo"</tr>";

     

    echo "</table>";

     

    ?>

×
×
  • Create New...