Jump to content

[SOLVED] Trouble posting to database


neogemima

Recommended Posts

I am pretty new to PHP and MySQL and some code is making me tear my hair out.  I have a form, and just need to upload the data to my table that is already made in my database.

 

Here is my code:

<?php

//create short variable names

 

$title=$_POST['title'];

$newscontent=$_POST['newscontent'];

 

if (!$title || !newscontent) {

echo "Please fill out both the title of the posting and the content.<br>";

exit;

}

 

if (!get_magic_quotes_gpc()) {

$title = addslashes($title);

$newscontent = addslashes($newscontent);

}

 

@ $db = mysqli_connect('hostname', 'user', 'pass', 'database');

 

 

if (mysqli_connect_errno()) {

echo "Error: Could not connect to database.  Please try again later.";

exit;

}

 

$query = "INSERT INTO NEWSPOSTING (title, content) VALUES ('$title', '$content')";

$result = mysqli_query($query);

 

 

if ($result) {

echo mysqli_affected_rows.' posting added to database.';

} else {

echo "An error has occured.  The item was not added.";

}

 

mysqli_close($db);

 

 

?>

 

The lines:

 

$query = "INSERT INTO NEWSPOSTING (title, content) VALUES ('$title', '$content')";

$result = mysqli_query($query);

 

keep returning an error no matter what I do.  Here is the error:

 

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/content/b/i/o/biotechposting/html/pages/forms/insert_news.php on line 37

An error has occured. The item was not added.

 

Does anyone have any suggestions?  Much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/153237-solved-trouble-posting-to-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.