What am I missing?
Posted: Sun Sep 18, 2005 3:05 pm
Ive been messing with this for a while now and as far as i can see everything is correct. The goal is to get the data from another page and then go through the database and delete any row that has the same value that is stored in the field stock. When i run it I dont get any errors but its not deleting it from my database. I verified that it is getting a variable from the other page and that it will compare the variable $stocknum and $stock and should delete the line however it doesnt delete it. Any suggestions or help would be greatly appreciated. Ive searched for a while as to what is preventing it. If anyone sees what im missing or doing incorectly Id thank you for posting.
Code: Select all
<?php
$stocknum =$_POST['stocknum'];
// variable to define connection features
$conn = mysql_connect("localhost", "user", "pass");
// pick database
mysql_select_db("myintern_cartest ", $conn);
// Create sql statement
$sql = "SELECT * FROM cars";
// Execute the sql statement
$result = mysql_query($sql, $conn) or die(mysql_error());
// while function
while($newArray = mysql_fetch_array($result))
{
$stock = $newArray['stock'];
if ( $stock == $stocknum)
{
$sql = "DELETE FROM cars WHERE stock=$stocknum";
mysql_query($sql);
}
}
?>