Note that there are some explanatory texts on larger screens.

plurals
  1. POsee if textarea value exists in array
    primarykey
    data
    text
    <p>I have a conundrum. I have a simple form. A dynamic select list that is pulling technician names from a database and a textarea. The form is intended for me to paste zipcodes (in this format: 12345,12346,12347,etc) and for them to be inserted into a table one by one along with the tech's id. This works great! However, just any zip won't do - as I have to have a license to work in it. </p> <p>To get around that annoying issue, I created a table that has a list of zip codes I do service. SO, I have a recordset of those zip codes, I'm inserting them into an array, and then checking to see if value from textarea exist in that array before it is inserted. Except, it isn't working. The array printed fine - so that works. The insert stuff works fine - as it did before I added the in_array stuff. Together - they're like my girlfriend and me. It just doesn't freaking work together.</p> <p>Here is my code:</p> <pre><code>//This is my recordset and where I'm putting it into an array mysql_select_db($database_localhost, $localhost); $query_Recordset1 = "SELECT zip_code FROM zip_code"; $Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $results = array(); do { $results[] = $row_Recordset1; } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); //DONE ARRAY //Now I'm taking zipcodes pasted in textarea so they can be inserted one at a time $zipcodes = explode(",", $_POST['textarea']); $countZips = (count($zipcodes)); if ((isset($_POST["MM_insert"])) &amp;&amp; ($_POST["MM_insert"] == "form1")) { foreach($zipcodes as $key=&gt;$value) { while ($countZips &gt;= 1) { $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } //DONE textarea //If statement to see if value exists in array if (in_array($value, $results)){ $insertSQL = sprintf("INSERT INTO zip_zip (zip_code, tech_id) VALUES (%s, %s)", GetSQLValueString($value, "int"), GetSQLValueString($_POST['select'], "int")); mysql_select_db($database_localhost, $localhost); $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error()); $countZips--; } else { $countZips--; } //Done value exists //Now moving to next page when done } $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&amp;" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } } //END </code></pre> <p>Does anyone know what in the world the problem is? Also - if someone edits this and makes the code formatting pretty - how do you do that?</p> <p>Thanks!</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.
    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