2

MY custom database, is getting data from a form, and is inserted when the consumer reach a certain page. I can't make it any other way (because of reasons)

the page is an easy access page, and people (and bots) can reach it easy. It result of a lot of empty rows in my table, and I want to write a code that delete all empty row, each time they reach the that page.

When I'm inserting the data I use below code:

$conn = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "INSERT INTO mage_emailorder (emailorder_id, order_date, product_name, location, date_for, name_title, email, company, adress, zipcode, city, phone, ean, comment, order_done, number_of_entries)
VALUES (NULL, '$newdate', '$conferance_name', '$hotel', '$datefor', '$ogtitel', '$email', '$virksomhed', '$adresse', '$postnr', '$by', '$telefon', '$ean', '$kommentarer', '0', '$entries')";



try {
    $conn = Mage::getSingleton('core/resource')->getConnection('core_write');
    $conn->query($sql);
} catch (Exception $e){
    echo $e->getMessage();
}

the deleting code

$sql2 = "DELETE FROM mage_emailorder WHERE product_name IS NULL;"



try {
    $conn = Mage::getSingleton('core/resource')->getConnection('core_write');
    $conn->query($sql2);
} catch (Exception $e){
    echo $e->getMessage();
}
?>

My code for deleting is giving me error in the try{ }catch(){}, can some one help me with why?

  • Can you please attach your error in question – Jayesh Patel Mar 11 '16 at 8:46
  • syntax error, unexpected 'try' (T_TRY) in /var/www/ifp.dk/public_html/app/design/frontend/ultimo/default/template/kolorcat/success.phtml on line 44 – Patrick Knudsen Mar 11 '16 at 9:11
  • Please try @talk2toyin anwser, it should fix your problem. – Jayesh Patel Mar 11 '16 at 9:17
4

I don't have enough rep here yet so, I can't add a comment. But from the error you got:

syntax error, unexpected 'try' (T_TRY) in /var/www/ifp.dk/public_html/app/design/frontend/ultimo/default/template/kolorcat‌​/success.phtml on line 44 

You have this before the try / catch block:

$sql2 = "DELETE FROM mage_emailorder WHERE product_name IS NULL;"

when it should actually be:

$sql2 = "DELETE FROM mage_emailorder WHERE product_name IS NULL";

Also, isn't there a way to prevent insert if values are not set ? I think you should give that a thought. It'd save you the overhead cost of this delete query :)

  • yeah i know, but im just doing damage control uintill i can build my own. and THANKS a lot! – Patrick Knudsen Mar 11 '16 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.