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
<!DOCTYPE html> <head> <meta charset="utf-8"> <title>data</title> <link rel="stylesheet" media="screen" href="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">
/* <![CDATA[ */
(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){}})();
/* ]]> */
</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
<?php
//debug mode
error_reporting(E_ALL);
ini_set('display_errors', '1');
//to show some error is smthng went wrong
$errors = array();
function connect(){
$connection = mysql_connect("localhost", "root", "" );
$db = mysql_select_db('permohonan_data', $connection);
if (!$connection || !$db){
return false;
}
else{
return true;
}
}
//will run if user did submit the form
if (!empty($_POST)){
//connect sql server:
if (!connect()){
$errors[] = "Can't establish link to MySql server";
}
$name = $_POST['name'];
$position = $_POST['position'];
$unit = $_POST['unit'];
$institute = $_POST['institute'];
$telefon = $_POST['telefon'];
$faks = $_POST['faks'];
$email = $_POST['email'];
$data = $_POST['data'];
$purpose = $_POST['purpose'];
//no error til here
if (empty($error)){
//prevent SQL injection
$name = mysql_real_escape_string($name);
$position = mysql_real_escape_string($position);
$unit = mysql_real_escape_string($unit);
$institute = mysql_real_escape_string($institute);
$telefon = mysql_real_escape_string($telefon);
$faks = mysql_real_escape_string($faks);
$email = mysql_real_escape_string($email);
$data = mysql_real_escape_string($data);
$purpose = mysql_real_escape_string($purpose);
}
//try insert value
$query = "INSERT INTO 'user'
(name,position,unit,institute,telefon,faks,email,data,purpose)
VALUES ('$name', '$position', '$unit', '$institute', '$telefon', '$faks', '$email', '$data', '$purpose')";
//try
if (!mysql_query($query)){
//
//die(mysql_error());
$errors[] = "Can't insert the values";
}
else {
//on success
header("Location:thankyou.php");
exit();
}
}
?>
==========part of admin.php===========
Expand|Select|Wrap|Line Numbers
<?php
$connect = mysql_connect("localhost","root","");
if (!$connect){
die(mysql_error());
}
mysql_select_db("permohonan_data");
$option = '';
$results = mysql_query("SELECT * FROM user ORDER BY id DESC");
$option .='<select>';
$count=mysql_num_rows($results);
if(isset($_POST['submit']))
{
$tindakan = mysql_real_escape_string(stripslashes($_POST['tindakan']));
$sql_edit = "UPDATE permohonan_data SET pemohon = tindakan = '".$tindakan."'";
if($result_edit = mysql_query($sql_edit))
{
$status_edit= "Success";
}
else
{
$status_edit= "Failed";
}
}
while ($row = mysql_fetch_array($results)){
?> <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
}
$option .='</select>';
?> </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. :/