Jump to content

Not Inserting into database


Dracolas

Recommended Posts

Hi

 

Currently it will never insert anything to the database as the line with the insert is commented out, and even if it wasn't it is merely setting up the SQL for it and not attempting to execute it.

 

Can't really see a reason why it would put out the error line if you have pressed submit (unless you have a VERY old version of php), but it does seem likely it would display the error on initial load

 

Quick reformat so I can see what goes where:-

 

<?php
error_reporting(E_ALL);
include("header.php");

require("db.php");
include("funcs.php");

//checks cookies to make sure they are logged in 
if(isset($_COOKIE['ID_my_site'])) 
{ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site']; 
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); 
$result = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); 
$row = mysql_fetch_array($result) or die(mysql_error());
$crank = $row['rank'];

while($info = mysql_fetch_array( $check )) 
{  
	//if the cookie has the wrong password, they are taken to the login page 
	if ($pass != $info['password']) 
	{ 
		header("Location: login.php"); 
	} 
}
} 
else 
//if the cookie does not exist, they are taken to the login screen 
{ 
header("Location: login.php"); 
} 

if ($crank <= 4) 
{
if (isset($_POST['submit'])) 
{
	// now we insert it into the database   
	$insert = "INSERT INTO wars (`username`, `date`, `opponent`, `osite`, `type`, `player1`, `player2`, `opponent1`, `opponent2`, `cshot`, `r1shot`, `r2shot`,    `r3shot`, `result`, `comments`)   VALUES ( $username, NOW(), '".$_POST['opponent']."' , '".$_POST['osite']."' , '".$_POST['type']."' , '".$_POST['player1']."' , '".$_POST['player2']."' ,    '".$_POST['opponent1']."' , '".$_POST['opponent2']."' , '".$_POST['cshot']."' , '".$_POST['r1shot']."' , '".$_POST['r2shot']."' , '".$_POST['r3shot']."' , '".$_POST['result']."' ,    '".$_POST['comments']."')";   
	if ($add_member = mysql_query($insert))   
	{
?>
<h1>War Added</h1>
<p>Thank you, War added.</p>
<a href="console.php">Back to Console</a>
<?php 
	} 
	else 
	{
		print('Error: '.mysql_error().'<br/>');
	}
?>
<h1><center>Add War Report</center></h1><p>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Clan Name: <input type='text' name='opponent'><br>
Site: <input type='text' name='osite'><br>
Challenge Type: 
<select name='type'>
	<option value=1v1>1v1</option> 
	<option value=2v2>2v2</option> 
</select>
<br>Player 1: 
<Select name='player1'>
<?php	
	$result = mysql_query("SELECT * FROM users order by rank");
	while($row = mysql_fetch_assoc($result))
	{
		$name = $row['username'];
		echo "<option value='$name'>$name</option>";
	}
?>
</select><br>
Player 2: 
<Select name='player2'>
<?php	
	$result = mysql_query("SELECT * FROM users order by rank");
	while($row = mysql_fetch_assoc($result))
	{
		$name = $row['username'];
		echo "<option value='$name'>$name</option>";
	}
?>
</select><br>
Opponent 1: <input type='text' name='opponent1'><br>
Opponent 2: <input type='text' name='opponent2'><br>
<p>
Screenshots:
Challenge: <input type='text' name='cshot'><br>
Round 1: <input type='text' name='r1shot'><br>
Round 2: <input type='text' name='r2shot'><br>
Round 3: <input type='text' name='r3shot'><br>
<p>
Win/Loss:
<select name='result'>
	<option value='win'>Win</option>
	<option value='loss'>Loss</option>
</select><br>
Comments:<br>
<textarea name='comments' cols='50' rows='5'></textarea>
<input type="submit" name="submit" value="Add War">;
<?php
}
}
else 
{	
echo('Sorry, only Corporals or above may Recruit at this time');
echo('<br><a href="console.php">Back To Console</a>');
}
include("footer.php");
?>

 

All the best

 

Keith

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.