Jump to content

[SOLVED] need help with a php remove from sql script


randydg

Recommended Posts

This is my code, Using this can anyone help me create a script that will delete an entry that i specify by ID

 

mysql_select_db("worksheets",$db) or die("Couldn't select database"); 
$sql = "INSERT INTO worksheets VALUES('','$date','$time','$caller','$equipment','$warranty','$billable','$inshopa','$onsite','$called','$workproblem','$workperformed','$serial','$comments','$dateworked1','$dateworked2','$dateworked3','$timein1','$timein2','$timein3','$timeout1','$timeout2','$timeout3','$techworked1','$techworked2','$techworked3','$quanity1','$quanity2','$quanity3','$quanity4','$quanity5','$quanity6','$description1','$description2','$description3','$description4','$description5','$description6','$unitprice1','$unitprice2','$unitprice3','$unitprice4','$unitprice5','$unitpric6','','','','','','','','','')";
    $result = mysql_query($sql); 
if (!$result) { 
            die('Invalid query: '.mysql_error()); 
    } 

 

Link to comment
Share on other sites

Well, its not solved completly. Here is what im lacking.

 

the above deletes the info in the worksheets, but doesnt delete the worksheet completly. Maybe this will help. this is the code that creates a new worksheet.

 


<body>

<?php
if (isset($_POST['submitnew'])) { 
    $status = trim(stripslashes($_POST['status']));
$priority = trim(stripslashes($_POST['priority']));
$inshop = trim(stripslashes($_POST['inshop']));
$inprogress = trim(stripslashes($_POST['inprogress']));
$pending = trim(stripslashes($_POST['pending']));
$tobepickedup = trim(stripslashes($_POST['tobepickedup']));
$completed = trim(stripslashes($_POST['completed']));
$checkbox = trim(stripslashes($_POST['checkbox']));
$inshopa = trim(stripslashes($_POST['inshopa']));
$name = trim(stripslashes($_POST['name']));
$date = trim(stripslashes($_POST['date']));
$caller = trim(stripslashes($_POST['caller']));
$phone = trim(stripslashes($_POST['phone']));
$alt = trim(stripslashes($_POST['alt']));
$address = trim(stripslashes($_POST['address']));
$equipment = trim(stripslashes($_POST['equipment']));
$warranty = trim(stripslashes($_POST['warranty']));
$billable = trim(stripslashes($_POST['billable']));
$inshopa = trim(stripslashes($_POST['inshopa']));
$onsite = trim(stripslashes($_POST['onsite']));
$called = trim(stripslashes($_POST['called']));
$city = trim(stripslashes($_POST['city']));
$zip = trim(stripslashes($_POST['zip']));
$state = trim(stripslashes($_POST['state']));
$workproblem = trim(stripslashes($_POST['workproblem']));
$workperformed = trim(stripslashes($_POST['workperformed']));
$serial = trim(stripslashes($_POST['serial']));
$dateworked1 = trim(stripslashes($_POST['dateworked1']));
$timein1 = trim(stripslashes($_POST['timein1']));
$timeout1 = trim(stripslashes($_POST['timeout1']));
$techworked1 = trim(stripslashes($_POST['techworked1']));
$comments = trim(stripslashes($_POST['comments']));
$dateworked2 = trim(stripslashes($_POST['dateworked2']));
$timein2 = trim(stripslashes($_POST['timein2']));
$timeout2 = trim(stripslashes($_POST['timeout2']));
$techworked2 = trim(stripslashes($_POST['techworked2']));
$dateworked3 = trim(stripslashes($_POST['dateworked3']));
$timein3 = trim(stripslashes($_POST['timein3']));
$timeout3 = trim(stripslashes($_POST['timeout3']));
$techworked3 = trim(stripslashes($_POST['techworked3']));
$quanity1 = trim(stripslashes($_POST['quanity1']));
$description1 = trim(stripslashes($_POST['description1']));
$unitprice1 = trim(stripslashes($_POST['unitprice1']));
$quanity2 = trim(stripslashes($_POST['quanity2']));
$description2 = trim(stripslashes($_POST['description2']));
$unitprice2 = trim(stripslashes($_POST['unitprice2']));
$quanity3 = trim(stripslashes($_POST['quanity3']));
$description3 = trim(stripslashes($_POST['description3']));
$unitprice3 = trim(stripslashes($_POST['unitprice3']));
$quanity4 = trim(stripslashes($_POST['quanity4']));
$description4 = trim(stripslashes($_POST['description4']));
$unitpreice4 = trim(stripslashes($_POST['unitpreice4']));
$quanity5 = trim(stripslashes($_POST['quanity5']));
$description5 = trim(stripslashes($_POST['description5']));
$unitprice5 = trim(stripslashes($_POST['unitprice5']));
$quanity6 = trim(stripslashes($_POST['quanity6']));
$description6 = trim(stripslashes($_POST['description6']));
$unitprice6 = trim(stripslashes($_POST['unitprice6']));
//Customer Table Vari
$name = trim(stripslashes($_POST['name']));
$phone = trim(stripslashes($_POST['phone']));
$alt = trim(stripslashes($_POST['alt']));
$address = trim(stripslashes($_POST['address']));
$city = trim(stripslashes($_POST['city']));
$state = trim(stripslashes($_POST['state']));
$zip = trim(stripslashes($_POST['zip']));

$time = date ( 'H:i:s' );
$status = 1;

//Customer Entry	
$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database"); 
$sql4 = "INSERT INTO customers VALUES('','$name','$phone','$alt','$address','$city','$state','$zip')";
$result4 = mysql_query($sql4); 
    if (!$result4) { 
            die('Invalid query: '.mysql_error()); 
    } 
    //print "Added successfully.<br />";


//Worksheet Entry	

    $db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database"); 
$sql = "INSERT INTO worksheets VALUES('','$date','$time','$caller','$equipment','$warranty','$billable','$inshopa','$onsite','$called','$workproblem','$workperformed','$serial','$comments','$dateworked1','$dateworked2','$dateworked3','$timein1','$timein2','$timein3','$timeout1','$timeout2','$timeout3','$techworked1','$techworked2','$techworked3','$quanity1','$quanity2','$quanity3','$quanity4','$quanity5','$quanity6','$description1','$description2','$description3','$description4','$description5','$description6','$unitprice1','$unitprice2','$unitprice3','$unitprice4','$unitprice5','$unitpric6','','','','','','','','','')";
    $result = mysql_query($sql); 
if (!$result) { 
            die('Invalid query: '.mysql_error()); 
    } 
    

//customer and worksheet data for "call Entry" Insert
$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database"); 
$sql3 = "SELECT `id` FROM `worksheets` WHERE `time` = '$time' LIMIT 0, 30";
$result3 = mysql_query($sql3);
    $worksheet = mysql_fetch_row($result3);
if (!$result4) { 
            die('Invalid query: '.mysql_error()); 
    } 
    //print "$time $worksheet[0] added successfully.<br />";

$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database"); 	
$sql5 = "SELECT `id` FROM `customers` WHERE `name` = '$name' LIMIT 0, 30";
$result5 = mysql_query($sql5);
    $customers = mysql_fetch_row($result5);
if (!$result5) { 
            die('Invalid query: '.mysql_error()); 
    } 
//print "$customers[0] added successfuly.<br />";

//Call Entry

$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database"); 
$sql2 = "INSERT INTO calls VALUES('','$date','$time','$customers[0]','$worksheet[0]','$status','$inshop','$inprogress','$pending','$tobepickedup','$completed','$priority')";
$result2 = mysql_query($sql2); 
    if (!$result2) { 
            die('Invalid query: '.mysql_error()); 
    } 
    print "Added successfully.<br />";

} 


