Jump to content

[SOLVED] Would someone check this code please


coutts

Recommended Posts

I have the following 2 pages. The user enters the SKU number in the form on delete.htm adn the pic file and SQL database entry are deleted in delete.php. Only they arent. Delete.php is a blank page (no errors), and as you can see I echoed SKU and I dont think it is being passed.

 

Any help, thanks

 

 

This is delete.htm

 

<html>
<head>
<title>Delete Item</title>
<style>
td  {font-family:arial; font-weight:500; font-size:12px; color:black}
</style>
</head>
<body>
<center>
<form action="delete.php" method="post" name="addform">
<table align="center" border="1" bgcolor="white" frame="box" bordercolor="black" bordercolorlight="black" bordercolordark="black" cellspacing="0" cellpadding="25" width="640">
<td valign="top">
<table border="0">
<tr><td>SKU</td><td><input type="text" name="SKU" size="15"></td></tr>
</table>
<input type="submit" value="Delete Item">
</form>
</table>
</td></table>
</center>
</body>
</html> 

 

This is delete.php

 

<html>
<head>
<title>Delete Item</title></head>
<body bgcolor="#FFFFFF">
<?php
$sku = $_POST["SKU"];
echo( $sku );
#connect to MySQL
$conn=@mysql_connect( "localhost", "", "")
	 	or die( "Err:Conn" );

#select the specified database
$rs = @mysql_select_db( "tractors", $conn ) 
		or die( "Err:Db" );
#create the query 
$sql = "select SKU, TITLE, DESCRIPTION, PRICE, CATEGORY from tractors"
#execute the query
$rs = mysql_query( $sql, $conn );

#write the data
while( $row = mysql_fetch_array( $rs ) )
{

    $sql = "DELETE FROM tractors WHERE SKU=$sku";
    $pics = "../pics/" . $row["SKU"] . ".jpg";
    unlink( $pics );
    $result = mysql_query($sql);
    echo( "<br><br><br><br><table align='center' border='3' bgcolor='white' frame='box' bordercolor='black' bordercolorlight='black' bordercolordark='black' cellspacing='0' cellpadding='10'><td>" );
    echo( "<font face='arial' color='black' size='3'>Item " .  $row["SKU"] . " has been deleted.");
    echo( "</td></table>" );
    mysql_close($sql); 
}


?>
</body>
</html>

I found the problem (and its one of those duh problems) the ; on the end of #create the query

$sql = "select SKU, TITLE, DESCRIPTION, PRICE, CATEGORY from tractors";

 

was missing. New to PHP - used to programming with visual basic - no need to end lines with vb.

 

Thanks for help

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.