Jump to content

Not submitting to database?


3raser

Recommended Posts

Anyone?

 

Full code:

 

<?php
include("config.php");
if(!$_GET['id'] || $_POST['id'])
{
	$id = $_POST['id'];
}
else
{
	$id = $_GET['id'];
}

if(!$id)
{
	echo "You haven't selected a server you'd like to join! <a href='index.php'>Home</a>";
}
else
{
$username = mysql_real_escape_string($_POST['username']);
$age = mysql_real_escape_string($_POST['age']);
$why = mysql_real_escape_string($_POST['why']);

	$sql = mysql_query("SELECT title,closed,id,username FROM servers WHERE id='$id'");

	if(!mysql_num_rows($sql))
	{
		echo "No such server exists!";
	}
	elseif(!$_POST['username'] || !$_POST['age'] || !$_POST['why'])
	{
		echo "Your Minecraft username: <form action='join.php' method='POST'><input type='text' name='username'>
		<input type='hidden' name='id' value='". $id ."'><br/><br/>
		Your age: <br/><input type='text' name='age'><br/><br/>
		Why should we accept you:<br/><textarea rows='15' cols='25' name='why' maxlength='250'></textarea><br/><input type='submit'>
		</form>";
	}
	elseif(is_numeric($age))
	{

		$ip = $_SERVER['REMOTE_ADDR'];
		$random = md5($why.$ip.$id.$age.$username);

		mysql_query("INSERT INTO apps VALUES ('', '$username', '$age', '$why', '$ip', '$random', '$id', '0')");

		echo "Whitelist application sent!<br/> If you wisht to check the status, write down this code: <b>". $random ."</b>
		<a href='index.php'>Home</a>";
	}
	else
	{
		echo "Age must be numbers only! Click back in your browser.";
	}

}
?>

Probably a good time to throw in some logic to see what the query is actually doing.

 

$ip = $_SERVER['REMOTE_ADDR'];
$random = md5($why.$ip.$id.$age.$username);
$query = "INSERT INTO apps VALUES ('', '$username', '$age', '$why', '$ip', '$random', '$id', '0')";
if( $result = mysql_query($query) ) {
if( mysql_affected_rows() < 1 ) {
	echo '<br>Query ran, but no record was inserted<br>';
}
} else {
echo "<br>Query string: $query<br>Produced error: " . mysql_error() . '<br>';
}
echo "Whitelist application sent!<br/> If you wisht to check the status, write down this code: <b>". $random ."</b>
<a href='index.php'>Home</a>";

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.