How can I update the data in mysql using the button defined in the table?

Hello

right now I am doing my project for the online election system using dreamweaver cc14. I create a table using php code to bind the data to mysql, and in this painting, I create also a button "vote" for voters to vote. My question is, how can I update my polling data in the mysql database when voters push button "vote" based on the id of the candidates? Here is my code I try:

<form method="post" id="form1">
      <?php
$servername = "localhost";
$username = "root";
$password = "pass";
$dbname = "ses";


// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
} 


$sql = "SELECT No, Calon, ID, Jurusan, Image FROM candidates";
$result = $conn->query($sql);


if ($result->num_rows > 0) {
     echo "<table >
  <tr>
  <th>NO</th>
  <th>Candidate</th>
  <th>INFO</th>
  <th>Vote</th>
  </tr>";
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<tr>
  <td>" . $row["No"]. "</td>
  <td><img src=" . $row['Image'] . "></td>
  <td><br/>-" . $row["Calon"]. " <br/>-" . $row["ID"]. " <br/>-" . $row["Jurusan"]. "<br/></td>
  <td><input type="."submit"." name=".$row["Calon"]." id=".$row["No"]. " value="."Vote"."></td>

  </tr>";
  if(isset($_POST["".$row['No'].""])){

  $vote_sachin = "UPDATE candidates SET Undi=Undi+1 WHERE No=".$row["No"]. "";

  $run_sachin = mysqli_query($conn, $vote_sachin);


}
    }
  echo "</table>";
} else {
     echo "0 results";
}






$conn->close();
?>




    </form>

I hope someone can help me in this area, because I'm still new in this programming language.

Thank you.

Youre probably going to insert a 'radio button' next to the names of candidates and recover the database ID of that (I guess that the ID is the primary key in your database that uniquely identifies each record.

His great confusion because you seem to update the database to aid WHERE no = "." $row ["no"]. so I don't know that ID is the primary key?

IF "No" IS your master database key, you need to change the code below:

TO:

Here's the complete code based on the ID of your primary database key.

<>

$servername = "localhost";

$username = 'root ';

$password = "pass";

$dbname = 'his ';

Create the connection

$conn = new mysqli ($dbname, $servername, $username, $password);

Check the connection

If {($conn-> connect_error)

Die ("connection failed:".) $conn-> connect_error);

}

$sql = "SELECT No, Calon, ID, Jurusan, Image OF candidates";

$result = $conn-> Query;

If you click on the button "vote" form run the code to update the database below

{if (isset($_POST['vote']))}

Get the value of the ID of the radio button form field and store it in a table.

$update_vote = $_POST ['candidate_id'];

loop in the table and update the database

foreach ($update_vote as $value) {}

$vote_sachin = ' candidates UPDATE SET Undi = Undi + 1 WHERE ID = ".". " $value. » « ;"

$run_sachin = mysqli_query ($conn, $vote_sachin);

}

}

?>

<>

If ($result-> num_rows > 0) {}

ECHO '.

";

each line output

While ($row = {$result-> fetch_assoc())}

ECHO '.

";

}

ECHO '.

";

ECHO '.

NO. Candidate INFO To the vote
" . $row ["no"]. "
-" . $row ["Calon"]. "
-" . $row ['ID']. "
-" . $row ["Jurusan"]. "
";

} else {}

echo "0 results."

}

$conn-> close();

?>

Tags: Dreamweaver

