0

Can anyone see a reason why this would be failing to connect with / write to a mysql database? I can't be sure which but I know the data isn't entering when the form is submitted. It just routes to a blank screen.

The html

<html>
<div style="width:  330px;  height:  130px;  overflow:  auto;">
<form STYLE="color: #f4d468;" action="send_post.php" method="post">

Category: <select STYLE="color: #919191; font-family: Veranda; 
font-weight: bold; font-size: 10px; background-color: #000000;" 
name="category">
<option value="blah1">blah1</option>
<option value="blah2">blah2</option>
<option value="blah3">blah3</option>
<option value="blah4">blah4</option>
</select> <br>

<textarea overflow: scroll; rows="4" cols="60" STYLE="color: 

#919191; font-family: Veranda; font-weight: bold; font-size: 10px; 

background-color: #000000; width:300px; height:80px; margin:0; 

padding:0;" name="contents">
</textarea><br>

<input type="submit" STYLE="color: #919191; font-family: Veranda; 
font-weight: bold; font-size: 10px; background-color: #000000;" 
value="Create Log">
</form>
</div>
</html>

and send_post.php

<?php
//Connecting to sql db.
$connect=mysqli_connect("localhost","username","password","mysqldatabasename");

//Sending form data to sql db.
mysqli_query($connect,"INSERT INTO mytablename (category, contents)
VALUES ('$_POST[category]', '$_POST[contents]')";
?>

I'm new to this but I researched hard and now I'm at an impasse. I've tried entering code that checks for connection errors but I always just get a white screen and no db updates. I would greatly appreciate help. (Also do the quotes stay included in "localhost", "username" etc?)

5
  • Again, just a plain white screen with no text return. Commented Sep 18, 2013 at 18:08
  • 1
    Ever heard of SQL injection? Commented Sep 18, 2013 at 18:09
  • i tried it in another browser and got Server error The website encountered an error while retrieving blah.com/send_post.php. It may be down for maintenance or configured incorrectly. Commented Sep 18, 2013 at 18:10
  • As I said guys, I'm really new. I can enable captcha to protect for attacks and i'll look into error reporting. Right now I'm trying to end an 8 hour quandry for something that seems like it should be simple. Commented Sep 18, 2013 at 18:13
  • Captcha does not help against injections in the slightest. Use MySQLi prepared statements: php.net/manual/en/mysqli.prepare.php Commented Sep 18, 2013 at 18:19

1 Answer 1

1

Seems to be a simple syntax error.

Missing a closing ) here:

mysqli_query($connect,"INSERT INTO mytablename (category, contents) VALUES ('$_POST[category]', '$_POST[contents]')"); 

The arguments for the mysqli_connect do need to be enclosed in quotes. You also might want to seriously consider sanitizing your inputs. This form is wide open.

Sign up to request clarification or add additional context in comments.

5 Comments

trying this nowand thanks. Do you know some documents I can read up on to sanitize things?
The minimum would be using php.net/manual/en/mysqli.real-escape-string.php. If this answer does it for you, feel free to accept it!
You guys are heros! Stupid bracket costed me hours haha. Alright thanks chums, I will study up on security and get this much more cleaned up, just privately experimenting with my first sql. Thanks again and if you guys have any security links to throw at me I'd be grateful. Peace!
Are you using an IDE to write your code? Its syntax highlighting should have pointed out the missing parenthesis.
There are a number of good IDEs that will work. Eclipse is nice as well as Netbeans and many others. It is a personal preference thing, and you should probably try a couple out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.