$date = date ( 'Y-m-d' );
?>



<form name="new" method="POST" action="<?=$PHP_SELF;?>">

<table width="800" border="1">
  <tr>

<td width="20%">
    <?php
	//Get Tech List out of database
	$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database");
	$query="SELECT `id`,`name` FROM `techs`";
	$result=mysql_query($query);
	$num=mysql_numrows($result);
	echo "<span class=\"style4\">In Shop</span><select name=\"inshop\" id=\"inshop\">";
	$i=0;
	while ($i < $num) {

	$techname=mysql_result($result,$i,"name");
	$techid=mysql_result($result,$i,"id");
	echo "<option value=$techid>$techname</option>";
	$i++;
	};
	echo "<option value=\"NA\">Other</option>";
	echo "<option value=\"-\" selected>-</option> </select>";

	?> 
</td>

<td width="20%">
<?php
	$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database");
	$query="SELECT `id`,`name` FROM `techs`";
	$result=mysql_query($query);
	$num=mysql_numrows($result);
	echo "<span class=\"style4\">In Progress</span><select name=\"inprogress\" id=\"inprogress\">";
	$i=0;
	while ($i < $num) {

	$techname=mysql_result($result,$i,"name");
	$techid=mysql_result($result,$i,"id");
	echo "<option value=$techid>$techname</option>";
	$i++;
	};
	echo "<option value=\"NA\">Other</option>";
	echo "<option value=\"-\" selected>-</option> </select>";

