Disscussion about deletion of record from php form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • punitshrivastava
    New Member
    • Jul 2007
    • 22

    Disscussion about deletion of record from php form

    Hi all,
    I am Punit
    I am working in php .i want to delete records from database from php form .
    For this i code the code is:
    [code=php]<?php

    $name = $_POST['firstname'];

    $host="localhos t"; // Host name
    $username="root "; // Mysql username
    $password="root "; // Mysql password
    $db_name="proje ctdb"; // Database name
    $tbl_name="pers on"; // Table name

    // Connect to server and select database.
    $dbconnection = mysql_connect(" $host", "$username" , "$password" )or die("cannot connect");
    mysql_select_db ("$db_name") or die("cannot select DB");

    // delete data in mysql database
    $sql="DELETE FROM person WHERE FirstName ='$name' ";
    echo "$sql";
    $result = mysql_query($sq l,$dbconnection );
    echo"$result";

    // if successfully deleted.
    if($result == 1)
    {
    echo "Successful ";
    echo "<BR>";
    echo "<a href='list_reco rds.php'>View result</a>";
    }

    else
    {
    echo "ERROR";
    }

    ?>[/code]
    it is not working
    when i echo sql statement it shows:

    DELETE FROM person WHERE FirstName ='' 1Successful
    As i am beginners in php so please suggest me .
    Thanks
    Last edited by pbmods; Jul 21 '07, 04:48 PM. Reason: Added CODE tags.
  • tarsem
    New Member
    • Jul 2007
    • 3

    #2
    hi, i am Tarsem SIngh
    Please read PHP help Tutorial -- http://www.php-mysql-tutorial.com/

    Comment

    • punitshrivastava
      New Member
      • Jul 2007
      • 22

      #3
      about deletion of data from php form

      Thanks Tarsem SIngh
      I just go through the website which you refer to me.
      Still i have a problem that value is not posting to another form.
      As i use post for fetching the value:
      $name = $_POST['firstname'];
      in ane form i use table .In that table i use to create row and five col.
      I want to fetch data from one col by the help of that data i delete the entire row from database.As if directly subsitute the value in query it perform the taskbut as i fetch the value from another form it is not working .
      Then i use to create textbob in col.
      by thismethod:
      [code=html]<td><input type = "text" name = "firstname" value="<? echo $rows['FirstName']; ?>" /></td> [/code]
      fetch the data in another form as previously i say.
      but still it is not working.
      please suggest me wht do.As i am beginner in php so please suggest me.
      Thanks
      punit
      Originally posted by tarsem
      hi, i am Tarsem SIngh
      Please read PHP help Tutorial -- http://www.php-mysql-tutorial.com/
      Last edited by pbmods; Jul 21 '07, 04:48 PM. Reason: Added CODE tags.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Punit.

        Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

        Comment

        • kovik
          Recognized Expert Top Contributor
          • Jun 2007
          • 1044

          #5
          I'd suggest you read more into the tutorial. Posted variables only exist *after* the form has been posted, and $rows would only exist after you've created it.

          Also, some basic security can go a long way.

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Originally posted by punitshrivastav a
            Thanks Tarsem SIngh
            I just go through the website which you refer to me.
            Still i have a problem that value is not posting to another form.
            As i use post for fetching the value:
            $name = $_POST['firstname'];
            in ane form i use table .In that table i use to create row and five col.
            I want to fetch data from one col by the help of that data i delete the entire row from database.As if directly subsitute the value in query it perform the taskbut as i fetch the value from another form it is not working .
            Then i use to create textbob in col.
            by thismethod:
            [code=html]<td><input type = "text" name = "firstname" value="<? echo $rows['FirstName']; ?>" /></td> [/code]
            fetch the data in another form as previously i say.
            but still it is not working.
            please suggest me wht do.As i am beginner in php so please suggest me.
            Thanks
            punit
            As I got, you are sending this form element to another script to deletion.
            [code=php]<td><input type = "text" name = "firstname" value="<? echo $rows['FirstName']; ?>" /></td> [/code]
            first try
            [code=php]<td><input type = "text" name = "firstname" value="pass_exi sting_firstname _here" /></td> [/code]
            If its is working,then the problem is with the script that you used to echo these lines.
            [code=php]<? echo $rows['FirstName']; ?>[/code]
            double check it or post that script also.

            Comment

            • abertay
              New Member
              • Jul 2007
              • 10

              #7
              Originally posted by punitshrivastav a
              Hi all,
              I am Punit
              I am working in php .i want to delete records from database from php form .
              For this i code the code is:
              [code=php]<?php

              $name = $_POST['firstname'];

              $host="localhos t"; // Host name
              $username="root "; // Mysql username
              $password="root "; // Mysql password
              $db_name="proje ctdb"; // Database name
              $tbl_name="pers on"; // Table name

              // Connect to server and select database.
              $dbconnection = mysql_connect(" $host", "$username" , "$password" )or die("cannot connect");
              mysql_select_db ("$db_name") or die("cannot select DB");

              // delete data in mysql database
              $sql="DELETE FROM person WHERE FirstName ='$name' ";
              echo "$sql";
              $result = mysql_query($sq l,$dbconnection );
              echo"$result";

              // if successfully deleted.
              if($result == 1)
              {
              echo "Successful ";
              echo "<BR>";
              echo "<a href='list_reco rds.php'>View result</a>";
              }

              else
              {
              echo "ERROR";
              }

              ?>[/code]
              it is not working
              when i echo sql statement it shows:

              DELETE FROM person WHERE FirstName ='' 1Successful
              As i am beginners in php so please suggest me .
              Thanks

              Remove the double qoutes in your mysql_connect & mysql_select_db query.
              Because $host="localhos t" so you dont need them again

              Code:
              mysql_connect($host,$root,$password);
              mysql_select_db($dbname);

              Comment

              Working...