0

I have student table in my DB , and I need to create extra form in student page so he can update the details. However im getting this error ( Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\WebInterfaceLogIn\studentEdit.php on line 81)

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
include ('includes/connection.php');

 // Create connection

if (isset($_POST["submit"]))
{ //Determine if a variable is set and is not NULL.
    if (!empty($_POST['ID']) && !empty($_POST['user']) && !empty($_POST['surr']) && !empty($_POST['course']) && !empty($_POST['mail']) && !empty($_POST['pass']))
    { //Determine if user enters both user name and password.
        $ID = $_POST['ID']; // enters user ID in database
        $user = $_POST['user']; // enters user name in database
        $surr = $_POST['surr']; // enters user surname in database
        $course = $_POST['course']; // enters user course in database
        $pass = $_POST['pass']; // enters password in database
        $mail = $_POST['mail'];

        // $query = mysqli_query($con,"SELECT * FROM students WHERE Student_ID='".$ID."'");  // change to update

        $query = mysqli_query("UPDATE students SET `course` = " . $_POST['course'] . ", `email` = " . $_POST['mail'] . " Student_ID='" . $ID . "'");
        $numrows = mysqli_num_rows($query);
        if ($numrows == 0)
        {
            $sql = "INSERT INTO students(Student_ID,Name,Surname,Course,email,password) VALUES('$ID', '$user','$surr','$course','$mail','$pass')"; // insert user name and password to database
            $result = mysqli_query($con, $sql);

            // Checks does user enters the details

            if ($result)
            {
                echo '<script language="javascript">;
                     alert("Account Successfully Updated");
                        document.location.href="index.php";
                     </script>';
            }
            else
            {
                echo mysqli_error($con);
            }
        }
    }
    else
    {
        echo '<script language="javascript"> 
                                alert("All fields required")
                             </script>';
    }
}

Can anyone can help to solve this problem?

2 Answers 2

1

You need pass connection object to function mysqli_query, something like this:

mysqli_query($con,"UPDATE students SET `course` = " .$_POST['course']. ", `email` = " .$_POST['mail']. " Student_ID='".$ID."'");

See more details on: http://www.w3schools.com/php/func_mysqli_query.asp

Sign up to request clarification or add additional context in comments.

Comments

0

The error is explicit enough.

add $con as a first parameter to your mysqli_query function on this line:

$query = mysqli_query("UPDATE students SET `course` = " . $_POST['course'] . ", `email` = " . $_POST['mail'] . " Student_ID='" . $ID . "'");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.