-1

Hello,

I just want to ask. Is it possible to do the insert and select in one time and in one form? I can't see any example of this problem. Can somebody help me?

Thanks.

4
Contributors
15
Replies
20
Views
5 Years
Discussion Span
Last Post by vibhaJ
0

insert and select ? i think those two are different things, i haven't encounter anything like that.
As far as i know INSERT is used when you intend to add or save a new row of data, while SELECT is used when data is already in the DB and you intend to get it. why not use UPDATE instead?

0

Can update and view list can do in the same form?

For example, I have a language form which is include language, written and spoken row. Then need to put add button tu add another language. Is it possible to do that?

0

do you mean you want to add a button that executes a query to add another row under the field language ?
yes it is.

PS: sorry if it seems that i don't understand you well, i just want it to be clear ..

0

Yes. Like that.. Can you please explain me how to do it? And if possible, can you please give me the example?

0

do you mean you want to add a button that executes a query to add another row under the field language ?
yes it is.

PS: sorry if it seems that i don't understand you well, i just want it to be clear ..

If you talk about a form - is this an html form, or do you mean a sql query? If you execute a query it is a select statement or an update statement. not both. if you have a html form, you can execute multiple queries when you execute the post of the form.

so if this is about a button on a page - if you push this the page this invokes needs to do an update statement and a select as well.
this is not a problem at all. Can you show us some code here? thanks in advance.

0

Your requirement is bit not clear. Just a guess.
When you add language bt clicking submit button, you need to use insert query.
While on page listing you need to use select query to fect all records from database.

0

Your requirement is bit not clear. Just a guess.
When you add language bt clicking submit button, you need to use insert query.
While on page listing you need to use select query to fect all records from database.

Yes. Can you tell me how to do it?

0

If you talk about a form - is this an html form, or do you mean a sql query? If you execute a query it is a select statement or an update statement. not both. if you have a html form, you can execute multiple queries when you execute the post of the form.

well that's what i have in mind.. in my case i used a button to submit the data inputted by the user where it navigates to a page where all the queries are placed, by then the data will be stored, it consists of several variables, tables and queries ..

0

I use a button to do the insert and select as well..

Is it possible to do it?

0
<?php
if (isset($_POST['add'])){
if (isset($_POST['staff_current_division'])){
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("IJA", $con);

$ija=mysql_query("INSERT INTO staff_career_history_db (career_history_division,career_history_dept,career_history_section,career_history_position,career_history_year) VALUES  ('$career_history_division','$career_history_dept','$career_history_section','$career_history_position','$career_history_year')");

$db_close=mysql_close();}}
?>

<form name="form1" method="post" action="index.php?page=isi_form2.php">

