omdx omdx - 5 months ago 13
PHP Question

if inside another if on Select Option

I have a Form with Option in numberreg.php:

<form action="process.php" method="post" name="SelectAutoNumber" id="SelectAutoNumber">

<select name="NoKep1" required id="NoKep1" oninvalid="setCustomValidity('Pilih Jenis Kelahiran!')"
onchange="try{setCustomValidity('')}catch(e){}">
<option value="">- Select Number-</option>
<option value="1">1 - None</option>
<option value="2">2 - AutoNumber</option>
</select>

</form>


and its process in another process.php after submit.

<?php
if ( $NoKep1 == 1 ) {
$NoKeputusan = "None";
} else {

$findcode = mysqli_query($con, "SELECT NoKep from ken_lahir") or die (mysqli_error());
// menjadikannya array
$datacode = mysqli_fetch_array($findcode);
$total_data = mysqli_num_rows($findcode);
// if $findcode
if ($datacode) {

$nilaicode = substr($total_data[0], 1);

$code = (int) $nilaicode;

$code = $total_data + 1;

$NoKeputusan = "XXX/".str_pad($kode, 4, "0", STR_PAD_LEFT)."/MMM";
} else {
$NoKeputusan = "XXX/0001/MMM";
}
?>


and the code give me syntax error. please help me here. really lost in here. any help would be appreciated. Thx

Answer

1)

<?php
$NoKep1 = $_POST['NoKep1']; // You Missed Here
if ( $NoKep1 == 1 ) {
    $NoKeputusan = "None";
} else {

2) And, At the end. You Missed closing }.

Updated Code (Refer Question Comment, as user commented)

As you have commented in comment about your code.

Change

isset($_POST[$NoKep1 == 1])

To

isset($_POST['NoKep1'] == 1])

And, Assign $NoKep1 as $NoKep1 = $_POST['NoKep1'];

<?php if ( isset($_POST['NoKep1'] == 1]) ) { 
  $NoKeputusan = "None"; 
} else { 
  $findcode = mysqli_query($con, "SELECT NoKep from ken_lahir") or die (mysqli_error()); 
    //Your code
}  
?>
Comments