?>
</td>
    <td width="20%">
<?php
	$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database");
	$query="SELECT `id`,`name` FROM `techs`";
	$result=mysql_query($query);
	$num=mysql_numrows($result);
	echo "<span class=\"style4\">Pending:</span><select name=\"pending\" id=\"pending\">";
	$i=0;
	while ($i < $num) {

	$techname=mysql_result($result,$i,"name");
	$techid=mysql_result($result,$i,"id");
	echo "<option value=$techid>$techname</option>";
	$i++;
	};
	echo "<option value=\"NA\">Other</option>";
	echo "<option value=\"-\" selected>-</option> </select>";
?>
</td>
    <td width="20%">
<?php
	$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database");
	$query="SELECT `id`,`name` FROM `techs`";
	$result=mysql_query($query);
	$num=mysql_numrows($result);
	echo "<span class=\"style4\">To Be pickedup:</span><select name=\"tobepickedup\" id=\"tobepickedup\">";
	$i=0;
	while ($i < $num) {

	$techname=mysql_result($result,$i,"name");
	$techid=mysql_result($result,$i,"id");
	echo "<option value=$techid>$techname</option>";
	$i++;
	};
	echo "<option value=\"NA\">Other</option>";
	echo "<option value=\"-\" selected>-</option> </select>";
?>
</td>
    <td width="20%">
<?php
	$db = mysql_connect("domain.com","user","pass") or die("Couldn't connect"); 
    mysql_select_db("database",$db) or die("Couldn't select database");
	$query="SELECT `id`,`name` FROM `techs`";
	$result=mysql_query($query);
	$num=mysql_numrows($result);
	echo "<span class=\"style4\">Completed:</span><select name=\"completed\" id=\"completed\">";
	$i=0;
	while ($i < $num) {

	$techname=mysql_result($result,$i,"name");
	$techid=mysql_result($result,$i,"id");
	echo "<option value=$techid>$techname</option>";
	$i++;
	};
	echo "<option value=\"NA\">Other</option>";
	echo "<option value=\"-\" selected>-</option> </select>";
?>
</td>
    <td width="80"><span class="style4">Priority:</span>
      <input name="priority" type="checkbox" id="priority" value="1">
  
    </td>
  </tr>
</table>

<br>
<table width="800"  border="1">
  <tr>
    <td colspan="5"><img src="image001.JPG" width="661" height="215"> 
    </td>
  </tr>
  <tr>
    <td width="38%" rowspan="2" valign="top"><p><strong>Name or Company:</strong> <input name="name" type="text" id="name" value=" " size="20"> 
          	<p>Address: 
          <input name="address" type="text" id="address" size="30">
		<br>
		City:       
            <input name="city" type="text" id="city" size="12">
      Zip
      <input name="zip" type="text" id="zip" size="10">     
      <br>
      State:     
      <input name="state" type="text" id="state" value="Tx" size="2">
       </td>
    <td width="13%">Date:
<input name="date" type="text" id="date" size="10"
	<?php
	echo "value=$date";
 	?>
	>
