-2

srno is being successfully fetched from a textbox

<?php
    $srno = $_POST['srno'];
    mysql_connect("localhost","root","");
    mysql_select_db("visit");
    $sql ="UPDATE visitor SET Exit='".$ab."' WHERE srno=$srno"; 
    mysql_query($sql) or die ("Error: ".mysql_error());
    ?>
John Conde
  • 217,595
  • 99
  • 455
  • 496
Gaurav Gupta
  • 55
  • 11

2 Answers2

4
  1. If $srno is a string you're missing quotes around it

  2. $ab is not defined

  3. Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

  4. You are also wide open to SQL injections

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
1

To further elaborate on John (Conde's) answer, exit is a MySQL reserved word:

Either rename it to something else, or wrap it in backticks:

$sql ="UPDATE visitor SET `Exit`='".$ab."' WHERE srno=$srno";
                          ^    ^ backticks

or (if $srno is a string, as John stated in his answer)

$sql ="UPDATE visitor SET `Exit`='".$ab."' WHERE srno='$srno'"; 

You have used mysql_error() on mysql_query() which should have signaled the syntax error, something you have not shared completely in your question, only as the question's title which does not show us the complete error message, however I am certain it is something to the effect of
...MySQL server version for the right syntax near 'Exit...


Add error reporting to the top of your file(s) which will help during production testing.

error_reporting(E_ALL);
ini_set('display_errors', 1);

which will signal an Undefined variable... warning for $ab.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141