texmansru47 Posted July 10, 2008 Share Posted July 10, 2008 This may be a stupid question, but I am seeing some weird results. I have a form with PHP code behind it to get two values for my database. I run a search from a value passed from the parent form and it works, and the INSERT INTO command takes that data no problem into the proper table, but the two values that the popup require the User to enter are not being posted to the database. Here is the code I have thus far: <form method="POST" name="Recv" action="entry.php"> <table width="400" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="2" bgcolor="#000000"><span class="style1">Recv Control</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">Asset 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" /></td> </tr> </table> </form> <?php $BatchNumData=$_GET['param1']; echo "Your Batch Number is:\n$BatchNumData"; // Connect to mysql database $con = mysql_connect("localhost","users","xxxx") or die('Connection: ' . mysql_error());; mysql_select_db("snatest", $con) or die('Database: ' . mysql_error()); // Insert form values into database $copy = mysql_fetch_array(mysql_query("SELECT * FROM `batch` WHERE `BatchNum`= '$BatchNumData'")) or die(mysql_error()); // ^^ SELECT THE DATA TO BE COPIED ^^ @mysql_query("INSERT INTO `recv` (`BatchNum`, `1Num`, `SerNum`, `ProdNum`, `ModelSku`, `ModelType`, `DateRecv`) VALUES ('" . $copy['BatchNum'] . "', '" . $copy['1Num'] . "', '" . $_POST[serNum] ."', '" . $_POST[ProdNum] ."', '". $copy['Sku'] ."', '". $copy['Type'] ."', Now())") or die(mysql_error()); mysql_close($con); ?> The two $_POST commands do not seem to be working, since in the database these values are blank. I use the same code for a standard form I have and it works fine. So would the $_POST commands work differently atfer being spawned by a javascript? Just cannot figure it out. Thanks, Texman Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/ Share on other sites More sharing options...
discomatt Posted July 10, 2008 Share Posted July 10, 2008 I dont see you checking to see if the form has been submitted :| Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586650 Share on other sites More sharing options...
tibberous Posted July 10, 2008 Share Posted July 10, 2008 Lol... the $_POST command... Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586671 Share on other sites More sharing options...
texmansru47 Posted July 10, 2008 Author Share Posted July 10, 2008 discomatt, Please elaborate. I'm a newbie to php and javascripting so any insight would be greatly appreciated. Thanks, Texman Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586674 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 How come you have '' around ALL of your array keys except the two $_POST ones? Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586678 Share on other sites More sharing options...
texmansru47 Posted July 10, 2008 Author Share Posted July 10, 2008 Do you mean the single '? I read that somewhere to do that... not sure why. I'm self teaching myself php so I gather my data from tutorials, books and and these forums. I see what the problem seems to be is that when the popup is opened, I get a record in my database without even typing in data. Anyone had a cure for that? Sound even crazier than my first question. But it seems when the popup entry form is opened, it generates a record... with blanks for my two values required. Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586697 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Because you don't check to see if the form was actually submitted in your PHP code. =/ Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586699 Share on other sites More sharing options...
texmansru47 Posted July 10, 2008 Author Share Posted July 10, 2008 OK... How would I do that? Again, I'm new to this and I have not come across this yet. Texman Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586703 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 if (isset($_POST['submit'])) { //Your code here } Also, change: <td><input type="submit" value="Submit" /></td> To: <td><input type="submit" value="Submit" name="submit" /></td> Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586706 Share on other sites More sharing options...
texmansru47 Posted July 10, 2008 Author Share Posted July 10, 2008 just to make sure what you are saying is for: if (isset($_POST['submit'])) { //Your code here } I would place that before my sql queries and INSERT? Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586714 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 You'd place it AROUND the whole thing. if (isset($_POST['submit'])) { //some code //insert query //anything else, blah blah blah } Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586715 Share on other sites More sharing options...
texmansru47 Posted July 10, 2008 Author Share Posted July 10, 2008 Well I placed it just after the <? php start call and the final } bracket before the ?> tag. Not nothing is being added to my database. I take it that this is working then? Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586725 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Did you make that change to the <input> tag that I mentioned? And yes, I think it's working. =P Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586727 Share on other sites More sharing options...
texmansru47 Posted July 10, 2008 Author Share Posted July 10, 2008 Yes I did. So I believe I have a form that is not working correctly. Any suggestions as to where I should start to look for solutions? Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586731 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Show me your full, current code please? Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586734 Share on other sites More sharing options...
texmansru47 Posted July 10, 2008 Author Share Posted July 10, 2008 Here is what I got: <html> <head> <title>Receiving - Part Two</title> </head> <body bgcolor="#C0C0C0"> <b><img border="0" src="logo1.jpg" width="45" height="44"> <font face="Arial" color="#000080">Product Entry</font></b><font face="Arial" color="#000080"> <hr> <P> <form method="POST" name="Recv" action="entry.php"> <table width="400" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="2" bgcolor="#000000"><span class="style1">Receiving</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">Asset 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" name="submit" /></td> </tr> </table> </form> <?php if (isset($_POST['submit'])) { $BatchNumData=$_GET['param1']; echo "Your Batch Number is:\n$BatchNumData"; // Connect to mysql database $con = mysql_connect("localhost","user","xxxxx") or die('Connection: ' . mysql_error());; mysql_select_db("test", $con) or die('Database: ' . mysql_error()); // Insert form values into database $copy = mysql_fetch_array(mysql_query("SELECT * FROM `batch` WHERE `BatchNum`= '$BatchNumData'")) or die(mysql_error()); // ^^ SELECT THE DATA TO BE COPIED ^^ @mysql_query("INSERT INTO `recv` (`BatchNum`, `1Num`, `SerNum`, `ProdNum`, `ModelSku`, `ModelType`, `DateRecv`) VALUES ('" . $copy['BatchNum'] . "', '" . $copy['RTSNum'] . "', '" . $_POST[serNum] ."', '" . $_POST[ProdNum] ."', '". $copy['Sku'] ."', '". $copy['ModelType'] ."', Now())") or die(mysql_error()); mysql_close($con); } ?> </body> </html> Without your additional code (the if statement) I get a blank record in my database of "0" value for the ProdNum and a blank for the SerNum but I get the proper value of from the SELECT command and INSERT (the $copy variables). I don't understand why this form is processing without any interaction from me. This code is the code from the parent form that calls this popup (javascript involved): <head> <title>Receiving</title> </head> <body bgcolor="#CCCCCC"> <b><img border="0" src="logo1.jpg" width="78" height="77"> <font face="Arial" color="#000080">Receiving - Part One</font></b><font face="Arial" color="#000080"> <P> <form method="POST" name="Recv" action="recvbatch.php"> <table width="550" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="2" bgcolor="#000000"><span class="style1">Batch/RA Receiving Start</span></td> </tr> <tr> <td bgcolor="#FFCC66">RA Number: </td> <td bgcolor="#CCCCCC"><input name="BatchNum" type="text" id="BatchNum"></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit Batch Request" /></td> </tr> </table> </form> </body> <center> <hr> <table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000"> <tr> <td width="140" align="center"><b>RA Number</b></td> <td width="130" align="center"><b>Prod Number</b></td> <td width="75" align="center"><b>KU</b></td> <td width="140" align="center"><b>Type of Repair</b></td> <td width="140" align="center"><b>Model</b></td> <td width="60" align="center"><b>Qty</b></td> <td width="140" align="center"><b>Model Type</b></td> <td width="130" align="center"><b>Received Date</b></td> </tr> <?php error_reporting(E_ERROR | E_WARNING | E_PARSE); $con = mysql_connect("localhost","users","xxxx") or die('Connection: ' . mysql_error());; mysql_select_db("test", $con) or die('Database: ' . mysql_error()); ?><? $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 results print ("<tr>"); print ("<td>$variable1</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>"); } } else { echo "No results returned"; } } else { echo "Query error: ".mysql_error(); } $batch1 = $variable1; mysql_close($con); ?> </table> <script language="JavaScript" type="Text/JavaScript"> //Will call the popup Window for Product Entry. var fifteenth;var sixteenth;var seventeenth; function eighteenth(nineteenth,twentieth) { seventeenth=eval("document.getElementById('"+nineteenth+"')");sixteenth=twentieth;fifteenth=seventeenth.childNodes[0].nodeValue;seventeenth.childNodes[0].nodeValue=twentieth;} function first2() { seventeenth.childNodes[0].nodeValue=fifteenth;} </script> </center> <center> <script> <!-- function openpopup(url, windowtarget) { window.open( url, windowtarget, 'width=570,height=290,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0'); } // --> </script> <a href="entry.php?param1=<?php echo $batch1; ?>" target="entry" OnClick="openpopup(this.href, 'entry'); return false;">Entry Screen</a> </center> <p><a href="receiving.html">Return to Main Receiving Page</a></p> I hope this helps, Texman Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586752 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 The form was processing because you had no checks to see whether or not it was actually submitted. It should work once submitted now. Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586753 Share on other sites More sharing options...
texmansru47 Posted July 10, 2008 Author Share Posted July 10, 2008 So you are indicating that my form should work now... without changing anything? Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586874 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 I don't see why it wouldn't. Did you try? Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-586877 Share on other sites More sharing options...
texmansru47 Posted July 11, 2008 Author Share Posted July 11, 2008 Yes I did... The form comes up and I can enter data, but nothing is written to the database. Before that IF statement, the data from the SELECT query is put in, but the $_POST inputs are still not working. Link to comment https://forums.phpfreaks.com/topic/114136-does-the-_post-command-work-differently-in-a-popup-spawned-by-a-javascript/#findComment-587531 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.