Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy row from table 1 to table 2
    text
    copied!<p>I need to copy a row from my table1 to my table2. I have a select that lists all the entries in an <code>&lt;option&gt;</code> from the table1, and when I choose an option, it needs to be inserted in the row (with the same name) in table2.</p> <p><strong>Trying to be more specific:</strong></p> <p>It's a form with fields that are inserted in table2, but one field is an option that lists the entries from table1. When they get submitted, they'll be put in table2, including the chosen option from table1.</p> <p>Could anyone help with this issue, please?</p> <p>Table2 HTML form:</p> <pre><code>&lt;div class="form"&gt; //Simple input that's normaly inserted in table2 &lt;form action="insert.php" method="post"&gt; &lt;input class="form1" type="text" value="NAME" name="name" onfocus="if (this.value=='NAME') this.value='';"/&gt; &lt;br /&gt; //Input that lists all the entries from the "companies" field from table1 &lt;select class="form7" value="COMPANIES" name="companies" /&gt; &lt;?php //Connection DB file with the two databases (already tested) include("connect.php"); //Select to list all the entries from "companies" row from table1 $query = mysql_query("SELECT * FROM table1 ORDER BY nomefantasia") or die(mysql_error()); while($array = mysql_fetch_array($query)) { //Option listing field echo '&lt;option value="companies" name="companies"&gt;'.$array['companies'].'&lt;/option&gt;'; } ?&gt; &lt;/select&gt; //Submit button &lt;input class="button" type="submit" value="SUBMIT" /&gt; &lt;/form&gt; </code></pre> <p></p> <p>INSERT INTO file</p> <pre><code>&lt;?php include("connect.php"); // Get values from form $name=$_POST['name']; // Insert data into mysql $sql="INSERT INTO $table2(name) VALUES ('$name')"; $result=mysql_query($sql); if($result){ echo "Done!!"; echo "&lt;br /&gt;"; echo "&lt;a href='#'&gt;Return&lt;/a&gt;"; } else { echo "ERROR"; } ?&gt; &lt;?php // close connection mysql_close(); ?&gt; </code></pre> <p>So, how do I call the "companies" row into that?</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