Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing multiple forms to a single MYSQL UPDATE query
    primarykey
    data
    text
    <p>First time dealing with passing multiple forms to a single UPDATE query (New to php)</p> <p>This script is pulling and displaying all data from a database table row(s) and displaying it via $currentadcode in textarea(s) Depending on how many rows in the database there are it repeats this code over and over to display the data with a limit then next page to see the rest.</p> <p>the textarea(s) name adcode$ID becomes adcode1 adcode2 adcode3 and the submit button(s) name editad$ID becomes editad1 editad2 editad3.</p> <pre><code>echo "&lt;div class=\"adcodearea\"&gt;"; echo "&lt;h2&gt;$ID : $adname&lt;/h2&gt;&lt;a href=\"?action=deletead&amp;IDnum=$ID\"&gt;Delete Ad&lt;/a&gt;&lt;br /&gt;\n"; echo "Preview :&lt;br /&gt;&lt;div class=\"adcode\"&gt;$currentadcode&lt;/div&gt;&lt;br /&gt; \n"; //echo "&lt;br /&gt;\n"; echo "&lt;form action=\"editad.php?action=editad\" name=\"addAD$ID\" method=\"post\"&gt;\n"; echo "AD code (can be any type of script) text link, javascript or banner :&lt;br /&gt;\n"; echo "Current AD Code :&lt;br /&gt;&lt;textarea name=\"adcode$ID\" wrap=\"physical\" cols=\"72\" rows=\"6\" onKeyDown=\"textCounter(document.addAD$ID.adcode$ID,document.addAD$ID.remLen$ID,5000)\" onKeyUp=\"textCounter(document.addAD$ID.adcode$ID,document.addAD$ID.remLen$ID,5000)\"&gt;$currentadcode&lt;/textarea&gt;"; echo "&lt;br /&gt;&lt;input readonly type=\"text\" name=\"remLen$ID\" class=\"adcountdown\" size=\"2\" maxlength=\"3\" value=\"5000\"&gt;Characters Left \n"; echo "&lt;input type=\"submit\" name=\"editad$ID\" class=\"adsubmit\" value=\"Edit AD Code\"&gt;&lt;/form&gt;\n"; echo "&lt;/div&gt;"; echo "&lt;br /&gt;&lt;hr /&gt;"; //echo "$letknownedited"; </code></pre> <p>It passes the data within the textarea to editad.php which is received by this code.</p> <pre><code>if ($_GET['action'] == "editad") { // Edit AD $newadcode = mysql_real_escape_string($_POST['adcode' . $ID]); $doedit = "UPDATE `adgate`.`ads` SET `ads`.`adcode` = '$newadcode' WHERE `ads`.`ID` = '$ID' LIMIT 1" or die(mysql_error()); $retval = mysql_query( $doedit, $connection ); if(! $retval ) { die('Could not update data: ' . mysql_error()); } echo "Updated data successfully\n"; //header("Location: displayads.php"); </code></pre> <p>But it only gets the first textarea's data on the page / Lowest adcode$ID - even if you edit the last one on the page. If you try to edit any other ad other than the first one (adcode8) on the page it throws this</p> <ul> <li>Notice: Undefined index: adcode8 in C:\Program Files (x86)\Zend\Apache2\htdocs\adgate\editad.php on line 29</li> </ul> <p>The first ad currently on the page (adcode8).</p> <p>So my thoughts where maybe pass the code to an IF, ELSEIF, ELSE but that wouldn't work since it could be an unlimited amount of ads.</p> <p>So that leaves HIDDEN form field which I wouldn't think I need to do since I'm passing a unique name=\"editad$ID\" to </p> <pre><code>$newadcode = mysql_real_escape_string($_POST['adcode' . $ID]); </code></pre> <p>Is that single line wrong or am what I'm trying to do impossible and need to try HIDDEN form fields? Here are the variables</p> <ol> <li>$ID (unique)</li> <li>$adname (unique but as the specific adname ex: Google Banner)</li> <li>$currentadcode (unique but as the specific code)</li> </ol> <p>Then..</p> <ul> <li>If hidden form field is required and it is not possible to pass dynamic submit button name to do the UPDATE then...</li> </ul> <p>If HIDDEN form field was like this</p> <pre><code>&lt;input type="hidden" name="$ID" value="$ID"&gt; </code></pre> <p>How would I adjust this code and would I even pass the</p> <p>$newadcode = mysql_real_escape_string($_POST['adcode' . $ID]);</p> <p>OBJECTIVE : To allow edibility of any TEXTAREA and UPDATE only that code/row in the MYSQL database</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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