Vegard Berg Vegard Berg - 2 months ago 5
PHP Question

Insert MYSQL PHP into database

I'm trying to insert some data to my database, but it will only insert
an unique id and userid. Rest of the attributes wont follow. Any suggestions?

Image of insert: https://i.gyazo.com/6ef1ba391f49f98b293b7550e2d55727.png

<?php

if(isset($_POST['project']))
{

// Escape user inputs for security
$stripped = mysql_real_escape_string($_GET['id']);
$title = mysqli_real_escape_string($_POST['title']);
$about = mysqli_real_escape_string($_POST['about']);
$code = mysqli_real_escape_string($_POST['code']);

mysql_query("INSERT INTO cms_prosjekt (userid, title, about, code) VALUES
('".$_SESSION['user']['id']."', '".$title."', '".$about."', '".$code."')") or die(mysql_error());

}
?>



<form action="" method="post">

<input type="text" class="form-control" type="text" name="title" id="title" placeholder="Fullt navn" style="margin-bottom:10px">
<input type="text" class="form-control" type="text" name="about" id="about" placeholder="Kode bedrift" style="margin-bottom:10px">
<input type="text" class="form-control" type="text" name="code" id="code" placeholder="Passord" style="margin-bottom:10px">

<button type="submit" name="project" class="button" class="btn btn-success" style="margin-bottom:10px;">Register prosjekt nĂ¥</button>

</form>

Answer

Try this

if (isset($_POST['project'])) {
        $stripped = mysql_real_escape_string($_GET['id']);
        $title = mysql_real_escape_string($_POST['title']);
        $about = mysql_real_escape_string($_POST['about']);
        $code = mysql_real_escape_string($_POST['code']);

        mysql_query("INSERT INTO cms_prosjekt (userid, title, about, code) VALUES ('" . $_SESSION['user']['id'] . "', '" . $title . "', '" . $about . "', '" . $code . "')") or die(mysql_error());
    }
Comments