Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2016
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Error querying database

    Hi, I got this code to add new suggestion and this can only be added by student.

    Code:
    <?php
    include 'dbConnection.php';
    if (isset($_SESSION['ID']) && $_SESSION['role'] == "student") {
        ?>
    
        <div align ="center">
            <fieldset>
                <form name="submitSuggestion" method="post" action="dosubmitSuggestion.php">
                    <font face="Arial" size="normal">
                    <table style="width: 80%;">
                        <tr>
                            <td colspan="2" align="center"><h3>Submit Suggestion</h3></td>
                        </tr>
                        <tr>
                            <td>Suggestion Title</td>
                            <td><input name="suggestionTitle" size="20" style="width: 300px"></td></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>Description</td>
                            <td><textarea name="description" rows="4" cols="50" style="width: 300px"></textarea></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
    
                        <tr>
                            <td>Email</td>
                            <td><input name="email" size="20" style="width: 300px"></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
    
                        <tr>Suggested By</td>
                            <td><input name="name" value="<?php echo $name; ?>"></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
    
                        <tr align="center">
                            <td><input type='submit' value='Submit Suggestion'></td>
                            <td><input type='reset' value='Reset'></td>
                        </tr>
    
                    </table>
                    </font>
                </form>
            </fieldset>
        </div>
        <?php
    } else {
        ?>
    
        <h4> <font color = "red">No Access Granted</font></h4>
        <?php
    }
    ?>
    After I submit the suggestion, it will proceed to this page.

    Code:
    <?php
    include 'dbConnection.php';
    if (isset($_SESSION['ID']) && $_SESSION['role'] == "student") {
        ?>
        <?php
        $suggestionTitle = $_POST["suggestionTitle"];
        $description = $_POST["description"];
        $email = $_POST["email"];
        $name = $_POST['name'];
        $date = date("Y-m-d");
    
        $query = "Insert into suggestion (suggestionTitle, description, email, suggestedBy, sugestedDate) VALUES ('$suggestionTitle','$description','$email','$name','$date')";
    
        $submitted = mysqli_query($link, $query) or die('Error querying database');
    
        if ($submitted) {
            $message = "New Suggestion is Successfully added.";
        } else {
            $message = "Suggestion is not Successful created";
        }
    
        mysqli_close($link);
        ?>
    
        <?php
        echo $message;
        ?>
    
        <?php
    } else {
        ?>
    
        <h4><font color = "red">No Access Granted</font></h4>
        <?php
    }
    ?>
    But it will show this message, "Error Querying Database".

    I still cannot figure out where is my mistake. Can anyone assist. Thanks

    My database for suggestedDate is in Date format

  2. #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    15,060
    Thanks
    165
    Thanked 2,250 Times in 2,237 Posts
    Change
    $submitted = mysqli_query($link, $query) or die('Error querying database');
    to
    PHP Code:
    $submitted mysqli_query($link$query) or die(mysqli_error($link)); 
    and check the output.

  3. Users who have thanked abduraooft for this post:

    justin0312 (Feb 27th, 2017)

  4. #3
    New Coder
    Join Date
    May 2016
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks, it solved my issue. Is my database table name type wrongly.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •