Jump to content

Not submitting to database?


3raser

Recommended Posts

For some reason it just stopped working. It was fine earlier. I don't even think I messed with it. :/

 

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

 

The data wont go in the database for some reason.

Link to comment
Share on other sites

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.";
	}

}
?>

Link to comment
Share on other sites

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>";

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.