Dracolas Posted January 27, 2010 Share Posted January 27, 2010 http://www.sourcepod.com/iowaog17-2672 why is it not inserting into the database? why is there no error msg after the Error: that is a screenshot of the page sourced above. Quote Link to comment https://forums.phpfreaks.com/topic/190023-not-inserting-into-database/ Share on other sites More sharing options...
kickstart Posted January 27, 2010 Share Posted January 27, 2010 Hi It would appear it just goes to display error and the MySQL error message if the submit button hasn't been pressed, irrespective of whether there is an SQL error. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/190023-not-inserting-into-database/#findComment-1002696 Share on other sites More sharing options...
Dracolas Posted January 28, 2010 Author Share Posted January 28, 2010 ok....how would i fix that and why isn't it inserting to the database? Quote Link to comment https://forums.phpfreaks.com/topic/190023-not-inserting-into-database/#findComment-1003133 Share on other sites More sharing options...
kickstart Posted January 28, 2010 Share Posted January 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190023-not-inserting-into-database/#findComment-1003157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.