Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.