Jump to content

A couple of issues - Duplicate Error Key (but no Dups) and Cannot write to MySql


texmansru47

Recommended Posts

I have been working on this page for now three weeks, and everytime I get something to work something else breaks.  Here is what I'm trying to do: 

 

1) Pass a variable from the parent form to a popup form (working)

2) Use that passed variable to process a SELECT * query from table 1 - (working)

3) On the second form (the popup spawned from the parent form) the user has to enter in two pieces of information (ProdNum and SerNum).

4) then I run a INSERT query to input some of the data from table 1 (from the SELECT Query I ran) as well as the two $_POST variables the user just entered (ProdNum and SerNum)

5) I run this in a loop using a counter that increments by one each pass agains the QTY value of the Batch that these products are being entered into the database for.

 

Here has been my problems:

1) At first when I pass the variable from the parent form to the popup entry form a "ghost record" was entered (no data from the user input - only the data from the SELECT query... this happens as soon as the form is presented... the user has no time to process anything, not even pressing the SUBMIT button.  I tired the !isset() function to no avail... at all... never worked once.  So I added a DELETE query to remove any records with the ProdNum set as '0'.  Seems to work.

2) The queries all work... the SELECT, the INSERT and the DELETE when I put in a straight value instead of the value of the passed variable (instead of a variable I set to equal the passed variable I put in a number like '1') everything works... data is written to the database appropriately, and the counter works... the only problem is I get the following error:

 

Your Batch Number is: Duplicate entry '4294967295' for key 1

 

where '4294967295' is any number you enter... and there are no duplicates at all... regardless the number entered... this error occurs, but the data is written to the database properly.

 

3) If I add the the variable that was passed to the second popup form the INSERT query does not input any data into the table while I have the DELETE query active.  But if you run a print_r against the SELECT query all the data is pulling correctly... I have also inputted a few echo command to list the values of particular fields being SELECTED and they are all there.  If I deactive the DELETE query only the initial blank record I mentioned earlier is inputted into the table and no other record I try to enter is.

 

Here is the code I have for the popup where it seems all the problems are:

 

<?php 

$BatchNumData=$_GET['param1']; 
echo "Your Batch Number is:\n$BatchNumData"; 


// Connect to mysql database 
$con = mysql_connect("localhost","user","xxxx") or die('Connection: ' . mysql_error());; mysql_select_db("snatest", $con) or die('Database: ' . mysql_error()); 

// Insert form values into database 
$sql = mysql_fetch_array(mysql_query("SELECT * FROM `batch` WHERE `BatchNum`= '$BatchNumData'")) or die(mysql_error()); 
// ^^ SELECT THE DATA TO BE COPIED ^^ 

$Batch=$sql['BatchNum']; 
$Qty=$sql[Qty]; 
$RTSNum=$sql['1Num']; 
$ModelType=$sql['ModelType']; 
$Sku=$sql['Sku']; 
$Card=$sql['Card']; 
$growit = 1; 

while ($growit <= $Qty) { 
@mysql_query("INSERT INTO `recv` (`BatchNum`, `ProdNum`, `SerNum`, `ModelType`, `ModelSku`, `1Num`,`Card`, `DateRecv`) VALUES ('$Batch', '" . $_POST['ProdNum'] . "', '" . $_POST['SerNum'] . "','$ModelType','$Sku','$RTSNum', '$Card', Now())") or die(mysql_error()); 
@mysql_query("DELETE FROM `recv` WHERE `ProdNum` = 0"); 

$growit = $growit + 1; } 
echo "<br>Your QTY is:\n $Qty"; 

mysql_close($con); 
?>

 

Now I'm trying to solves these problems but I cannot seem to figure out where to start.  On the database here are the vitals:

 

The Primary Key is the ProdNum

No Auto Increment

Class = BigInt[15]

Must be Unique

 

Not sure if that helps.  At this point I cannot move forward since I really do not know what to do.  I would love to get the !isset() function to work but it is just not.

 

BTW - the popup form portion of this page is on the top part of the php page where this above listed code is located:  Here is the form coding:

 


<form method="post" name="Recv" action="entry.php"><font color="#000080" face="Arial">
  <table border="0" cellpadding="3" cellspacing="2" width="400">
    <tbody>
      <tr style="color: rgb(255, 255, 255); font-weight: bold;">
        <td colspan="2" bgcolor="#000000"><span class="style1">Receiving Module</span></td>
      </tr>
      <tr>
        <td bgcolor="#ffcc66">Serial Number: </td>
        <td bgcolor="#cccccc"><input name="SerNum" id="SerNum" type="text"></td>
      </tr>
      <tr>
        <td bgcolor="#ffcc66" width="135">Prod Number:</td>
        <td bgcolor="#cccccc" width="300"><input name="ProdNum" id="ProdNum" type="text"></td>
      </tr>
      <tr>
        <td> </td>
        <td><input value="submit" name="submit" type="submit"></td>
      </tr>
    </tbody>
  </table>

 

Honestly I'm a newbie to development and my hat is off to you all who can figure this stuff out.  I have a trial by fire since I am an owner of this company with 20 years Infrastructure background... no development, so if anyone out there could throw me a bone I would greatly appreciate it.

 

Thanks,

Sader,

 

I guess I do not understand.... The variable I have set is:  $Qty=$sql[Qty]... it seems to work since I get a value when I run the print_r($sql) command.

 

unkwntech:

 

That field will be for data inputting into the database from the users... I thought that cannot be auto increment.... is that a wrong assessment?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.