neogemima Posted April 8, 2009 Share Posted April 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153237-solved-trouble-posting-to-database/ Share on other sites More sharing options...
redarrow Posted April 8, 2009 Share Posted April 8, 2009 $result = mysqli_query($query,$database_connection_variable); guessing Quote Link to comment https://forums.phpfreaks.com/topic/153237-solved-trouble-posting-to-database/#findComment-804984 Share on other sites More sharing options...
samshel Posted April 8, 2009 Share Posted April 8, 2009 Procedural style: mixed mysqli_query ( mysqli $link , string $query [, int $resultmode ] ) extract from manual...use the following $result = mysqli_query($db,$query); Quote Link to comment https://forums.phpfreaks.com/topic/153237-solved-trouble-posting-to-database/#findComment-804989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.