jmac2501 Posted January 30, 2008 Share Posted January 30, 2008 I am having a problem getting this to work. It dosn't give an error but dosn't delete. if (empty($price)) { $query = "DELETE FROM listings WHERE reo='$reo'"; mysql_query($query); echo "REO $reo deleted"; mysql_close(); echo ("<br />"); } Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/ Share on other sites More sharing options...
pocobueno1388 Posted January 30, 2008 Share Posted January 30, 2008 You need to try to catch the error with die(). mysql_query($query)or die(mysql_error()."<p>With Query:<br>$query"); Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453703 Share on other sites More sharing options...
jmac2501 Posted January 30, 2008 Author Share Posted January 30, 2008 i tryed that and still nothing... here is my whole code for that part: $link = mysql_connect('mysql6.*******.com', '******', '*******') or die('Could not connect: ' . mysql_error()); mysql_select_db('*****') or die('Could not select database'); $query = "DELETE FROM listings WHERE reo='$reo'"; mysql_query($query)or die(mysql_error()."<p>With Query:<br>$query"); mysql_query($query); echo "REO $reo deleted"; mysql_close($link); echo ("<br />"); Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453709 Share on other sites More sharing options...
revraz Posted January 30, 2008 Share Posted January 30, 2008 Remove this second entry mysql_query($query); If this is your condition, maybe it's not empty? if (empty($price)) Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453715 Share on other sites More sharing options...
jmac2501 Posted January 30, 2008 Author Share Posted January 30, 2008 I made it so that it is empty to test... but everything else looks ok besides the second mysql_query($query);? Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453754 Share on other sites More sharing options...
revraz Posted January 30, 2008 Share Posted January 30, 2008 syntax is right, but we dont know your db/table layout or if $reo contains a valid value Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453760 Share on other sites More sharing options...
jmac2501 Posted January 30, 2008 Author Share Posted January 30, 2008 ok so i figured out the problem but am looking for a solution. How would i clear out my previous varables? my script runs and gathers variables but if it comes acrossed $price and there is no $price it uses its last cycles variables. i.e. cycle 1 price = 1 echoed $price = 1 cycle 2 price = 2 echoed $price = 2 cycle 3 price = echoed $price = 2 (instead of being empty) Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453762 Share on other sites More sharing options...
pocobueno1388 Posted January 30, 2008 Share Posted January 30, 2008 Just don't set the variable unless the price has a value. <?php if (!empty($row['price'])) $price = $row['price']; ?> It's kinda hard to give you a good example without seeing code. Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453768 Share on other sites More sharing options...
jmac2501 Posted January 30, 2008 Author Share Posted January 30, 2008 <?php error_reporting(E_ALL ^ E_NOTICE); $link = mysql_connect('mysql6.******.com', '******', '******') or die('Could not connect: ' . mysql_error()); mysql_select_db('*****') or die('Could not select database'); $query = "SELECT * FROM Listings"; $result = mysql_query($query); $num = mysql_num_rows($result); mysql_close($link); $i = 0; while ($i < $num) { $reo = mysql_result($result, $i, "reo"); require_once ("class_http.php"); $h = new http(); $h->dir = "/home/foo/bar/"; if (!$h->fetch("http://metrolistmls.com/cgi-bin/GetOneR.cfm?County=SA&iRow=0&nJL=7&MLSNum=" . $reo)) { echo "<h2>There is a problem with the http request!</h2>"; echo $h->log; exit(); } if ($beg = strpos($h->body, "http://mlsmedia.metrolistmls.com/bigphoto/", 0)) { $end = strpos($h->body, ".jpg", $beg); $pic = substr($h->body, $beg, ($end + 4) - $beg); echo ("$pic"); echo ("<br />"); } if ($beg = strpos($h->body, "<td align=\"center\" class=\"PageTitle\" width=\"534\"><b> $", 0)) { $end = strpos($h->body, "</b></td>", $beg); $price = substr($h->body, $beg + 55, ($end - 55) - $beg); echo ("$price"); echo ("<br />"); } if ($beg = strpos($h->body, "<td class=\"PageTitle\" colspan=\"3\" align=\"center\"><b>", 0)) { $end = strpos($h->body, ",", $beg); $streetaddress = substr($h->body, $beg + 52, ($end - 52) - $beg); echo ("$streetaddress"); echo ("<br />"); $str = '$streetaddress '; } if ($beg = strpos($h->body, "<td class=\"PageTitle\" colspan=\"3\" align=\"center\"><b>", 0)) { $end = strpos($h->body, "</b></td>", $beg); $city = substr($h->body, $beg + 56 + strlen($str), ($end - 61 - strlen($str)) - $beg); echo ("$city"); echo ("<br />"); } if ($beg = strpos($h->body, "<td width=\"16%\" class=\"FormTitle\">Sq Ft</td> <td width=\"14%\">", 0)) { $end = strpos($h->body, "</td> <td width=\"16%\"", $beg); $squarefeet = substr($h->body, $beg + 76, ($end - 76) - $beg); echo ("$squarefeet"); echo ("<br />"); } if ($beg = strpos($h->body, "<td width=\"16%\" class=\"FormTitle\">Bedrooms</td>", 0)) { $end = strpos($h->body, "</td> <td width=\"16%", $beg); $bed = substr($h->body, $beg + 97, ($end - 97) - $beg); echo ("$bed"); echo ("<br />"); } if ($beg = strpos($h->body, "<td width=\"16%\" class=\"FormTitle\">Full Baths</td>", 0)) { $end = strpos($h->body, "</td> <td width=\"16%", $beg); $Fbath = substr($h->body, $beg + 81, ($end - 81) - $beg); echo ("$Fbath"); echo ("<br />"); } if ($beg = strpos($h->body, "<td width=\"16%\" class=\"FormTitle\">Half Baths</td>", 0)) { $end = strpos($h->body, "</td> <td width=\"16%", $beg); $Hbath = substr($h->body, $beg + 99, ($end - 99) - $beg); echo ("$Hbath"); echo ("<br />"); } if ($beg = strpos($h->body, "<td width=\"60\"><b>Agent</b></td>", 0)) { $end = strpos($h->body, " ", $beg); $agent = substr($h->body, $beg + 85, ($end - 85) - $beg); if (trim($agent) == "Diane C Cox") { $agent = "Diane Cox"; $teng = "Lizette Gonzalez </td> </tr> </table> </td> </tr> <tr> <td height=\"17\" colspan=\"3\"> <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\"> <tr> <td width=\"60\"><b>Office</b></td> <td class=\"body14\"> <a href=\"../Offices/01rmxg08.cfm\" class=\"link2\"><b>RE/MAX Gold Sacramento</b></a>"; } if (trim($agent) == "Lizette Gonzalez") { $agent = "Lizette Gonzalez"; echo ($agent); echo ("<br />"); } } if (trim($pic) == "") { $pic = "../images/nophoto1b_small.jpg"; } Echo ($price); if (empty($price)) { /* Connecting, selecting database */ $db_link = mysql_connect("mysql6.*****.com", "******", "******"); if (!$db_link) { die("Could not connect: " . mysql_error()); } mysql_select_db("******") or die("Could not select database"); $query = "DELETE FROM listings WHERE reo='$reo'"; mysql_query($query); echo "REO $reo deleted"; echo ("<br />"); mysql_close($db_link); } elseif (isset($price)) { $link = mysql_connect('mysql6.******.com', '******', '*****') or die('Could not connect: ' . mysql_error()); mysql_select_db('*****') or die('Could not select database'); $query = ("UPDATE listings SET streetaddress='$streetaddress', city='$city', price='$price', squarefeet='$squarefeet', bed='$bed', Fbath='$Fbath','$Hbath', reo='$reo', agent='$agent', pic='$pic' WHERE reo='$reo'"); mysql_query($query); echo ($sql); echo "Record Updated"; mysql_close($link); } if ($i > $num) { break; } $i++; } if ($sql) { echo "Success!"; echo $sql or die("could not connect to the database"); } elseif (!$sql) { echo ("FAILED TO INPUT DATA <p><a href=\"../Members/Error.htm\">CLICK HERE</a></p>"); } ?> Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453772 Share on other sites More sharing options...
jmac2501 Posted January 30, 2008 Author Share Posted January 30, 2008 nevermind I fixed it. Added $price = ""; to clear it. Link to comment https://forums.phpfreaks.com/topic/88613-solved-delete-from-database/#findComment-453854 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.