Jump to content

php code gets "Connection has been reset"


Hypersource
Go to solution Solved by mentalist,

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!

Edited by Hypersource
Link to comment
Share on other sites

  • Solution

 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)

Link to comment
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.