Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring query result in variable
    text
    copied!<p>I have a form where people can subscribe or unsubscribe to a newsletter(this works). The problem is that when I want to insert the data to a database I get a problem. The form itself is this:</p> <pre><code>&lt;form action="subscriptionsedit2.php?CusID=&amp;lt;?=$_GET["&gt; " name="frmEdit" method="post"&amp;gt; &lt;?php $objConnect = mysql_connect("localhost","root","root") or die(mysql_error()); $objDB = mysql_select_db("NAW"); $strSQL1 = "SELECT ID, Titel FROM Mail"; $strSQL = "SELECT * FROM Klant WHERE ID = '".$_GET["ID"]."' "; $objQuery = mysql_query($strSQL); $objQuery1 = mysql_query($strSQL1); $objResult = mysql_fetch_array($objQuery); if(!$objResult) { echo "Not found ID=".$_GET["ID"]; } else { ?&gt; &lt;fieldset&gt; &lt;legend&gt;Wijzig&lt;/legend&gt; &lt;table width="600" border="1"&gt; &lt;tr&gt; &lt;th width="91"&gt; &lt;div align="center"&gt; ID &lt;/div&gt; &lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div align="center"&gt; &lt;?=$objResult["ID"];?&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&lt;br&gt; &lt;table width="600" border="1"&gt; &lt;tr&gt; &lt;th width="91"&gt; &lt;div align="center"&gt; ID &lt;/div&gt; &lt;/th&gt; &lt;th width="91"&gt; &lt;div align="center"&gt; Subscribe &lt;/div&gt; &lt;/th&gt; &lt;th width="91"&gt; &lt;div align="center"&gt; Unsubscribe &lt;/div&gt; &lt;/th&gt; &lt;/tr&gt;&lt;?php $i = 0; while($objResult1 = mysql_fetch_array($objQuery1)) { $i++; ?&gt; &lt;tr&gt; &lt;td&gt; &lt;div align="center"&gt; &lt;?=$objResult1["ID"];?&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;div align="center"&gt; &lt;input type="checkbox" name="sub" value="10"&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt; &lt;div align="center"&gt; &lt;input type="checkbox" name="sub" value="90"&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt;&lt;?php } ?&gt; &lt;/table&gt; &lt;/fieldset&gt;&lt;!-- content --&gt;&lt;input type="submit" name="submit" value="Submit"&gt; &lt;input type="button" name="cancel" value="Cancel" onclick="window.location='klanten.php'"&gt; &lt;?php } mysql_close($objConnect); ?&gt; &lt;/form&gt; </code></pre> <p>On subscriptionsedit2.php The data will be inserted in the database like this:</p> <pre><code>mysql_connect('localhost','root','root'); mysql_select_db('NAW') or die (mysql_error()); $Klant_ID = $objResult["ID"]; $Mail_ID = $objResult1["ID"]; $Status = $_POST['sub']; $Datum = date("d-m-y"); $sql = mysql_query("INSERT INTO Subscriptions (Klant_ID, Mail_ID, Status, Datum) VALUES ('".$Klant_ID."', '".$Mail_ID."', '".$Status."', '".$Datum."')") or die (mysql_error()); </code></pre> <p>This is the error I get: Notice: Undefined variable: objResult in /var/www/Mail/subscriptionsedit2.php on line 16 Notice: Undefined variable: objResult1 in /var/www/Mail/subscriptionsedit2.php on line 17</p> <p>As you can see there is no value in the variables $Klant_ID and $Mail_ID . So my question is how do I store the Klant_ID (<code>&lt;?=$objResult["ID"];?&gt;</code>) and the Mail_ID (<code>&lt;?=$objResult1["ID"];?&gt;</code>) into a variable correctly? I hope this question is clear enough but if you have any questions about it just comment^^.If anyone has an idea on how to do this it would be great!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload