0

i revamped my mysqli db to insert values from my form into the db using prepared statements. Thanks stackoverflow - i learned this is the way to go by reading up on this site.

Changed my statements to look like below, but for some reason they aren't inserting into the db. What could I be doing wrong? I added '' around my strings but that did not work... not sure what I could be missing. I started from a tutorial and worked my way around to this set of code.

Any help getting my insert to work would be appreciated, I am new to mysqli prepared statements. Here is my code:

  <?php
  $con= new mysqli("localhost","admin1","default","sourcesDB");
  // Check connection

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

  $biotext = $_POST[$bio];

        $keywords= json_encode($_POST['Keyword_ID']);
        $assocs= json_encode($_POST['Associations']);
        $fname = $_Post['FName'];
        $mname = $_POST['MName'];
        $lname = $_POST['LName'];
        $suffix = $_POST['Suffix'];
        $dept = $_POST['Dept'];
        $title = $_POST['Title'];
        $title2 = $_POST['Title2'];
        $title3 = $_POST['Title3'];
        $edu = $_POST['Education'];
        $edu2 = $_POST['Education2'];
        $edu3 = $_POST['Education3'];
        $ph1 = $_POST['PH1'];
        $ph2 = $_POST['PH2'];
        $email = $_POST['Email'];
        $pic = $_POST['Pic'];
        $linkname = $_POST['LinkName'];
        $website = $_POST['Website'];
        $tags = $_POST['Tags'];
        $bio = $_POST['bioLinks'];


  $stmt = $con->prepare('INSERT IGNORE INTO profileTable
   (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ');

  $stmt->bind_param('sssssssssssssssssssss', $fname, $mname, $lname, $suffix, $dept,
  $title, $title2, $titl3, $edu, $edu2, $edu3, $ph1, $ph2, $email,  $pic, $linkname,
  $bio, $website, $keywords, $tags, $assocs);

  if($stmt->execute()) {
echo '<div style="color: green;">Profile Added!</div>';
echo "<meta http-equiv='Refresh' content='4; URL=addProfile.php'>";
  }
  else {
echo "Failed to insert";
  }

  $stmt->close();
MizAkita
  • 1,115
  • 5
  • 21
  • 52

1 Answers1

0

I was able to answer this question on my own... i added the names of the columns to insert into and then bound my params to my value. In the end, this is what ended up working flawlessly...

    if ($stmt = $con->prepare("INSERT INTO profileTable (FirName, MName, LaName,
         Suffix, Dept, Title, Title2, Title3, Education, Education2, Education3,
         PH1, PH2, Email, Photo, BioLK, Website, Keyword_ID, Tags, Associations) 
          VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));

         {
      $stmt->bind_param("ssssssssssssssssssss", $fname, $mname, $lname, $suffix, 
         $dept, $title, $title2, $title3, $edu, $edu2, $edu3, $ph1, $ph2, $email,
         $linkname, $bio, $website, $keywords, $tags, $assocs);

      $stmt->execute();
         echo '<div style="color: green;">Profile $fname $lname Added!</div>';
         echo "<meta http-equiv='Refresh' content='4; URL=addProfile.php'>";

       $stmt->close();

       mysqli_close($con);
        }
MizAkita
  • 1,115
  • 5
  • 21
  • 52