0

hello friends.
i have a function in where i move all table content to another table and delete from preview table, the DELETE DON'T work i can't understund why but here is my code i need your helps friends all your reply count for me.

$query_suppr_panier = sprintf ("DELETE FROM panier WHERE id = %s ",
                                   GetSQLValueString($row_panier['id'], "int"));
    mysql_select_db($database_marketbase, $zmarketbase);
    $Result = mysql_query ($query_suppr_panier, $marketbase) or die (mysql_error());
    $compteur= $compteur+1;
    }
}
2
Contributors
10
Replies
34
Views
3 Years
Discussion Span
Last Post by chrisschristou
Featured Replies
  • 1
    diafol 3,720   3 Years Ago

    You really only need to do this once in the page: mysql_select_db($database_marketbase, $marketbase); And: "Select id article,..." Shouldn't that be "SELECT id_article,..." or "SELECT id, article,..." Also "VALUE" should be "VALUES" It may be time to get an MySQL GUI - try SQLyog Community version. It should save you (and … Read More

0

Please stop using mysql_* functions. They're deprecated. I'm sure this has been pointed out to you many times.

What's this? $marketbase

I can't see it mentioned - I take it that;s supposed to be your link identifier, but from the mysql_select_db, the link identifier is $zmarketbase

0

apart mysql_* i don't know what to use and if i change now it will be hard for to find the way since my site is advanced to this way :(
$marketbase is my link $zmarketbase was a mistake but now the right code is

$query_suppr_panier = sprintf ("DELETE FROM panier WHERE id = %s ",
                                   GetSQLValueString($row_panier['id'], "int"));
    mysql_select_db($database_marketbase, $marketbase);
    $Result = mysql_query ($query_suppr_panier, $marketbase) or die (mysql_error());
    $compteur= $compteur+1;
    }
}

and still it don't delete/

0

It looks as though this code is inside a loop / conditional / function as there are close braces at the bottom. This should certainly not be part of a loop, although it probably is from the counter I see ($compteur).

Anyway...

echo $query_suppr_panier;
$Result = mysql_query ($query_suppr_panier, $marketbase) or die (mysql_error());

Have a look at the query printed to the screen. Does it look odd? If not just copy it from the screen and run it in phpmyadmin to see if it works.

BTW your counter will increment regardless of the success of the deletion

Edited by diafol

0

I tryed to get out from loop but still id don't delete.
I use this code

$Result1 = mysql_query($query_lignecommande, $marketbase) or die(mysql_error());
$query_suppr_panier = sprintf ("DELETE FROM panier WHERE id = %s ",
                                   GetSQLValueString($row_panier['id'], "int"));
    mysql_select_db($database_marketbase, $marketbase);
    echo $query_suppr_panier;
    $Result = mysql_query ($query_suppr_panier, $marketbase) or die (mysql_error());
    $compteur= $compteur+1;
    }
}

AND I GET this on screen DELETE FROM panier WHERE id = NULL DELETE FROM panier WHERE id = NULL DELETE FROM panier WHERE id = NULL
i tryed this in phpmyadmin

$query_suppr_panier = sprintf ("DELETE FROM panier WHERE id = %s ",
                                   GetSQLValueString($row_panier['id'], "int"))

