Good Day Daniwebbers!
Wonder if I can have some help. I am trying to build an 'admin panel' of sorts where the user can add content to their website, edit and delete it, all from one spot (Not unlike a CMS system I guess but purely for the purpose of uploading news/case studies ect)

Now pretty much have everything done except for this one edit function that I cannot seem to fathom (I have the other edit functions working but this one is eluding me)

So basically to summarise the problem, The user navigates to a list of case studies, from here they can select the case study they want to delete or edit.

They click on the 'Edit' link which will redirect them to a form. This form is populated by the data from the database depending on the ID of the case study.

HOWEVER! When the 'Submit' button is clicked nothing happens.

I have checked and double checked the variables and the database field names as well as the html tables names and they all seem the match up. I'm wondering if someone with an outside perspective can point me in the right direction if it wouldn't be too much trouble?

This is the code to actually make the changes:

function editcase($i)

{
    ini_set('display_errors',1);
    error_reporting(E_ALL);

    $conn = mysqli_connect("Connection String");

    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    $enquery =  "SELECT * FROM casestudy WHERE caseid='$i'";
    $enresult = mysqli_query($conn, $enquery) or trigger_error($enquery . ' - has encountered an error at:<br />');

    if ($enresult) {

    while ($enrow = mysqli_fetch_array($enresult)) {

    echo "
                <form enctype='multipart/form-data' action='functions/caseedit.php' method='post'>
                <table>

                    <tr>
                    <td>News Ref:</td>
                    <td>" . $i . "<input type='hidden' name='cid' value='" . $i . "' /><input type='hidden' name='oldfi' value='" . $enrow['casefile'] . "' /></td>
                </tr>


                    <tr>
                        <td>Title:</td>
                        <td><input type='text' name='title' value='" . $enrow['casetitle'] . "' size='100' /></td>
                    </tr>

                        <tr>
                        <td>Author:</td>
                        <td><input type='text' name='author' value='" . $enrow['caseauthor'] . "' size='100' /></td>
                    </tr>

                    <tr>
                        <td>Status:</td>
                        <td><select name='stat'><option value='enabled' ";
                        if ($enrow['casestatus'] == "enabled")
                        {
                            echo "selected='selected' ";
                        }
                        echo ">Enabled</option><option value='disabled' ";
                        if ($enrow['casestatus'] == "disabled")
                        {
                            echo "selected='selected' ";
                        }
                        echo "}>Disabled</option></select>
                    </td>
                    </tr>

                    <tr>
                        <td>Snippet Text:</td>
                        <td><textarea name='snip' rows='6' cols='80'>" . $enrow['casesnippet'] . "</textarea></td>
                    </tr>

                    <tr>
                        <td>Current File:</td>
                       <td>" . $enrow['casefile'] . " - <a href='news/" . $enrow['casefile'] . "' target='_blank'>View   File</a></td>
                    </tr>

                    <tr>
                        <td>Change File:</td>
                        <td><input type='file' name='file'></td>
                    </tr>

                    <tr>
                        <td colspan='2'><input type='submit' name='submit' value='Edit' /></td>
                    </tr>
                </table>
                </form>
            ";
                }

        }
            else {
            echo "Oh noes, an error!";
        }
}

When submit is selected on the form it should run this code:

<?php
$i = $_POST['cid'];
$t = $_POST['title'];
$a = $_POST['author'];
$st = $_POST['stat'];
$sn = $_POST['snip'];



$conn = mysqli_connect("Connection String") or die ("Could not connect to database");
if(!is_uploaded_file($_FILES['file']['tmp_name']))
{
    $naquery = "UPDATE casestudy SET casetitle='$t',caseauthor='$a',casestatus='$st',casesnippet='$sn', WHERE caseid=$i";

    mysqli_query($conn, $ebquery);
}
else
{
    if ($_FILES['file']['type'] != "application/pdf"  && $_FILES['file']['type'] != "application/msword"  && $_FILES['file']['type'] != "application/vnd.openxmlformats-officedocument.wordprocessingml.document"  && $_FILES['file']['type'] != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"  && $_FILES['file']['type'] != "application/vnd.ms-excel")
    {
        $naquery = "UPDATE casestudy SET casetitle='$t',caseauthor='$a',casestatus='$st',casesnippet='$sn', WHERE caseid=$i";
        mysqli_query($conn, $naquery);
    }
    else
    {
        $finame = $_FILES["file"]["name"];
        //$ext = end(explode(".", $finame));
        $result = move_uploaded_file($_FILES['file']['tmp_name'], "../casestudy/$finame");
        if ($result == 1)
        {
            $naquery = "UPDATE casestudy SET casetitle='$t',caseauthor='$a',casestatus='$st',casesnippet='$sn', casefile='$finame' WHERE caseid=$i";
            mysqli_query($conn, $naquery);
        }
        else
        {
            $naquery = "UPDATE casestudy SET casetitle='$t',caseauthor='$a',casestatus='$st',casesnippet='$sn', WHERE caseid=$i";
            mysqli_query($conn, $naquery);
        }
    }

}
if($result){
    echo "Data Edited successfully<br />";
    echo "click <a href='link'>here</a> to return to Case Studies";
}

else {
    echo "Ohes Noes! An Error has occured";
    echo "click <a href='link'>here</a> to return to Case Studies";
}

$conn-> close();
?>

It runs to some extent in the sense that I get the echo'd "Ohes Noes! An Error has occured" message.
If anyone could give me a nudge in the right direction I would very much appreciate it!

Thanks in Advance!

Your queries have a comma before the WHERE, it will generate an error. Remove it.

Commas have been removed!
Thanks, I feel a bit daft about it being something so small.

I just couldn't see it though

Thank you!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.