Forum Moderators: coopster
Code from first form where the variable is collected to the second page: (the $_POST[BatchNum] is from the first form input).
$sql = "SELECT * FROM `batch` WHERE `BatchNum`= '$_POST[BatchNum]'";
$results = mysql_query($sql);
if ($results) { //this will check if the query failed or not
if (mysql_num_rows($results) > 0) { //this will check if results were returned
while($copy = mysql_fetch_array($results)) {
$variable1=$copy['BatchNum'];
$variable2=$copy['1Num'];
$variable3=$copy['Sku'];
$variable4=$copy['Type'];
$variable5=$copy['Model'];
$variable6=$copy['Qty'];
$variable7=$copy['ModelID'];
$variable8=$copy['RecvDate'];
//table layout for resultsprint ("<tr>");
print ("<td><a href='testrecv.php?variable1=".$variable1."'>".$variable1."</a></td>");
print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("<td>$variable5</td>");
print ("<td>$variable6</td>");
print ("<td>$variable7</td>");
print ("<td>$variable8</td>");
print ("</tr>"); }
<P>
<form method="POST" name="Option_Recv" action="testrecv.php">
<table width="400" border="0" cellspacing="2" cellpadding="3">
<tr>
<td colspan="2" bgcolor="#000000"><span class="style1">Receiving IMEI</span></td>
</tr>
<tr>
<td bgcolor="#FFCC66">Serial Number: </td>
<td bgcolor="#CCCCCC"><input name="SerNum" type="text" id="SerNum"></td>
</tr>
<tr>
<td width="135" bgcolor="#FFCC66">Prod Number:</td>
<td width="300" bgcolor="#CCCCCC"><input name="ProdNum" type="text" id="ProdNum"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit Data" /></td>
</tr>
</table>
</form>
<?PHP// Connect to mysql database
$con = mysql_connect("localhost","user","#*$!x") or die('Connection: ' . mysql_error());;
mysql_select_db("test", $con) or die('Database: ' . mysql_error());
$BatchNumData=$_GET['variable1'];
$growit= 0;
echo "Your Batch Number is:\n$BatchNumData";
// 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 ^^
//Set Variables for Scripting
$Batch=$sql['BatchNum'];
$Qty=$sql[Qty];
$1Num=$sql['1Num'];
$ModelType=$sql['ModelType'];
$Sku=$sql['Sku'];
$Card=$sql['Card'];
?>
<?PHP
@mysql_query("INSERT INTO `recv` (`BatchNum`, `ProdNum`, `SerNum`, `ModelType`, `Sku`, `1Num`,`Card`, `DateRecv`) VALUES ('$Batch', '" . $_POST['ProdNum'] . "', '" . $_POST['SerNum'] . "','$ModelType','" . $Sku . "','$1Num', '$Card', Now())") or die(mysql_error());
mysql_close($con);
?>
<?php
if (!isset($_POST['submit']) {
?>
//put for code here
<P>
<form method="POST" name="Option_Recv" action="testrecv.php">
<table width="400" border="0" cellspacing="2" cellpadding="3">
<tr>
<td colspan="2" bgcolor="#000000"><span class="style1">Receiving IMEI</span></td>
</tr>
<tr>
<td bgcolor="#FFCC66">Serial Number: </td>
<td bgcolor="#CCCCCC"><input name="SerNum" type="text" id="SerNum"></td>
</tr>
<tr>
<td width="135" bgcolor="#FFCC66">Prod Number:</td>
<td width="300" bgcolor="#CCCCCC"><input name="ProdNum" type="text" id="ProdNum"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit Data" /></td>
</tr>
</table>
</form>
<?php
} else {
//put form processing here
// Connect to mysql database
$con = mysql_connect("localhost","user","#*$!x") or die('Connection: ' . mysql_error());;
mysql_select_db("test", $con) or die('Database: ' . mysql_error());
$BatchNumData=$_GET['variable1'];
$growit= 0;
echo "Your Batch Number is:\n$BatchNumData";
// 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 ^^
//Set Variables for Scripting
$Batch=$sql['BatchNum'];
$Qty=$sql[Qty];
$1Num=$sql['1Num'];
$ModelType=$sql['ModelType'];
$Sku=$sql['Sku'];
$Card=$sql['Card'];
?>
<?PHP
@mysql_query("INSERT INTO `recv` (`BatchNum`, `ProdNum`, `SerNum`, `ModelType`, `Sku`, `1Num`,`Card`, `DateRecv`) VALUES ('$Batch', '" . $_POST['ProdNum'] . "', '" . $_POST['SerNum'] . "','$ModelType','" . $Sku . "','$1Num', '$Card', Now())") or die(mysql_error());
}
?>
Would this be along the lines?
if (!isset($_POST['ProdNum'] == 0)) {
$produ = $_POST['ProdNum'];
$sql = "DELETE FROM `snarecv` WHERE `ProdNum` = $produ";
} else {
I STILL get a blank page. No offense to anyone but I have NEVER been able to get the isset funciton to work... EVER! According to the php manual this is for validating variables in a boolean aspect (true or false). The problem I'm having is not validating whether or not someone pushed the SUBMIT button, because it is not happening. I need to delete the freaking ghost record that generated from the page beening called and posted... since I could not get the original code to work. But again, this stupid function is giving me a blank freaking page. This is killing me. I have a deadline I very past due on and I cannot even get to phase II of this page because the this BS. This is the only form I'm having trouble with and I know it is directly associated to the $_GET variable from the first form.
Since I'm getting a blank page my first assumption is this due to poor syntax.... but I cannot see where I'm messing up. Even on the PHP manual the syntax looks like me... kinda of like telling me to F up or something.
If anyone can see where this code is wrong and why I would get a blank page, PLEASE show what I'm doing wrong because I'm sick of staring at code that looks right to me.
And this !isset code is not working very well. How can a True False boolean such as this process multiple tasks? In addition how do I even know this code is running since no one has pressed the freaking SUBMIT button. As soon as the form is spawned (am trying from a javascript to a popup as well as a full php page - both get the same results). I would need it to delete the bad record then run the process I need ran (insert data in a loop until QTY has bene satisfied)... then on the FALSE side I would have to run the exact same code with a check to verify that there is no record with a "0" in the ProdNum field.
In addition, the Delete command I have is not working either. I have:
@mysql_query("DELETE FROM `recv` WHERE `ProdNum` = 0");
I have as well has nothing there since it is not deleting the record.
How come this one action is kicking my butt? I'm sure it is something Im not seeing or catching - but it would be nice to have some feedback to figure out what the heck is going on.