I'm working on a cart progaram, early stages. I have several areas where i echo variable results, etc... and I track it through phpmyadmin
The INSERT is adding an empty row and indexing seems to be inconsistent. I would like to add just the one row (at the end/bottom).
My code is as follows:
I post an invcode from a order button click. this works!
I retrieve data from the corresponding record in table rockid. this works!
The insert into usercart1 never shows more than 1 row affected! yet,
on the first submission (i.e., delete all usercart records in phpmyadmin prior to submitting) I get a blank row then the data that was sent.
my second submission inserts the data between the blank and first filled row (not sure if this is a consistent trend) I think it puts a new submitted invcode row at the top sometimes???)
Anyway I would like one row inserted at a time from top to bottom
PHP Code:
//** Performing SQL query (single item sent from order button click) **
$sentcode = $_POST["invcode"];
$query = "SELECT picpath, itemcode, itemdesc, itemqty, itemprice FROM rockid WHERE itemcode='$sentcode'";
$result = mysql_query($query) or die('Query failed:(here!) ' . mysql_error());
What I see is you having $query equal to the insert string. Then you have $result = mysql_query($query) which looks to me as having result then re-insert the information. I may be wrong, but this is what caught my eye.
I don't see anything there that would cause the insert statement to process more than once, and I don't see anything in the insert statement that would cause more than one row to be inserted.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
The program works just fine in IE and Opera (i.e., NO EXTRA BLANK ROWS INSERTED)
I end the page with a SELECT * TABLE usercart1 query and echo. When used in conjuction with a Prior Delete:
PHP Code:
//** delete blank recors item to usercart1 **
$query = "DELETE FROM usercart1 WHERE itemcode=''";
//echo "Updated records: %d\n", mysql_affected_rows();
$result = mysql_query($query) or die('Query failed:(or here!) ' . mysql_error());
it shows that Firefox is ending the page showing me the usercart1 table and no extra blank rows, yet if i go directly to myphpadmin; THERE IT IS, AN EXTRA ROW OF BLANK INFO!
Well I was thinking it was a Firefox issue in the sense that:
1) This does not occur at all with IE and Opera, and
2) The Form action POST and corresponding data (in this case I only have one form field set with the name of invcode and I set that = to $sentcode (see below). So when any of the order buttons is clicked the value of form 'invcode' is first updated with that products information, then the form is processed, or sent to the order.php page. This page uses the (only one POST item sent) to update my cart TABLE usercart1, this is done with an INSERT.
Therefore I think some freaky code has been overlooked.
Or between when the order button is clicked and when my Firefox Browser is submitting the POST form data to be proccessed in order.php.
Remember all three browsers do this same thing.
Order of events:
1) Click order button
2) Update hidden formfield 'invcode' with the product code of the item selected.
3) Form action to order.php
From below:
First SELECT the record/row data FROM rockid that corresponds with the item $sentcode.
Then write those results to an array and echo that out.
Then SELECT * FROM usercart1 and echo that out
Then a DELETE FROM usercart1 WHERE $sentdata ="" (comment this one out sometimes as I check)
Then INSERT INTO usercart1 ($sentdata info)
Then SELECT * FROM usercart1
Then turn that into an array that I use to display whats in the cart
Then at the end I re-echo usercart1
With Firefox: (with DELETE commented out)
first item click:
All the code is processed and both usercart1 echos appear to be complete and correct (first echo is empty and second has one item).
In myphpadmin there is a blank extra row. (either the usercart1 querys did not detect this or it was put there after the order.php page was run.
second item click:
All the code is processed and both usercart1 echos show the extra blank line.
In myphpadmin there is a blank extra row, but just one not two. (there is always just one extra row never more and if i delete it out with myphpadmin the next click will just add another one!
The DELETE statement does help me keep things in line for what I want to do, but seems very uneccessary!
With IE and OPERA: (with DELETE commented out)
NEVER SEE AN EXTRA ROW AT ANY TIME WITH DELETE COMMENTED OUT OR NOT
(over the next few days i'll try to run some simple pages with INSERTS in other tables and see what happens)
Order of events:
1) Click order button
2) Update hidden formfield 'invcode' with the product code of the item selected.
3) Form action to order.php
How are you doing #2? Using JS? That's probably the culprit. if you do a var_dump on the item as it gets sent, you'd probably find the issue (I've had cases where FF adds an extra , to some things.) So this can be a FF issue assuming #2 is done via JS. But you should look at that for the problem.
Sorry if you mentioned that before, I must have missed it.
Hi everyone,
I seem to have the same exact problem than that guy. I'm running a CMS engine, and it only happens on 1 of my query pages. Here are the codes :
if(checkBan() == false){
include "template/_main.php";
}
else{
include "template/_banned.php";
}
If the user isn't banned :
PHP Code:
<?
checkUser('4');
if(!isset($_GET['id'])){
echo "
You must select an user to ban.
";
}
else{
if(!isset($_GET['confirmed'])){
echo "
Are you sure you want to ban this user? <a href=\"index.php?content=admin&view=users&action=ban&id=$_GET[id]&confirmed=1\">Yes</a> <a href=\"index.php?content=admin&view=users&action=list\">No</a>
";
}
else{
$userSql = mysql_query("SELECT last_ip FROM ".$table_suffixe."users WHERE user_id = ".$_GET['id']);
$userRow = mysql_fetch_array($userSql);
$userInsert = new mySQL;
$userArray = array("user_id" => $_GET['id'], "ip" => $userRow['last_ip']);
$userInsert->sqlInsert('bans',$userArray);
echo "
The user has been banned. You will now be redirected to the users list.
<meta http-equiv=\"refresh\" content=\"2;url=index.php?content=admin&view=panel\">
";
}
}
?>
And the query function :
PHP Code:
function sqlInsert($insertTable,$insertArray){
$table_suffixe = 'dvengine_';
$insertKeys = implode(",",array_keys($insertArray));
if((mysql_query("SELECT $insertKeys FROM ".$table_suffixe.$insertTable) == true) && isset($insertArray)){
foreach($insertArray as $key => $value){
$insertArray[$key] = nl2br(addslashes($value));
}
$insertValues = implode("','",$insertArray);
$insertValues = "'".$insertValues."'";
mysql_query("INSERT INTO ".$table_suffixe.$insertTable." (".$insertKeys.") VALUES (".$insertValues.")");
}
}
Anyone has an idea about this? It most likely isn't the background-image issue because I actually don't load any background picture ...
Best regards,
Francis B.
Last edited by Francky683; 06-02-2006 at 04:42 PM.
Bookmarks