Similar Questions

  • How can I update the table table of contents for the sub condition?

    Hi guys,.

    I have a custom table that must be updated in a table source 'abc ';

    I have to update 8 fields of 'abc', based on five keys corresponding between custom and abc records

    Here is the syntax I have a suite please let me know the effective way to do this.

    I get the error message for the syntax below. I think that 'FROM' keyword must not be use GTA?

    update of custom table one

    Set a.field1 = b.field1, a.field2 = b.field2, a.field3 = b.field3

    ABC b

    where value = ' 05 "

    Hello

    Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

    Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

    If you ask yourself on a DML statement, such as UPDATE, then the CREATE TABLE and you post instructions INSERT must re - create the tables as they are to the DML, and the results will be the content of the or a modified tables when it's all over.

    Simplify the problem as much as possible.  For example, if your real problem involves 8 columns, try to post an issue affecting only 2 or 3 columns.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    2766124 wrote:

    Hi guys,.

    I have a custom table

    What is a custom table?  How is it different from a regular table?

    that must be updated in a table source 'abc ';

    I have to update 8 fields of 'abc', based on five keys corresponding between custom and abc records

    Here is the syntax I have a suite please let me know the effective way to do this.

    I get the error message for the syntax below. I think that 'FROM' keyword must not be use GTA?

    update of custom table one

    Set a.field1 = b.field1, a.field2 = b.field2, a.field3 = b.field3

    ABC b

    where value = ' 05 "

    An example of the correct syntax for the use of a subquery in an UPDATE statement is:

    UPDATE one

    SET (Field1, Field2, Field2) =

    (SELECT field1, Field2, field3

    ABC

    WHERE value = ' 05 "

    );

    This is a correct syntax, but I don't know if this will do exactly what you want, because I don't know exactly what you want.

    FUSION is often easier and sometimes more effective than updated.

  • The map database - how can I update the table

    Hello
    I develop a bpel using SOA 10.1.3.4 process. The process of bed from a table and writes to a table B. The process must then update table A for lines which it was moved to table B and look for new ones. I can't understand how to do this. Can you please tell me how this could be done.

    Thanks in advance for your help.
    HD

    It's a checkbox when configuraing the data source, it will be either XA or global transactions. I think that, by default, it uses global transactions, so you should be fine.

    see you soon
    James

  • How do I update the table in Jdev

    Hello

    I use Jdev 11.1.1.7.1.

    The control of data, I added that ADF only read the table. When I click on the button create and return to the report screen, highlight lines are added.

    Highlighted those who is not inserted into the DB table but he showed in the report. How to remove it. How can I update the table?

    Kindly advice me.

    Thank you

    Swathi

    That's what I got:

    -You have a table read-only, and a link to create.

    -When you press the link create a popup will be launched with a new record (may be a form in the same table iterator).

    -When you press save to save the changes validation triggers, stop you to insert the record.

    -After the fire of validation you will close the pop-up window (by pressing icon or by pressing Cancel).

    -After closure of the pop-up window, you will find that reading one table has some blank lines.

    If it is your problem if you have 2 choices:

    1. in the AppModule you can make a new instance on the view object (to which redirect the table) If your view object called 'EmployeesView', so, in AppModule, you should have EmployeeView1 and EmployeeView2 and your table may point to EmployeeView1, and when you create new line create in EmployeeView2 and after completing the creation you can run the query and then refresh the table (as shown in the following code).

    2 - the second option in the popup cancelListener link at the rear bean method then you can update the table by program as:

        DCIteratorBinding iter = (DCIteratorBinding) BindingContext.getCurrent().getCurrentBindingsEntry().get("TableIteratorName"); // from pageDef.
        iter.getViewObject().executeQuery();
        RequestContext.getCurrentInstance().addPartialTarget(getTableComponent());// from table Binding property bind it to object in back bean
    
  • How can I update the expiration date on my credit card account?

    How can I update the expiration date on my credit card account?

    How can I update the expiration date on my credit card account?

    Go to your Bank and get a new card.

  • Satellite L300D - 24 d how can I update the graphics driver?

    Hello

    How can I update the driver for my ATI Radeon 3100 graphics card. (Win Vista 32 bit)
    I download and installed the new ATI Catalyst worms. 10.12.

    If I change my graphics card options, there is always the old driver installed... Worms. 22.04.08 8.479.0.0
    Also, it is not possible to change the settings for graphic resolution higher than 1280 X 800 Pix.

    Thanks for the help,

    Fun1975

    First, you must use the page to Toshiba display driver.
    The use of other drivers can lead to highest GPU temperature and cause overheating.

    But if you want to use other drivers, you can do so at you own risk.
    In order to install another driver, go to Device Manager, mark the graphics card, then press on uninstall button.
    Then the driver should be uninstalled.

    After you restart the laptop, you can try to install the new version.

    > It is also not possible to change the settings for graphic resolution higher than 1280 X 800 Pix.
    The internal screen for laptop supports 1280 x 800 high resolution. It is not possible to choose a higher value.

  • I had to change my Apple ID because of accusations of fraud but my iPhone 6s 9.2 still has the old Apple ID and will not accept old or new passwords. How can I update the iPhone with the new Apple ID 9.2 6s?

    I had to change my Apple ID due to fraudulent charges but my iPhone 6s 9.2 still has the old Apple ID and will not accept old or new passwords. How can I update the iPhone 6s 9.2 with the new Apple ID and password? I tried to perform a complete reset, but which requires the Apple ID and password that doesn't work not... pretty frustrated here.

    YYou have unlink the old iphone you as find my iphone the reset all devices on this subject from your account then plug it to your iTunes then restore a new one after that reset password that under the new phone then connect

  • I managed to see the profile of the artist in Apple's music. How can I update the profile picture?

    I managed to see the profile of the artist in Apple's music. How can I update the profile picture?

    This is a user forum. No Apple itself is allowed to answer your questions here.

    You are probably better contact Apple Support directly to get an answer to your question.

  • How can I update the gps of streets &amp; trips

    How can I update the gps of streets & trips (not sure which version)

    Hi CP agent v-2jeen

     

    Because the question is specific to the streets and trips you contact that it can support the assistance team. I would recommend posting your query to the community of Microsoft streets & trips. Please visit the links below to find a community that will support what ask you in the right direction.

    http://social.Microsoft.com/forums/en-us/streetsandtrips/threads

    You can also check out below help links-
    http://support.Microsoft.com/ph/1058#TAB0
    http://www.Microsoft.com/streets/en-us/support-and-training.aspx

    I hope this helps.

  • I'm not having implemented the cd with me. How can I update the window components. by mistake I uninstalled the

    I'm not having implemented the cd with me. How can I update the window components. by mistake I uninstalled the

    Reinstall windows components, you've accidentally deleted when you have the game CD with you.

  • URGENT! How can I update the build on BB store

    Hi all..

    I want to update the build on BB store. Please help me how can I update the build on bb store after the download of version 1.

    Now, I need to download version 2.

    Thank you

    After signing, choose manage products, then in the line that corresponds to the product that you're gong to update, you should find an icon "+" under the heading of press.  A click on it.

    I don't remember having a problem, this the first time, so I suspect it's pretty much follow your nose after that.

    It is also available help documentation:

    http://developer.BlackBerry.com/DevZone/blackberryworld/adding_and_apps_and_releases_in_blackberry_w...

  • How can I update the BIOS on my Sony Vaio laptop using disc or usb? Note: I can't windows at all.

    Hi, I want to know how can I update the current bios on my sony laptop using the disc or usb.

    I can't access the windows on the laptop at all, because I'm getting STOP: 0 x 00000 "a5 error that says: your bios is not fully compatible with acpi.»
    This error prevents me to access any live disc or recovery disks.
    I would like to learn more about records tho method.
    Thank you.

    Take it to a repair shop, you have damaged the card mother/connections

  • How can I update the rubrics with WebServices?

    How can I update the rubrics with WebServices?

    /Anyone/ has some success with this?

    It becomes important to our business objectives in order to solve the problems within the control elements.

    I can't enter the number of line by line in order to uniquely identify it. How can I get that number, so I can send it with xml "update"?

    A little nudge in the right direction would be much appreciated.

    Aaron.

    You must use a field on the form as the one on the line items, NOT the line number that appears in the journal of the line item. If I understand correctly, the LineItemIdentifier can be any field on the form, even the short description. It is best if you know you will use web services to update the line items, you add a (potentially hidden) field to the form and fill that with unique values when positions are created. If you are working with existing elements of line, then you must choose a field that will be usually unique within a single record and hope, you don't have a lot of duplicates.

  • Exporting DNG from Lightroom, but the thumbnail in os x Finder still shows the unmodified image. How can I update the thumbnail?

    I export a DNG from Lightroom on my iMac (OSx 10.11.2) but the thumbnail in os x Finder still shows the unmodified image. How can I update the thumbnail?

    Export to DNG will always export a unretouched photo non-modified. Your changes are in the XMP of DNG file as text, and most of the viewers of DNG files cannot interpret or use this text. So, it seems that when you export photos in DNG, Lightroom has done what it is supposed to do.

  • vCenter Server is a virtual machine, how can I update the host

    I have 2 guests in our environment, I have updated the host of the 2nd, but may not know how to upgrade the 1 host because vcenter server runs as a virtual machine on it. This has me thinking that I don't have the installation program as best as possible.

    Basically, we have 2 Guest boxes and a small box of DC. I don't really want to run vcenter on the dc area. What would be the best soltuong for our environment? Can I keep vcenter as a virtual machine? If Yes, how can I update the host it will run on?

    Thanks in advance everyone... Chris

    I was afraid of that say you that

    Well in this case you may need to update the host manually (see for example http://communities.vmware.com/people/vmroyale/blog/2011/09/15/updating-esxi-5--single-use-esxcli-how-to) even with the need to manually update the host on which vCenter Server is running, I would always run as a virtual machine. There is usually not that many updates.

    André

    Post edited by: a.p..

  • How can I update the patch of dps to my Adobe CS6 class

    How can I update the patch of dps to my Adobe CS6 class

    http://helpx.Adobe.com/Digital-Publishing-Suite/help/installing-digital-publishing-tools.h tml

    Neil

Maybe you are looking for