</td>
    <td width="18%">Caller:
    <input name="caller" type="text" id="caller" size="12"></td>
    <td width="16%">Phone:
    <input name="phone" type="text" id="phone" size="12"></td>
    <td width="15%">Alt:
    <input name="alt" type="text" id="alt" size="12"></td>
  </tr>
  <tr>
    <td colspan="3" valign="top"><div align="center">
      <p>Equipment to Service: </p>
      <p>
        <input name="equipment" type="text" id="equipment" size="30">
      </p>
    </div></td>
    <td align="left" valign="top" nowrap>
  <div align="left">
    <table width="100%" border="0">
          <tr>
            <td width="57">Warranty</td>
            <td width="43"><input name="warranty" type="checkbox" id="warranty" value="1"></td>
          </tr>
          <tr>
            <td>Billable</td>
            <td><input name="billable" type="checkbox" id="billable" value="1"></td>
          </tr>
          <tr>
            <td>In Shop </td>
            <td><input name="inshopa" type="checkbox" id="inshopa" value="1"></td>
          </tr>
          <tr>
            <td>On Site </td>
            <td><input name="onsite" type="checkbox" id="onsite" value="1"></td>
          </tr>
          <tr>
            <td>Called</td>
            <td><input name="called" type="checkbox" id="called" value="1">
</td>
          </tr>
        </table>
  </div>
  </tr>
  <tr>
    <td colspan="5" w><strong>Work Problem:</strong><br> 
      <textarea name= "workproblem" cols="90" rows="10" id="workproblem"></textarea></td>
  </tr>
  <tr>
    <td colspan="5"><strong>Work Performed:</strong><br>
    <textarea name= "workperformed" cols="90" rows="10" id="workperformed"></textarea></td>
  </tr>
  <tr>
    <td colspan="5"><table width="786" border="1">
      <tr>
        <td width="60" height="26">Date</td>
        <td width="42">In</td>
        <td width="42">Out</td>
        <td width="30">Tech</td>
        <td width="578">Serial/CD-Key: 
          <input name="serial" type="text" id="serial" size="70"></td>
      </tr>
      <tr>
        <td><input name="dateworked1" type="text" id="dateworked1" size="10"></td>
        <td><input name="timein1" type="text" id="timein1" size="7"></td>
        <td><input name="timeout1" type="text" id="timeout1" size="7"></td>
        <td><div align="center">
          <input name="techworked1" type="text" id="techworked1" size="2">
        </div></td>
        <td rowspan="3" align="left" valign="top">Comments:<br>
                        <textarea name= "comments" cols="55" rows="5" id="comments"></textarea>
          </td>
      </tr>
      <tr>
        <td><input name="dateworked2" type="text" id="dateworked2" size="10"></td>
        <td><input name="timein2" type="text" id="timein2" size="7"></td>
        <td><input name="timeout2" type="text" id="timeout2" size="7"></td>
        <td><div align="center">
          <input name="techworked2" type="text" id="techworked2" size="2">
        </div></td>
        </tr>
      <tr>
        <td><input name="dateworked3" type="text" id="dateworked3" size="10"></td>
        <td><input name="timein3" type="text" id="timein3" size="7"></td>
        <td><input name="timeout3" type="text" id="timeout3" size="7"></td>
        <td><div align="center">
          <input name="techworked3" type="text" id="techworked3" size="2">
        </div></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="5"><table width="786" border="1">
      <tr>
        <td width="47">Quanity</td>
        <td width="542">Description</td>
        <td width="72">Unit Price </td>
        <td width="97">Extended Price </td>
      </tr>
      <tr>
        <td><input name="quanity1" type="text" id="quanity1" size="2"></td>
        <td><input name="description1" type="text" id="description1" size="80"></td>
        <td><input name="unitprice1" type="text" id="unitprice1" size="12"></td>
        <td><div align="right">
          <input name="textfield" type="text" size="10">
        </div></td>
      </tr>
      <tr>
        <td><input name="quanity2" type="text" id="quanity2" size="2"></td>
        <td><input name="description2" type="text" id="description2" size="80"></td>
        <td><input name="unitprice2" type="text" id="unitprice2" size="12"></td>
        <td>          <div align="right">
          <input name="textfield" type="text" size="10">        
        </div></td>
      </tr>
      <tr>
        <td><input name="quanity3" type="text" id="quanity3" size="2"></td>
        <td><input name="description3" type="text" id="description3" size="80"></td>
        <td><input name="unitprice3" type="text" id="unitprice3" size="12"></td>
        <td><div align="right">
          <input name="textfield" type="text" size="10">
        </div></td>
      </tr>
      <tr>
        <td><input name="quanity4" type="text" id="quanity4" size="2"></td>
        <td><input name="description4" type="text" id="description4" size="80"></td>
        <td><input name="unitprice4" type="text" id="unitprice4" size="12"></td>
        <td><div align="right">
          <input name="textfield" type="text" size="10">
        </div></td>
      </tr>
      <tr>
        <td><input name="quanity5" type="text" id="quanity5" size="2"></td>
        <td><input name="description5" type="text" id="description5" size="80"></td>
        <td><input name="unitprice5" type="text" id="unitprice5" size="12"></td>
        <td><div align="right">
          <input name="textfield" type="text" size="10">
        </div></td>
      </tr>
      <tr>
        <td><input name="quanity6" type="text" id="quanity6" size="2"></td>
        <td><input name="description6" type="text" id="description6" size="80"></td>
        <td><input name="unitprice6" type="text" id="unitprice6" size="12"></td>
        <td><div align="right">
          <input name="textfield" type="text" size="10">
        </div></td>
      </tr>
      <tr>
        <td colspan="2" rowspan="3"><p><img src="image005.gif" width="494" height="128"></p></td>
        <td height="27">Subtotal</td>
        <td><div align="right">
          <input name="subtotal" type="text" id="subtotal" size="10">
        </div></td>
      </tr>
      <tr>
        <td height="30">Tax</td>
        <td><div align="right">
          <input name="tax" type="text" id="tax" size="10">
        </div></td>
      </tr>
      <tr>
        <td height="51">Total Price </td>
        <td><div align="right">
          <input name="totalprice" type="text" id="totalprice" size="10">
        </div></td>
      </tr>
    </table></td>
  </tr>
