Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

php - Why doesn't it want to add a category?

i am making a cms for a school assiment but when i try to create a new category it keeps giving me errors: google chrome gives me this:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in Warning: Missing argument 3 for addCat(), called in C:xampphtdocsportfoliojbehrensadmindoAddc.php on line 6 and defined in C:xampphtdocsportfoliojbehrensincludesfunctions.php on line 254

Notice: Undefined variable: cDesc in C:xampphtdocsportfoliojbehrensincludesfunctions.php on line 255

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:xampphtdocsportfoliojbehrensincludesfunctions.php on line 256

Warning: Cannot modify header information - headers already sent by (output started at C:xampphtdocsportfoliojbehrensincludesfunctions.php:254) in C:xampphtdocsportfoliojbehrensadmindoAddc.php on line 7

here is my code: from the function page:

function addCat($mysqli, $cName, $cDesc){
    $query = "INSERT INTO categories (title, description) VALUES ('$cName', '$cDesc')";
    mysqli_query($mysqli, $query);
}

from the page that shout check the inputs:

<?php
include '../includes/functions.php';
sec_session_start();
if(isset($_POST['submit'])){
    if(isset($_POST['CatName'])){
        addCat($_POST['CatName'],$_POST['CatDesc']);
        header("Location: categories.php");
    } else{
        echo"please set a category name!";
        include('addCat.php');
    }
}else{
    header("Location: addCat.php");
}
 ?>

and finally the input:

<form action="doAddc.php" method="post">
   <label for="CatName">Name</label>
   <input type="text" name="CatName" id="CatName"/>
   <label for="CatDesc">Description</label>
   <input type="text" name="CatDesc" id="CatDesc"/>
   <input type="submit" name="submit" value="submit"/>
</form>

hope some of u know what i am doing wrong here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to pass through your mysql database connection to the addCat function as the first parameter.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...