473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

how to update a database that has a dropdown list in php

20
hello,

I have a html form for user to submit their inquiry. after submitting the form, the data will go to php file and then it will connect to the database. I can do that.

the problem is, for admin view, it will have a dropdown list (approved/not approved) for admin to validate the data. how to update the database? I managed to do the dropdown, but when I clicked the save button, the database didnt update anything.

please help me, thanks in advanced !

==========form.html===========
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html> <head> <meta charset="utf-8"> <title>data</title> <link rel="stylesheet" media="screen" href="http://bytes.com/styles.css" > </head> <body bgcolor="#13b4ff"> <div id="header" style="background-color: #4169E1;"><hr> <form class="form" action="http://bytes.com/submit.php" method="post" name="form" > <ul> <li> <label for="name">Name:</label> <input type="text" name="name" required /> </li> <li> <label for="position:">Jawatan:</label> <input type="text" name="position" /> </li> <li> <label for="unit">Unit:</label> <input type="text" name="unit" required /> </li> <li> <label for="institute">Institute:</label> <input type="text" name="institute" required /> </li> <li> <label for="telefon">No. Telefon:</label> <input type="number" name="telefon" required /> </li> <li> <label for="faks">No. Faks:</label> <input type="number" name="faks"/> </li> <li> <label for="email">E-mail:</label> <input type="email" name="name" placeholder="name@something.com"/ required> <span class="form_hint">proper format<script type="text/javascript">
  2. /* <![CDATA[ */
  3. (function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
  4. /* ]]> */
  5. </script></span> </li> <li> <label for="data">Data Required:</label> <input type="text" name="data" required/> </li> <li> <label for="purpose">Purpose:</label> <input type="text" name="purpose" required/> </li> <li> <button class="submit" type="submit">Submit</button> </li> </ul> </form> </body> </html>
==========submit.php===========
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //debug mode
  4. error_reporting(E_ALL);
  5. ini_set('display_errors', '1');
  6.  
  7. //to show some error is smthng went wrong
  8. $errors = array();
  9.  
  10. function connect(){
  11.     $connection = mysql_connect("localhost", "root", "" );
  12.     $db = mysql_select_db('permohonan_data', $connection);
  13.  
  14. if (!$connection || !$db){
  15.     return false;
  16.     }
  17. else{
  18.     return true;
  19.     }
  20. }
  21.  
  22. //will run if user did submit the form
  23. if (!empty($_POST)){
  24.  
  25. //connect sql server:
  26. if (!connect()){
  27.     $errors[] = "Can't establish link to MySql server";
  28.     }
  29.  
  30.     $name = $_POST['name'];
  31.         $position = $_POST['position'];
  32.         $unit = $_POST['unit'];
  33.         $institute = $_POST['institute'];
  34.         $telefon = $_POST['telefon'];
  35.         $faks = $_POST['faks'];
  36.         $email = $_POST['email'];
  37.         $data = $_POST['data'];
  38.         $purpose = $_POST['purpose'];
  39.  
  40. //no error til here
  41. if (empty($error)){
  42.  
  43. //prevent SQL injection
  44.     $name = mysql_real_escape_string($name);    
  45.     $position = mysql_real_escape_string($position);
  46.     $unit = mysql_real_escape_string($unit);
  47.     $institute = mysql_real_escape_string($institute);
  48.     $telefon = mysql_real_escape_string($telefon);
  49.     $faks = mysql_real_escape_string($faks);
  50.     $email = mysql_real_escape_string($email);
  51.     $data = mysql_real_escape_string($data);
  52.     $purpose = mysql_real_escape_string($purpose);
  53.  
  54. }
  55.  
  56. //try insert value
  57. $query = "INSERT INTO 'user'
  58.      (name,position,unit,institute,telefon,faks,email,data,purpose)
  59.         VALUES ('$name', '$position', '$unit', '$institute', '$telefon', '$faks', '$email', '$data', '$purpose')";
  60.  
  61. //try
  62. if (!mysql_query($query)){
  63.     //
  64.     //die(mysql_error());
  65.     $errors[] = "Can't insert the values";
  66.     }
  67. else {
  68.     //on success
  69.     header("Location:thankyou.php");
  70.     exit();
  71.  
  72. }
  73.  
  74. }    
  75.  
  76. ?>
==========part of admin.php===========
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $connect = mysql_connect("localhost","root","");
  3.     if (!$connect){
  4.         die(mysql_error());
  5.     }
  6.     mysql_select_db("permohonan_data");
  7.     $option = '';
  8.     $results = mysql_query("SELECT * FROM user ORDER BY id DESC");
  9.  
  10.     $option .='<select>';
  11.     $count=mysql_num_rows($results);
  12.  
  13.     if(isset($_POST['submit']))
  14. {
  15.     $tindakan = mysql_real_escape_string(stripslashes($_POST['tindakan']));
  16.  
  17.     $sql_edit = "UPDATE permohonan_data SET pemohon = tindakan = '".$tindakan."'";
  18.     if($result_edit = mysql_query($sql_edit))
  19.     {
  20.         $status_edit= "Success";
  21.     }
  22.     else
  23.     {
  24.         $status_edit= "Failed";
  25.     }
  26. }
  27.  
  28.     while ($row = mysql_fetch_array($results)){
  29.  
  30.     ?> <tr> <td><?php echo $row['id']?></td> <td><?php echo $row['name']?></td> <td><?php echo $row['unit']?></td> <td><?php echo $row['telefon']?></td> <td><?php echo $row['faks']?></td> <td><?php echo $row['email']?></td> <td><?php echo $row['data']?></td> <td><?php echo $row['purpose']?></td> <td><select> <option <?php if( $row['tindakan'] == '-'){ echo "selected";}?> >-</option> <option <?php if( $row['tindakan'] == 'app'){ echo "selected";}?> >Approved</option> <option <?php if( $row['tindakan'] == 'notapp'){ echo "selected";}?> >Not Approved</option> </select></td> </tr> <?php
  31. }
  32.     $option .='</select>';
  33. ?> </tbody> </table> <input type='submit' value='Save'>

I need help with my admin.php. I know the code is unorganized. I'm really new to this. :/
Jan 13 '14 #1
2 4154
Exequiel
288 256MB
try to determine or put the value for pemohon $sql_edit = "UPDATE permohonan_data SET pemohon = tindakan = '$tindakan'";
Jan 15 '14 #2
Dormilich
8,658 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. "UPDATE permohonan_data SET pemohon = tindakan = '".$tindakan."'";
I doubt this is valid syntax
Jan 24 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: carmen | last post by:
I am having a problem with the code below. When the page loads the data is pulled from the db just fine But when I try to update the dropdown list that has the onchange added to it it is now...
1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
1
by: Ian Davies | last post by:
Hello In a php file I have a drop down list with index numbers in whos default value is feed into an sql query that filters records from my database and displays them in an html table. Trouble...
2
by: JIM.H. | last post by:
Hello, I have a dropdown list, updated through a dataset. After bind, I use this to add extra item to my dropdown list. myDropDownList.Items.Add(“Item1”), I can remove that by using...
2
by: Sam | last post by:
A) Destination Table with 4 Fields. 1) Last Name 2) First Name 3) State 4) Zip Code. B) Look up table State/Zip Code with 2 Fields
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
0
by: creamy | last post by:
Hello everyone, please i'm trying to populate a drop down list with values i read from a file. When one drop down is selected, i take its value like ddlState.selectedItem.. and read the file. But...
5
by: abhi3211 | last post by:
i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from ms-access database. in second dropdown list i want to get data...
4
by: Paul | last post by:
Hi all, I have a page that has a form on it which has a dropdown list on it. It connect to an sql database and populate the list. What I would like to do is make the list editable so that if the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.