</table>


<table width="800" border="0">
  <tr>
    <td align="right" valign="top"><input type="submit" name="submitnew" value="SUBMIT"/> <INPUT TYPE="reset"></td>
  </tr>
</table>
</form>

</body>

Link to comment
Share on other sites

<?php
mysql_select_db("worksheets",$db) or die("Couldn't select database");
$theidyouspecify ='';// define this as the id you specify
$sql = "DELETE FROM worksheets WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);

$sql = "DELETE FROM calls WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);

$sql = "DELETE FROM customers WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);


$sql = "SELECT `id` FROM `worksheets` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$worksheet = mysql_fetch_row($result);
if (!$result) { 
echo 'Worksheets entry deleted<br />';
}else{
echo 'failed to remove from worksheets table<br />';
}

$sql = "SELECT `id` FROM `customers` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$customers = mysql_fetch_row($result);
if (!$result) { 
echo 'customers entry deleted<br />';
}else{
echo 'failed to remove from customers table<br />';
}

$sql = "SELECT `id` FROM `calls` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$calls= mysql_fetch_row($result);
if (!$result) { 
echo 'calls entry deleted<br />';
}else{
echo 'failed to remove from calls table<br />';
}


?>

 

This will delete from all 3 tables (calls, worksheets & customers)

Link to comment
Share on other sites

ok i took what you just posted and did this

 


<?php
mysql_connect("domain","user","user") or die("Couldn't connect");
$theidyouspecify ='';// define this as the id you specify
$sql = "DELETE FROM worksheets WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);

$sql = "DELETE FROM calls WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);

$sql = "DELETE FROM customers WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);


$sql = "SELECT `id` FROM `worksheets` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$worksheet = mysql_fetch_row($result);
if (!$result) { 
echo 'Worksheets entry deleted<br />';
}else{
echo 'failed to remove from worksheets table<br />';
}

$sql = "SELECT `id` FROM `customers` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$customers = mysql_fetch_row($result);
if (!$result) { 
echo 'customers entry deleted<br />';
}else{
echo 'failed to remove from customers table<br />';
}

$sql = "SELECT `id` FROM `calls` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$calls= mysql_fetch_row($result);
if (!$result) { 
echo 'calls entry deleted<br />';
}else{
echo 'failed to remove from calls table<br />';
}


