Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, <code>mysql_query</code> is deprecated as I know.</p> <p>Try learning <a href="http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html" rel="nofollow">PDO</a>. It is safer, and other advantages I guess.</p> <p>Moreover, what your example is doing is, write <strong>into</strong> the mysql query, which is probably wrong. In the end, you will have a mysql query like :</p> <pre><code>insert into tablename set Reg_no = 'something' while(fieldcount&lt;=10) { echo something else } </code></pre> <p>etc. , which does not make sense in MySQL. MySQL will not understand what <code>echo</code> is.</p> <p>MySQL expects a query like <code>"INSERT INTO tablename(fieldname) VALUES ('the_value')"</code>;</p> <p>So I guess what you are trying to do is run a mysql query, and echo something in the screen, like this:</p> <pre><code>$pdo-&gt;query("insert into tablename (field1,field2) values ('value1' , 'value2')"); while(fieldcount&lt;=10) { echo "something"; } </code></pre> <p>and please note that above example is also not safe, if you are concerned about mysql injection.</p> <p>So, my advice is, also learn about <a href="http://pressedweb.com/tutorials/pdo-baby-steps-prepared-statements/" rel="nofollow">prepared statements</a>.</p> <h2>Edit:</h2> <p>If you want to run mysql queries in a loop, you can do something like this:</p> <pre><code>&lt;?php for($i=0 ; $i &lt; 10 ; $i++) { $thefield = "field".$i; // construct your field name $thevalue=$i; // construct your value. I guess this is where your $_REQUEST variables go. $pdo-&gt;query("insert into tablename($thefield) VALUES('$thevalue')"); // then run the necessary mysql query. echo "i inserted $thevalue for the field $thefield"; } // and of course, for this case, you may not need a loop. You can insert multiple values at once, like this: $pdo-&gt;query("insert into tablename (field1,field2,and_any_other_field) values ('value1' , 'value2' , 'value_for_other_field')"); // etc. ?&gt; </code></pre> <p>for example.</p>
    singulars
    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