psonawane Posted January 12, 2013 Share Posted January 12, 2013 (edited) Hi all am trying to update the database table by submitting a form and used isset (0 function but is shows nothing what can I do? here's my code!!! <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><hr> <?php } $host = "localhost"; $uname = "root"; $pass = "pranit"; $db_name = "rk_bookings"; $tbl_name = "bus_details";[/size][/color][/font] [font="Verdana, Geneva, sans-serif"][color="#333333"][size=3] mysql_connect("$host", "$uname", "$pass") or die("cannot connect"); mysql_select_db("$db_name") or die("cannot select DB");[/size][/color][/font] [font="Verdana, Geneva, sans-serif"][color="#333333"][size=3] $coname = $_POST['coname']; $dest = $_POST['destination']; $sql = "SELECT * FROM $tbl_name WHERE company='$coname' and destination='$dest'"; $result = mysql_query($sql) or die(mysql_error()); $rows = mysql_fetch_array($result, MYSQLI_ASSOC); ?> <div id="disp"> <form action="update.php"> <table> <tr> <th>Company Name</th> <th>Bus Facilities</th> <th>Depart Time</th> <th>Arrival Time</th> </tr> <tr> <td><input type="text" name="coname" value="<?php echo $rows['company']; ?>"></td> <td><input type="text" name="aminities" value="<?php echo $rows['aminities']; ?>"></td> <td><input type="text" name="depart" value="<?php echo $rows['depart']; ?>"></td> <td><input type="text" name="arrive" value="<?php echo $rows['arrive']; ?>"></td> </tr> <tr> <th>Duration</th> <th>Rate</th> <th>From</th> <th>To</th> </tr> <tr> <td><input type="text" name="duration" value="<?php echo $rows['duration']; ?>"></td> <td><input type="text" name="rate" value="<?php echo $rows['price']; ?>"></td> <td><input type="text" name="start" value="<?php echo $rows['start']; ?>"></td> <td><input type="text" name="destination" value="<?php echo $rows['destination']; ?>"></td> </tr> <tr> <th style="border: none; background: none;"></th> <td></td> <th style="border: none; background: none; float: right;"></th> </tr> </table> <button type="submit" name="submit">Update!</button><br><br><br> </form> <strong><a href="home.php">Click Here to Go Back!</a></strong> <br><br><br> </div> </body> </html>[/size][/color][/font] [font="Verdana, Geneva, sans-serif"][color="#333333"][size=3] Edited January 12, 2013 by psonawane Quote Link to comment Share on other sites More sharing options...
devWhiz Posted January 12, 2013 Share Posted January 12, 2013 try empty() Quote Link to comment Share on other sites More sharing options...
psonawane Posted January 12, 2013 Author Share Posted January 12, 2013 Nothing Happened senior!!! Quote Link to comment Share on other sites More sharing options...
psonawane Posted January 12, 2013 Author Share Posted January 12, 2013 Hi as per ur instruction I tried this <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 } $host = "localhost"; $uname = "root"; $pass = "pranit"; $db_name = "rk_bookings"; $tbl_name = "bus_details"; if (empty($_POST['update'])) { $rate = $_POST['rate']; $coname = $_POST['coname']; $dest = $_POST['destination']; mysql_connect("$host", "$uname", "$pass") or die(mysql_error()); mysql_select_db($db_name); $sql1 = "UPDATE $tbl_name SET price='$rate' WHERE company='$coname' AND destination='$dest'"; $result = mysql_query($sql1); if ($result) { echo "Successful"; } else { echo mysql_error(); } } ?> </body> </html> and its now saying Notice: Undefined index: rate in C:\xampp\htdocs\RK_files\update.php on line 40 Notice: Undefined index: coname in C:\xampp\htdocs\RK_files\update.php on line 41 Notice: Undefined index: destination in C:\xampp\htdocs\RK_files\update.php on line 42 Quote Link to comment Share on other sites More sharing options...
psonawane Posted January 12, 2013 Author Share Posted January 12, 2013 and one more thing which I dint understand is in if (isset($_POST['update'])) what does update mean? Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 12, 2013 Share Posted January 12, 2013 It's your script, so if you don't know what it means no-one does. Also, you need to re-read your change. Translate what it means into plain English, and you should have an epiphany. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted January 12, 2013 Share Posted January 12, 2013 and one more thing which I dint understand is in if (isset($_POST['update'])) what does update mean? I don't know why you chose "update" when you added that line of code. But that line is supposed to be checking to see if the form was submitted. Usually, I use the name of the submit INPUT element there. In your code, that would be "submit". Except that your second post did not include the form that was in the first post, so ... You need to check if one of the fields from the form isset (in the $_POST array) which means the form was submitted, before you do any database updates. When you switched to empty, you effectively reversed the IF test so you should have added NOT -- if (! empty($_POST['submit'])) (However isset() is the way to go.) Note: session_start needs to be called before anything is sent to the browser. By the time you call it you have already sent the HEAD so, your session may not be working properly. For form processing, you generally want to move the processing code above the HTML anyway. It would go something like this: 1. Start a Session (if one is needed) 2. If the form was submitted ... A. Validate the data B. If the data is valid update the database 3. Build the form page Now you can include any error messages from the validation on the page Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.