?>
<form name="id" method="POST" action="<?=$PHP_SELF;?>">
    Enter worksheet id to delete ($worksheetnum) 
      <input name="name" type="text" id="name" size="40">
      <INPUT TYPE="submit"></form>

 

but when I use that i get the error

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource on line 16

 

line 16 is $worksheet = mysql_fetch_row($result);

I think my host doen't like mysql_fetch_row not sure

 

Link to comment
Share on other sites

I changed it... not sure what I was doing in first one, sorry.

 

<?php
mysql_connect("domain","user","user") or die("Couldn't connect");
$theidyouspecify ='';// define this as the id you specify
$sql = "DELETE FROM worksheets WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);

$sql = "DELETE FROM calls WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);

$sql = "DELETE FROM customers WHERE id='$theidyouspecify' LIMIT 1";
mysql_query($sql);


$sql = "SELECT `id` FROM `worksheets` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$num=mysql_numrows($result);
if ($num<1) { 
echo 'Worksheets entry deleted<br />';
}else{
echo 'failed to remove from worksheets table<br />';
}

$sql = "SELECT `id` FROM `customers` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$num=mysql_numrows($result);
if ($num<1) { 
echo 'customers entry deleted<br />';
}else{
echo 'failed to remove from customers table<br />';
}

$sql = "SELECT `id` FROM `calls` WHERE `id` = '$theidyouspecify'";
$result = mysql_query($sql);
$num=mysql_numrows($result);
if ($num<1) { 
echo 'calls entry deleted<br />';
}else{
echo 'failed to remove from calls table<br />';
}


?>
<form name="id" method="POST" action="<?=$PHP_SELF;?>">
    Enter worksheet id to delete ($worksheetnum)
      <input name="name" type="text" id="name" size="40">
      <INPUT TYPE="submit"></form>

 

 

Link to comment
Share on other sites

Ok the code works now but it only will delete what i put in

$theidyouspecify ='idnumber';// define this as the id you specify

 

Is there anyway to make it pull the id number from a form?

 

I think I know what to do. put the code in a separate file and put the form in one by itself.

and have the form post to the code? but if I do that what would i do for the form?

 

<form name="id" method="POST" action="code.php">
    Enter worksheet id to delete ($worksheetnum)
      <input name="id" type="text" id="id" size="40">
      <INPUT TYPE="submit"></form>

 

p.s. Thanks for all your help. I'll put your name in the code for author

Link to comment
Share on other sites

Covered in one file

 

<?php

if(isset($_POST['submit'])){
if(is_numeric($_POST['id'])) {
	$theidyouspecify = $_POST['id'];// define this as the id you specify
}else{
	$error[] = 'Id must be numeric.';
}
// no error, so run the query
if(!$error){
	if(!mysql_connect("domain","user","pass")) $error[] = "Couldn't connect to database<br />";
	if(!mysql_select_db("worksheets",$db)) $error[] = "Couldn't select database<br />";

	$sql = "DELETE FROM worksheets WHERE id='$theidyouspecify' LIMIT 1";
	if(!mysql_query($sql)){ 
		$error[] = 'failed to remove from worksheets table<br />';
	}else{
		$error[] = 'Worksheets entry deleted<br />';
	}

	$sql = "DELETE FROM calls WHERE id='$theidyouspecify' LIMIT 1";
	if(!mysql_query($sql)){ 
		$error[] = 'failed to remove from calls table<br />';
	}else{
		$error[] = 'calls entry deleted<br />';
	}

	$sql = "DELETE FROM customers WHERE id='$theidyouspecify' LIMIT 1";
	if(!mysql_query($sql)){ 
		$error[] = 'failed to remove from customers table<br />';
	}else{
		$error[] = 'customers entry deleted<br />';
	}

}

}

?>
<div id="error">
<?php
  $error[]='';
  foreach($error as $value){
  	echo $value;
  }
?>
</div>
<form name="id" method="POST" action="<?=$PHP_SELF;?>">
    Enter worksheet id to delete ($worksheetnum)
    <input name="id" type="text" id="id" size="10" />
    <input type="submit" name="submit" />
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.