Jump to content

php code gets "Connection has been reset"


Hypersource

Recommended Posts

Read title.

 

Code:

<?php

//error_reporting(-1); //this will show all errors
//ini_set('memory_limit', '256M');
//ini_set('max_execution_time', 3000);
include 'c.php'; // connects to database 
$id = $_GET['id']; // get forum id
$sid = $id; // ...
$text = $_POST['chatext']; // chat text 
$name2 = $_POST['participant']; // chat username
$sname2 = $name2; // ..
$ip = $_SERVER['REMOTE_ADDR']; // get users ip for logging
$result = '';
//if this is a postback, send data to server.
if($_POST['postback'] == 'TRUE')
{

//everything needs to be sanitized before going into a SQL query
$sql = "INSERT INTO posts (ip,text,name,forumid) VALUES ($ip,$text,$sname2,$sid)";
mysqli_query($con,$sql) or die(mysql_error());
$result = 'chat submitted'; // easy error message showing
}
?>

<center>
<b color='red'><?php echo $result; ?></b>
<h1>Chat Box</h1>
<form method='POST' action='chatbox.php?id=<?php echo $id; ?>'>
<input name="participant" placeholder='Your Nickname' value="<?php echo $name2; ?>"><br><br>
<textarea name="chatext" placeholder='Chat Here' rows='4' cols='30'></textarea><br><br>
<input type='hidden' name='postback' value='TRUE'>
<input type='submit' value ='Submit'>
</form>
</center>

c.php:

<?php
$host = "*";
$database = "*";
$duser = "*";
$dpassword = "*";
$con=mysqli_connect($host,$duser,$dpassword,$database);

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/283319-php-code-gets-connection-has-been-reset/
Share on other sites

 no matter WHAT data I submit it says connection reset.. I even tried a bare-bones forum. (just a submit button nothing else not even php code)

 

it works completly O.K for GET though?!?!

 

What server software is it, are you saying you definately have PHP working, are you sure the database is working?

 

er, should the variables being inserted be wrapped in quotes? (I was ignoring validation issues)

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.