SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP MYSQL Query to delete records from table using combo box selection..

    hii,,
    I've 2 combo boxes in my front end html form, user has to select values from both the combo boxes to delete records frm mysql table, my delete query is not being executed,, please help me out..
    herez my front end form,
    Code HTML4Strict:
    [CODE]<TD CLASS="text">
    <SPAN STYLE="font-weight: bold; color:#001F97;">
    Batch ID:
    </SPAN>
     
    </TD>
    <td>
    <select name="Batch" style="width:180px; font-weight:bold; color:#001F97;"><option value="" selected="selected"><b>-Select Batch ID-</option></b>
    <option value="T08" style="font-weight:bold">T08</option>
    <option value="T09" style="font-weight:bold">T09</option>
    <option value="T10" style="font-weight:bold">T10</option>
    <option value="T11" style="font-weight:bold">T11</option>
    <option value="T12" style="font-weight:bold">T12</option>
    <option value="T13" style="font-weight:bold">T13</option>
    <option value="T14" style="font-weight:bold">T14</option>
    <option value="T15" style="font-weight:bold">T15</option>
    </select>
    </td>
    </tr>
    <tr>
    <TD CLASS="text">
    <SPAN STYLE="font-weight: bold; color:#001F97;">
    Exam Type:
    </SPAN>
     
    </TD>
    <td>
    <select name="Type" style="width:180px; font-weight:bold; color:#001F97;"><option value="" selected="selected">-Select Type-</option>
    <option value="In I" style="font-weight:bold">In I</option>
    <option value="In II" style="font-weight:bold">In II</option>
    <option value="In III" style="font-weight:bold">In III</option>
    <option value="In IV" style="font-weight:bold">In IV</option>
    <option value="Inl V" style="font-weight:bold">Inl V</option>
    <option value="In VI" style="font-weight:bold">In VI</option>
    <option value="Final " style="font-weight:bold">Final </option>
    <option value="Ext" style="font-weight:bold">Ext</option>
    </select>
    </tr>
    </td>
    </table>[/CODE]
    mysql php delete query :
    Code PHP:
    [CODE]<?PHP
      include "authn.php";
    //Connect to mysql server
    	$link=mysql_connect("localhost","root","");
    	if(!$link) {
    		die('Failed to connect to server: ' . mysql_error());
    	}
    	//Select database
    	$db=mysql_select_db("tge");
    	if(!$db) {
    		die("Unable to select database");
    	}
    $Batch = $_POST['Batch'];
    $Type = $_POST['Type'];
     
     
     
    	$query = mysql_query("DELETE FROM in WHERE Type = '$Type' AND Batch = '$Batch'") or die(mysql_error());
     
    	echo "records deleted";
     
     
    	?>[/CODE]
    i want to delete rows based on this type and batch only.. as there are several batches and types are there in th table..
    many thanks.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Your table is called 'in'?
    Try putting back-ticks around that tablename.
    Another thing you might want to do is echo the values of $Type and $Batch and see if they are correct.

  3. #3
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hii,,
    firstly thanx for ur reply,,
    i pasted the mysql generated query only,
    i printed the values coming form html form too they r printed correctly..
    Code PHP:
    [CODE]$type=$_POST['type'];
    	$batch=$_POST['batch'];
     
    	$query = mysql_query("DELETE FROM `in` WHERE CONVERT(`in`.`Type` USING utf8) = '$type' AND CONVERT(`in`.`Batch` USING utf8) = '$batch'") or die(mysql_error());
    	//header("Location: csin1delup.php");[/CODE]

    when i replace $type and $batch in the query and give variables of html form, the records are being deleted successsfullyy..
    i dunnno wats happening with these posted variables..

  4. #4
    SitePoint Zealot pavanpuligandla's Avatar
    Join Date
    Sep 2008
    Location
    hyderabad
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hii,,
    got the o/p..
    Code PHP:
    [CODE]<?PHP
      include "authn.php";
    //Connect to mysql server
    	$link=mysql_connect("localhost","root","");
    	if(!$link) {
    		die('Failed to connect to server: ' . mysql_error());
    	}
    	//Select database
    	$db=mysql_select_db("tge");
    	if(!$db) {
    		die("Unable to select database");
    	}
     
    	$type=$_POST['type'];
    	$batch=$_POST['batch'];
     
     
     
    	$query = mysql_query("DELETE FROM `in` WHERE CONVERT(`in`.`Type` USING utf8) = '$type' AND CONVERT(`in`.`Batch` USING utf8) = '$batch'") or die(mysql_error());
        header("Location: csin1delup.php");
     
    	?>[/CODE]

    but now i've to show the user which records has been deleted so i'm printing those values in "csin1delup.php" as
    <? echo "$type"; ?> but the variable values are not getting printed..any suggestions??


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •