How To update records

Codes here !

Moderators: macek, egami, gesf

psonawane
New php-forum User
New php-forum User
Posts: 2
Joined: Fri Jan 11, 2013 9:21 am

How To update records

Postby psonawane » Fri Jan 11, 2013 9:27 am

Hi all following is my code to update record in a database table. but it gives me following error / notice says:

Notice: Undefined index: price in C:\xampp\htdocs\RK_files\update.php on line 34

Notice: Undefined index: coname in C:\xampp\htdocs\RK_files\update.php on line 35

Notice: Undefined index: destination in C:\xampp\htdocs\RK_files\update.php on line 36


Please Help me! :(

Code: Select all

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link rel="stylesheet" href="main.css" type="text/css">
    </head>
    <body background="media/dark_blue_background-wallpaper-1920x1200.jpg">
    <center>
        <?php
        session_start();
        if ($_SESSION['uname']) {
            ?>   
            <div id="bus">
                <p><img src="media/rk_logo2.png" height="100" width="220"></p>
                <ul>
                    <li style="float: right; padding-right: 10px; font-family: sans-serif; font-weight: bold;">You are Logged in as, <?php echo "" . $_SESSION['uname'] . "!"; ?></li>
                </ul><br>
                <div id="menu">               
                    <ul>
                        <li><a href="add.php">Add Bus and Service</a></li>
                        <li><a href="edit.php">Change Bus and Service</a></li>
                        <li><a href="del.php">Delete Bus and Service</a></li>
                        <li><a href="show.php">View Bus and Service</a></li>                       
                    </ul>               
                </div>
                <?php
            }

            $rate1 = $_POST['price'];
            $company1 = $_POST['coname'];
            $destination1 = $_POST['destination'];
            $connect = mysql_connect("localhost", "root", "pranit");

            if (!$connect) {
                die("could not connect" . mysql_error());
            }
            mysql_select_db("rk_bookings", $connect);

            $query = mysql_query("UPDATE bus_details SET price='$rate1' WHERE company='$company1' AND destination='$destination1'");
           
            if ($query) {
                echo "Records Updated!!!";
            } else {
                echo mysql_error();
            }
           
            mysql_close($connect);
           
            ?>
            </body>
            </html>

onadvance
New php-forum User
New php-forum User
Posts: 5
Joined: Mon Nov 07, 2011 10:36 am

Re: How To update records

Postby onadvance » Tue Jan 22, 2013 12:05 pm

Hi,

I'm not sure it can help you.

The first time you try to upload a POST the server can not recognize it if it's NOT any value in the post.
So
You need to specify, if there is not any value, the POST is empty.
somthing like that:

if(!isset($_POST['price'])) $_POST['price'] = "" ;
if(!isset($_POST['coname'])) $_POST['coname'] = "" ;
if(!isset($_POST['destination'])) $_POST['destination'] = "" ;

You need to have this specification at the top of your page

It hope it helps


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron