Leonard Febrianto
Leonard Febrianto

Reputation: 984

Query did not want to execute

Why is my query didn't want to execute ? Usually i can do it with this code. But this time, its taking many time to resolve this.

Here is the code :

Edited

$nim = $_GET['nim'];
$conn = mysqli_connect($hostname_localhost,$username_localhost,$password_localhost, $database_localhost) or die(mysqli_error($conn));
$query = "select nama_user1,kelas,jurusan from user1 where kode_user1 = '".$nim."'";
$query_exec = mysqli_query($conn, $query) or die(mysqli_error($conn));
if($data = mysqli_fetch_array($query_exec))
{
    $kelas = $data['kelas'];
    $jurusan = $data['jurusan'];
    $nama = $data['nama'];
    echo $nama;
}

While i run it in mySQL , it does show the result from the query. But when i execute that query it didn't show anything when i'm echo it.

Please help me.

Upvotes: 0

Views: 37

Answers (2)

Leonard Febrianto
Leonard Febrianto

Reputation: 984

I'm sorry. My mistake..

So the problem came from previous page.

I just write this :

header('Location: schedule2.php?nim="'.$nim.'"&jumlah_schedule="'.$jumlah_schedule.'"');

So the correct is :

header('Location: schedule2.php?nim='.$nim.'&jumlah_schedule='.$jumlah_schedule.'');

And i change $nim = $_GET['nim'];

with

$nim = $_REQUEST['nim'];

Thanks for the support dstudeba

Upvotes: 0

dstudeba
dstudeba

Reputation: 9038

Quick answer is $nama = $data['nama']; should be $nama = $data['nama_user1'];

Longer answer

$query = mysql_prepare($conn, "select nama_user1, kelas, jurusan from user1 where kode_user1 = ?");
mysqli_stmt_bind_param($query, "i", $nim);
mysqli_stmt_execute($query) or die(mysqli_error($conn));
myslqi_stmt_bind_result($query, $nama_q, $kelas_q, $jurusan_q);
while(mysqli_fetch_array($query))
{
    $kelas = $kelas_q;
    $jurusan = $jurusan_q;
    $nama = $nama_q;
    echo $nama;
}

Edit to add I do most of my stuff with POST this way:

if(isset($_POST['nim'])){
     $nim = $_POST['nim'];
}

Upvotes: 1

Related Questions