Sten Cooley Sten Cooley - 4 months ago 16
MySQL Question

Inserting into mySQL with PHP but nothing shows up in phpmyadmin

While trying to insert into a mySQL database I get no errors but nothing shows up in the phpmyadmin query. Here is the code for the php file that I am trying to insert with. I know this isn't the best way to do it but it's what I have so far.

<?php

require 'steamauth/steamauth.php';
require 'php/main.php';
require 'php/db.php';

$title = $_POST["title"];
$desc = $_POST["desc"];
$date = $_POST["date"];
$skills = $_POST["skills"];
$budget = $_POST["budget"];
$tc = $_POST["tc"];
$steamid = $steamprofile['steamid'];
$steamname = $steamprofile['personaname'];
$avatar = $steamprofile['avatarmedium'];
$dateposted = date("m-d-y");


// insert into db

if(1==1){

$insert = $link->query("INSERT INTO livepost (title, desc, date, skills, budget, tc, steamid, steamname, avatar, dateposted)
VALUES ('$title', '$desc', '$date' , '$skills' , '$budget', '$tc', '$steamid', '$steamname', '$avatar', '$dateposted')");

header('Location: index');

} else {

header('Location: index?insertdidntwork');

}

Answer

maybe you can try this one and you should always use $mysqli->error() function to know what type of error you have

   <?php
$title = $_POST["title"];
$desc = $_POST["desc"];
$date = $_POST["date"];
$skills = $_POST["skills"];
$budget = $_POST["budget"];
$tc = $_POST["tc"];
$steamid = $steamprofile['steamid'];
$steamname = $steamprofile['personaname'];
$avatar = $steamprofile['avatarmedium'];
$dateposted = date("m-d-y");
// insert into db
if (1 == 1) {
    $insert = $link ->query("INSERT INTO livepost (`title`,`desc`,`date`,`skills`,`budget`,`tc`,`steamid`,`steamname`,`avatar`,`dateposted`)

    VALUES ('".$title."', '".$desc."', '".$date."' , '".$skills."' , '".$budget."', '".$tc."', '".$steamid."', '".$steamname."', '".$avatar."', '".$dateposted."')") or die($mysqli -> error . __LINE__);
    header('Location: index');
} else {
    header('Location: index?insertdidntwork');
}
?>