and i got syntax error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query_suppr_panier = sprintf ("DELETE FROM panier WHERE id = %s ", ' at line 1

0

i tryed this in phpmyadmin

Really?

The screen should have shown you that the id was not being placed into the SQL.

$row_panier['id']

is not being placed into the query. And if you paste anything into phpmyadmin - ensure that it's SQL and not php - it doesn't like it.

0

Well, if $row_panier is not set, I would imagine that you'd want to check that out. As we do not have your code, I cannot really suggest much else.

Edited by diafol

0

okay so here is whole code

mysql_select_db($database_marketbase, $marketbase);
    $query_commande = sprintf("Select id, subtotal
                               FROM commande
                               WHERE client ='".$_SESSION['MM_Username']."'
                               ORDER BY id DESC");
$commande = mysql_query($query_commande, $marketbase) or die(mysql_error());
$row_commande = mysql_fetch_assoc($commande);
$totalRows_commande = mysql_num_rows($commande);

mysql_select_db($database_marketbase, $marketbase);
$query_panier = sprintf("Select id article, SKU, quantity, shipping, prix, total
                        FROM panier
                        WHERE client ='".$_SESSION['MM_Username']."' ");
$panier = mysql_query($query_panier, $marketbase) or die (mysql_error());
$totalRows_panier = mysql_num_rows($panier);
$compteur = 0;  
while ($row_panier = mysql_fetch_assoc($panier) and $compteur < $totalRows_panier)
{
    $query_lignecommande = sprintf("INSERT 
                                    INTO lignecommande(
                                    commande, article, sku, prix, quantity, shipping, subtotal, total) VALUE ( %s, %s, %s, %s, %s, %s,%s, %s)",
                                    GetSQLValueString($row_commande['id'], 'int'),
                                    GetSQLValueString($row_panier['article'], 'text'),
                                    GetSQLValueString($row_panier['SKU'], 'text'),
                                    GetSQLValueString($row_panier['prix'],"double"),
                                    GetSQLValueString($row_panier['quantity'], 'int'),
                                    GetSQLValueString($row_panier['shipping'],"double"),
                                    GetSQLValueString($row_commande['subtotal'],"double"),
                                    GetSQLValueString($row_panier['total'],"double"));
mysql_select_db($database_marketbase, $marketbase);
$Result1 = mysql_query($query_lignecommande, $marketbase) or die(mysql_error());
$query_suppr_panier = sprintf ("DELETE FROM panier WHERE id = %s ",
                                   GetSQLValueString($row_panier['id'], "int"));
    mysql_select_db($database_marketbase, $marketbase);
    echo $query_suppr_panier;
    $Result = mysql_query ($query_suppr_panier, $marketbase) or die (mysql_error());
    $compteur= $compteur+1;
    }
}
?>
</body>
</html>
<?php
mysql_free_result($panier);
mysql_free_result($commande);
?>mysql_select_db($database_marketbase, $marketbase);
    $query_commande = sprintf("Select id, subtotal
                               FROM commande
                               WHERE client ='".$_SESSION['MM_Username']."'
                               ORDER BY id DESC");
$commande = mysql_query($query_commande, $marketbase) or die(mysql_error());
$row_commande = mysql_fetch_assoc($commande);
$totalRows_commande = mysql_num_rows($commande);

mysql_select_db($database_marketbase, $marketbase);
$query_panier = sprintf("Select id article, SKU, quantity, shipping, prix, total
                        FROM panier
                        WHERE client ='".$_SESSION['MM_Username']."' ");
$panier = mysql_query($query_panier, $marketbase) or die (mysql_error());
$totalRows_panier = mysql_num_rows($panier);
$compteur = 0;  
while ($row_panier = mysql_fetch_assoc($panier) and $compteur < $totalRows_panier)
{
    $query_lignecommande = sprintf("INSERT 
                                    INTO lignecommande(
                                    commande, article, sku, prix, quantity, shipping, subtotal, total) VALUE ( %s, %s, %s, %s, %s, %s,%s, %s)",
                                    GetSQLValueString($row_commande['id'], 'int'),
                                    GetSQLValueString($row_panier['article'], 'text'),
                                    GetSQLValueString($row_panier['SKU'], 'text'),
                                    GetSQLValueString($row_panier['prix'],"double"),
                                    GetSQLValueString($row_panier['quantity'], 'int'),
                                    GetSQLValueString($row_panier['shipping'],"double"),
                                    GetSQLValueString($row_commande['subtotal'],"double"),
                                    GetSQLValueString($row_panier['total'],"double"));
mysql_select_db($database_marketbase, $marketbase);
$Result1 = mysql_query($query_lignecommande, $marketbase) or die(mysql_error());
$query_suppr_panier = sprintf ("DELETE FROM panier WHERE id = %s ",
                                   GetSQLValueString($row_panier['id'], "int"));
    mysql_select_db($database_marketbase, $marketbase);
    echo $query_suppr_panier;
    $Result = mysql_query ($query_suppr_panier, $marketbase) or die (mysql_error());
    $compteur= $compteur+1;
    }
}
?>
</body>
</html>
<?php
mysql_free_result($panier);
mysql_free_result($commande);
?>
1

You really only need to do this once in the page:

mysql_select_db($database_marketbase, $marketbase);

And:

"Select id article,..."

Shouldn't that be

"SELECT id_article,..."

or

"SELECT id, article,..."

Also

"VALUE" should be "VALUES" 

It may be time to get an MySQL GUI - try SQLyog Community version. It should save you (and us!) a lot of time

Edited by diafol

Votes + Comments
it worked this was helpfull
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.