<p><strong>B. CAREER HISTORY IN PROTON / <em>PENGALAMAN KERJA DI PROTON</em></strong></p>
<table width="672" border="0" align="center">
  <tr>
    <td><div align="center">1.</div></td>
    <td>Division / <em>Bahagian </em></td>
    <td><div align="center">:</div></td>
    <td colspan="3"><select name="career_history_division" id="career_history_division">
      <option value="-">Select Division</option>
      <option value="Engineering">Engineering</option>
      <option value="Manufacturing">Manufacturing</option>
      <option value="GroupQuality">Group Quality</option>
      <option value="VehicleCostReduction">Vehicle Cost Reduction (VCR)</option>
      <option value="OperationOffice">Operation Office</option>
      <option value="GreenTechnology">Green Technology</option>
      <option value="Environment,Health&amp;Safety">Environment,Health &amp; Safety (EHS)</option>
      <option value="ProductionPlanning&amp;Development">Production Planning &amp; Development</option>
      <option value="ProductStrategy">Product Strategy</option>
      <option value="GroupMarketing,Branding&amp;Motorsports">Group Marketing,Branding &amp; Motorsports</option>
      <option value="GroupAfterSales">Group After Sales</option>
      <option value="Export">Export</option>
      <option value="GroupTechnicalProcurement">Group Technical Procurement</option>
      <option value="GroupFinance">Group Finance</option>
      <option value="GroupInformation&amp;CommunicationTechnology">Group Information &amp; Communication Technology</option>
      <option value="GroupAssetManagement">Group Asset Management</option>
      <option value="Group Human Resources">Group Human Resources</option>
      <option value="GroupInternalAudit">Group Internal Audit</option>
      <option value="GroupRiskManagement">Group Risk Management</option>
      <option value="GroupLegal,Secretarial&amp;Compliance">Group Legal,Secretarial &amp; Compliance</option>
      <option value="GroupCommunication">Group Communication</option>
      <option value="GroupCorporatePlanning">Group Corporate Planning</option>
      <option value="MD'sOffice">MD's Office</option>
    </select></td>
  </tr>
  <tr>
    <td width="12"><div align="center">2.</div></td>
    <td width="139">Department / <em>Jabatan</em></td>
    <td width="9"><div align="center">:</div></td>
    <td colspan="3"><label>
      <input name="career_history_dept" type="text" id="career_history_dept" size="50" />
      </label>
    </td>
  </tr>
  <tr>
    <td><div align="center">3.</div></td>
    <td>Section / <em>Seksyen</em></td>
    <td><div align="center">:</div></td>
    <td colspan="3"><label>
      <input name="career_history_section" type="text" id="career_history_section" size="50" />
      </label>
    </td>
  </tr>
  <tr>
    <td><div align="center">4.</div></td>
    <td>Position / <em>Jawatan</em></td>
    <td><div align="center">:</div></td>
    <td colspan="3"><label>
      <input name="career_history_position" type="text" id="career_history_position" size="50">
      </label>
    </td>
  </tr>
  <tr>
    <td height="27"><div align="center">5.</div></td>
    <td>Year / <em>Tahun</em></td>
    <td><div align="center">:</div></td>
    <td width="400"><label>
      <select name="career_history_year" id="career_history_year">
        <option value="0">0</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18">18</option>
        <option value="19">19</option>
        <option value="20">20</option>
        <option value="21">21</option>
        <option value="22">22</option>
        <option value="23">23</option>
        <option value="24">24</option>
        <option value="25">25</option>
        <option value="26">26</option>
        <option value="27">27</option>
        <option value="28">28</option>
        <option value="29">29</option>
        <option value="30">30</option>
        <option value="31">31</option>
        <option value="32">32</option>
        <option value="33">33</option>
        <option value="34">34</option>
        <option value="35">35</option>
        <option value="36">36</option>
        <option value="37">37</option>
        <option value="38">38</option>
        <option value="39">39</option>
        <option value="40">40</option>
        <option value="41">41</option>
        <option value="42">42</option>
        <option value="43">43</option>
        <option value="44">44</option>
        <option value="45">45</option>
        <option value="46">46</option>
        <option value="47">47</option>
        <option value="48">48</option>
        <option value="49">49</option>
        <option value="50">50</option>
      </select>
      </label>
    </td>
    <td width="38"><label>
      <input name="add" type="submit" id="add" value="Add">
      </label>
    </td>
    <td width="48"><label></label>
        <input name="reset2" type="reset" id="reset2" value="Reset" /></td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="639" border="0" align="center">
  <tr>
    <td width="129"><div align="center">Division / <em>Bahagian</em> </div></td>
    <td width="157"><div align="center">Department / <em>Jabatan</em> </div></td>
    <td width="119"><div align="center">Section / <em>Seksyen</em> </div></td>
    <td width="124"><div align="center">Position / <em>Jawatan</em></div></td>
    <td width="88"><div align="center">Year / <em>Tahun</em></div></td>
  </tr>

<?
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("IJA", $con);
$result = mysql_query("SELECT * FROM staff_career_history_db");
?>

  <?php while($row = mysql_fetch_array($result))
                {

                ?>
  <tr>
    <td><div align="center"><?php echo $row['career_history_division']; ?></div></td>
    <td><div align="center"><?php echo $row['career_history_dept']; ?></div></td>
    <td><div align="center"><?php echo $row['career_history_section']; ?></div></td>
    <td><div align="center"><?php echo $row['career_history_position']; ?></div></td>
    <td><div align="center"><?php echo $row['career_history_year']; ?></div></td>
  </tr>
  <?php }?>


</table>

This is my code..

0

1) Create one config.php file and add database connection code there. Include that config.php file on top of your page. No need to connect database multi time on page.

2) After your insert query code, use header function and redirect page . Otherwise each time you hit F5 one entry will be done.

3) Also i didn't see closing of form tag.

3) You can move select query code on top. So all php code will be on top of PHP, it is good practice. Don't use more PHP lines in between of HTML tags.

4) Use some code indent. So it will be easy to read :)

Rest your code is okay... That's IT !!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.