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>

Link to comment
Share on other sites

Turn on error display and error reporting

Echo your $sql to make sure it's valid

Use mysql_error after your query to see if there are any errors

Remove your mysql_close($sql) at the end of your while loop

Link to comment
Share on other sites

Tried all suggestions without any clue. Still getting a blank window

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

Link to comment
Share on other sites

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

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.