Jump to content

Temporary table retrieve corrupt data


ruano84

Recommended Posts

Hi,
I am having throuble with a temporary table. I can create it, fill it and even select it, but every time i access it, the data is corrupted. This is the code to create it:
(The query is supposed to be ?sec=xx&art=yy&cant=zz)

[code]
<?php
$ref=apache_request_headers();
setcookie("origen",$ref['Referer']);
setcookie("query",$_SERVER['QUERY_STRING']);
session_start();
if(!isset($_SESSION["nombre"])){
session_write_close();
header("location:ingresar.php"); //To the registration page
}else
{
$dbh=mysql_pconnect ("localhost", "interglo_admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db("interglo_Users");
$id=session_id();
parse_str($_COOKIE["query"]);
mysql_query("CREATE TEMPORARY TABLE IF NOT EXISTS cart$id (cat char(255),id int, cantidad int)");
mysql_query("INSERT INTO cart$id (cat,id,cantidad) VALUES ('$sec','$art','$cant')");
header("location:".$_COOKIE["origen"]);
}
?>
[/code]

And this is the code for access it:

[code]
<?php
session_start();
if($err==0){
$_SESSION["nombre"]=$row[0]." ".$row[1];
$_SESSION["cedula"]=$row[2];
$_SESSION["fijo"]=$row[3]."-".$row[4];
$_SESSION["cel"]=$row[5]."-".$row[6];
$_SESSION["direccion"]=$row[7];
$_SESSION["email"]=$row[8];
if(isset($_COOKIE["query"])) header("location:add.php?".$_COOKIE["query"]);
}
if($_SERVER['QUERY_STRING']=="sec=v_cart"){
$dbh=mysql_pconnect ("localhost", "interglo_admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("interglo_Users");
echo mysql_error();
$res=mysql_query("SELECT * FROM cart$id"); //The shopping cart
echo mysql_error();
$aff=mysql_affected_rows();
echo $id." ".$aff."<br>";
echo mysql_error();
if($aff==0){
?>
A&uacute;n no has agregado art&iacute;culos a tu carro de compras.<br>
<?php
}else{
$dbh1=mysql_connect("localhost","interglo_admin");
mysql_select_db("interglo_productos"); //The products
for($i=0;$i<$aff;$i++){
$fetch=mysql_fetch_row($res);
echo $i." ".$fetch[0]." ".$fetch[1]."<br>";
$res1=mysql_query("SELECT * FROM ".$fetch[0]." WHERE id=".$fetch[1]);
echo mysql_error();
$fetch1=mysql_fetch_row($res1);
echo $fetch1[1]." ".$fetch[2]." ".$fetch[3]."<br>";
}
}

$id=session_id();
[/code]

I hope somebody can help me
Alexis RR
Link to comment
Share on other sites

After creating modifying etc. can you select it at the same page?
If you can on the same page but can't on the other then the script is not accessing the same temporary tables. Temporary tables last just a session and should be destroyed the moment you close the connection.
Link to comment
Share on other sites

Hi, thanks for answer.

In the script i create the table and insert the data, when i select, everything is fine, like a normal table. When i select the same table with the pconnect function (it's supposed to give me a reference of the last one), sometimes output that the table doesn't exists, sometimes it selects but retrieve just the first x rows and sometimes the data is ok.

Thanks again,
Alexis RR
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.