peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 Ok map done. Now back to my buy soldier.php again lol I dont know what error this throws back, it just displays a blank screen, but i do know that the user info work but the insert into soldier table don't seem to insert. and reason why this might be? <?php include "header.php"; $action = ( array_key_exists( 'action', $_GET) ? $_GET['action'] : "" ); switch ($action) { case "buy1": buy1_soldier(); break; case 'buy2': do_buy1_soldier(); break; default: echo " <h2>Buy Soldiers</h2> Here you can buy a Soldier to fight for you.<br /><br /> <a href='buysoldier.php?action=buy1'>Buy your Soldier (Level 1) - 50 Coins</a>"; } function buy1_soldier() { print "<h3>Name your Soldier</h3> <form action='buysoldier.php?action=buy2' method='post'> Soldiers Name<input type='text' name='soldiername' /><br /> Are you sure?<br /> <input type='submit' value='Create Soldier (50 coins)' /></form>"; } function do_buy1_soldier() { $session=$_SESSION['email']; $con = mysqli_connect('localhost','user','pass','db'); $query1="UPDATE users SET soldiers=soldiers+1, coins=coins-50 WHERE user_email='$session'"; mysqli_query($con, $query1); $run = mysqli_query($con, "SELECT * FROM users WHERE user_email = '$session'"); while ($row=mysqli_fetch_array($run)){ $user_id = $row[0]; } $soldiername = $_POST['soldiername']; $query = "INSERT INTO soldier ('', 'owner', 'soldiername', 'soldierrank', '', '', '', '', '', '','','') VALUES( '', '$user_id', '$soldiername', '1', '', '', '', '', '', '','','')"; if(mysqli_query($con, $query)) { echo "Soldier Created"; } } include "footer.php"; ?> Quote Link to comment Share on other sites More sharing options...
Zettieee Posted December 2, 2014 Share Posted December 2, 2014 Ok map done. Now back to my buy soldier.php again lol I dont know what error this throws back, it just displays a blank screen, but i do know that the user info work but the insert into soldier table don't seem to insert. and reason why this might be? <?php include "header.php"; $action = ( array_key_exists( 'action', $_GET) ? $_GET['action'] : "" ); switch ($action) { case "buy1": buy1_soldier(); break; case 'buy2': do_buy1_soldier(); break; default: echo " <h2>Buy Soldiers</h2> Here you can buy a Soldier to fight for you.<br /><br /> <a href='buysoldier.php?action=buy1'>Buy your Soldier (Level 1) - 50 Coins</a>"; } function buy1_soldier() { print "<h3>Name your Soldier</h3> <form action='buysoldier.php?action=buy2' method='post'> Soldiers Name<input type='text' name='soldiername' /><br /> Are you sure?<br /> <input type='submit' value='Create Soldier (50 coins)' /></form>"; } function do_buy1_soldier() { $session=$_SESSION['email']; $con = mysqli_connect('localhost','user','pass','db'); $query1="UPDATE users SET soldiers=soldiers+1, coins=coins-50 WHERE user_email='$session'"; mysqli_query($con, $query1); $run = mysqli_query($con, "SELECT * FROM users WHERE user_email = '$session'"); while ($row=mysqli_fetch_array($run)){ $user_id = $row[0]; } $soldiername = $_POST['soldiername']; $query = "INSERT INTO soldier ('', 'owner', 'soldiername', 'soldierrank', '', '', '', '', '', '','','') VALUES( '', '$user_id', '$soldiername', '1', '', '', '', '', '', '','','')"; if(mysqli_query($con, $query)) { echo "Soldier Created"; } } include "footer.php"; ?> Set error reporting to E_ALL Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted December 2, 2014 Share Posted December 2, 2014 Ok map done. Now back to my buy soldier.php again lol I dont know what error this throws back, it just displays a blank screen, but i do know that the user info work but the insert into soldier table don't seem to insert. and reason why this might be? <?php include "header.php"; $action = ( array_key_exists( 'action', $_GET) ? $_GET['action'] : "" ); switch ($action) { case "buy1": buy1_soldier(); break; case 'buy2': do_buy1_soldier(); break; default: echo " <h2>Buy Soldiers</h2> Here you can buy a Soldier to fight for you.<br /><br /> <a href='buysoldier.php?action=buy1'>Buy your Soldier (Level 1) - 50 Coins</a>"; } function buy1_soldier() { print "<h3>Name your Soldier</h3> <form action='buysoldier.php?action=buy2' method='post'> Soldiers Name<input type='text' name='soldiername' /><br /> Are you sure?<br /> <input type='submit' value='Create Soldier (50 coins)' /></form>"; } function do_buy1_soldier() { $session=$_SESSION['email']; $con = mysqli_connect('localhost','user','pass','db'); $query1="UPDATE users SET soldiers=soldiers+1, coins=coins-50 WHERE user_email='$session'"; mysqli_query($con, $query1); $run = mysqli_query($con, "SELECT * FROM users WHERE user_email = '$session'"); while ($row=mysqli_fetch_array($run)){ $user_id = $row[0]; } $soldiername = $_POST['soldiername']; $query = "INSERT INTO soldier ('', 'owner', 'soldiername', 'soldierrank', '', '', '', '', '', '','','') VALUES( '', '$user_id', '$soldiername', '1', '', '', '', '', '', '','','')"; if(mysqli_query($con, $query)) { echo "Soldier Created"; } } include "footer.php"; ?> ok so i took the code and inserted it into a mccodes file replaced the header and footer replaced with with was needed for mccodes anyways there is no errors showing up on the main page it displaying fine for me ok for your inserting issue i was cleaning up the code a little and noticed this $query = "INSERT INTO soldier ('','owner', 'soldiername', 'soldierrank', '', '', '', '', '', '','','') VALUES('','$user_id', '$soldiername', '1', '', '', '', '', '', '','','')"; whats all the empty single quotes for if these have default values you don't need to add the single quotes also for a auto increment you don't need to add the ' ' for that as well `Test` int(10) not null default 0 also i have noticed you used ' instead of ` try the code below see if it helps $query = "INSERT INTO soldier (`owner`, `soldiername`, `soldierrank`) VALUES('$user_id', '$soldiername', '1')"; if soldierrank is set to default 1 in the sql table then there is no need to insert this info Quote Link to comment Share on other sites More sharing options...
peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 already set to Set error reporting to E_ALL and blank page And to non stop coding, i dont know about mccodes as i'm not using mccodes lol. but the blanks was autofilled into the db so ok i understand that part. The new line of code, $query = "INSERT INTO soldier (`owner`, `soldiername`, `soldierrank`) VALUES('$user_id', '$soldiername', '1')"; Does the same thing, it takes away the 50 coins, gives you 1 soldier count but still enters nothing into the soldier field on the site.... Soldier Rank isnt in the table and done php side. Quote Link to comment Share on other sites More sharing options...
G7470 Posted December 2, 2014 Share Posted December 2, 2014 When this query runs, check the data in the soldier table. Are all of the fields of the soldier table filled in correctly? If not, then that could be where your problem is. If all of the data in the soldier table is in fact correct, then the issue is not directly related to the insert; rather, it is the display. There must be some kind of condition or other issue that is causing the "soldier field" to be empty. Do you have to maybe refresh the page to get the soldier to display? Not sure what else I could advise you to do without actually seeing this in action or doing a full code trace. ~G7470 Quote Link to comment Share on other sites More sharing options...
peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 When this query runs, check the data in the soldier table. Are all of the fields of the soldier table filled in correctly? If not, then that could be where your problem is. If all of the data in the soldier table is in fact correct, then the issue is not directly related to the insert; rather, it is the display. There must be some kind of condition or other issue that is causing the "soldier field" to be empty. Do you have to maybe refresh the page to get the soldier to display? Not sure what else I could advise you to do without actually seeing this in action or doing a full code trace. ~G7470 Well i dont know, it just shows up a blank page. tried to refresh, just takes more coins and adds +1 soldier count in users but inserts nothing into the soldier table in the database. My buysoldier page is above in the posts and the Database is below -- -- Table structure for table `soldier` -- CREATE TABLE IF NOT EXISTS `soldier` ( `soldierid` int(11) NOT NULL AUTO_INCREMENT, `owner` int(11) NOT NULL, `soldiername` text NOT NULL, `soldierrank` int(11) NOT NULL, `soldierxp` int(11) NOT NULL DEFAULT '0', `soldierwep` int(11) NOT NULL DEFAULT '0', `soldierarmour` int(11) NOT NULL DEFAULT '0', `soldierspower` decimal(11,4) NOT NULL DEFAULT '10.0000', `soldiersdefence` decimal(11,4) NOT NULL DEFAULT '10.0000', `soldiersaglity` decimal(11,4) NOT NULL DEFAULT '10.0000', `health` int(11) NOT NULL DEFAULT '100', `maxhealth` int(11) NOT NULL DEFAULT '100', PRIMARY KEY (`soldierid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted December 2, 2014 Share Posted December 2, 2014 (edited) thats because your using a variable and no declaring it $soldiername would need to be $soldiername = mysql_real_escape_string($_POST['soldiername']); As you are using a post method for the soldiername you need to use the post variable $_POST['then the name value'] as you used soldiername Edited December 2, 2014 by NonStopCoding Quote Link to comment Share on other sites More sharing options...
peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 thats because your using a variable and no declaring it $soldiername would need to be $soldiername = mysql_real_escape_string($_POST['soldiername']); someplace before the query Nope Still does the same thing lol, If i PM'ed you the cpanel details would you take a look. because i feel like smashing the code lol Quote Link to comment Share on other sites More sharing options...
G7470 Posted December 2, 2014 Share Posted December 2, 2014 I agree with [MENTION=70347]NonStopCoding[/MENTION] I'm thinking it has something to do with that $_POST variable, but in a little different way. I would echo out the $soldiername before running the query to verify that there is a value going in there as well as the $user_id fields, like the following: while ($row=mysqli_fetch_array($run)){ $user_id = $row[0]; } $soldiername = $_POST['soldiername']; echo $soldiername . " "; echo $user_id . " "; One you have verified that those values are being filled in, you can remove the echo statements, but that is a good way to error check. If one of these values are not getting filled in, we can go from there. ~G7470 Quote Link to comment Share on other sites More sharing options...
peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 I agree with [MENTION=70347]NonStopCoding[/MENTION] I'm thinking it has something to do with that $_POST variable, but in a little different way. I would echo out the $soldiername before running the query to verify that there is a value going in there as well as the $user_id fields, like the following: while ($row=mysqli_fetch_array($run)){ $user_id = $row[0]; } $soldiername = $_POST['soldiername']; echo $soldiername . " "; echo $user_id . " "; One you have verified that those values are being filled in, you can remove the echo statements, but that is a good way to error check. If one of these values are not getting filled in, we can go from there. ~G7470 Yes it echos the Soldier name and owners ID. Quote Link to comment Share on other sites More sharing options...
G7470 Posted December 2, 2014 Share Posted December 2, 2014 (edited) Ok. In that case, it is the insert query itself. If data does in fact exist in the soldier table, verify that the auto_increment current value is set appropriately. So say your latest row in the table has a soldierid of 4. Then, your auto_increment value should be set to 5. In cPanel, that can be checked through the operations tab I believe in PhpMyAdmin once that table is selected. I say this because I have ran into this issue in the past, and the query itself seems to look fine to me. EDIT: Just to note, the auto_increment value only has to be greater than the largest value. It does not necessarily have to be the very next value, but that is more appropriate. I say this because the only real issue with auto_increment is making sure that the auto_increment value that the table is expecting cannot have already been used, as this would be a primary key violation. ~G7470 Edited December 2, 2014 by G7470 Quote Link to comment Share on other sites More sharing options...
peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 Ok. In that case, it is the insert query itself. If data does in fact exist in the soldier table, verify that the auto_increment current value is set appropriately. So say your latest row in the table has a soldierid of 4. Then, your auto_increment value should be set to 5. In cPanel, that can be checked through the operations tab I believe in PhpMyAdmin once that table is selected. I say this because I have ran into this issue in the past, and the query itself seems to look fine to me. ~G7470 Looking at the table structure i posted above it all looks ok. Quote Link to comment Share on other sites More sharing options...
peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 Done. Changed $query = "INSERT INTO soldier (`owner`, `soldiername`, `soldierrank`) VALUES('$user_id', '$soldiername', '1'))"; if(mysqli_query($con, $query)) { echo "Soldier Created"; } To $query = "insert into soldier (owner,soldiername,soldierrank) values ('$user_id','$soldiername','1')"; if(mysqli_query($con, $query)){ echo "Success, Your Soldier is Complete"; } Will post more problems up here if and as they come Quote Link to comment Share on other sites More sharing options...
G7470 Posted December 2, 2014 Share Posted December 2, 2014 FYI, from the posts above, the specific code that you just now referenced was not there as written. Please make note to update your code appropriately so that we can provide more accurate assistance. :) ~G7470 Quote Link to comment Share on other sites More sharing options...
peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 FYI, from the posts above, the specific code that you just now referenced was not there as written. Please make note to update your code appropriately so that we can provide more accurate assistance. :) ~G7470 wasnt it, i though it was as Nonstopcoding pointed about how i had so many ,'','','' that was not needed lol. I've PM'ed you anyway. Quote Link to comment Share on other sites More sharing options...
G7470 Posted December 2, 2014 Share Posted December 2, 2014 It's slightly different haha. Looks like there was an added ) onto it from his post. Might have been just a typo of some sort. Those happen to me all the time. I got your PM, no worries. I responded. ~G7470 Quote Link to comment Share on other sites More sharing options...
peterisgb Posted December 2, 2014 Author Share Posted December 2, 2014 It's slightly different haha. Looks like there was an added ) onto it from his post. Might have been just a typo of some sort. Those happen to me all the time. I got your PM, no worries. I responded. ~G7470 Thanks, it annoys me that tiny little things like and extra ' , ` or ) can bust everything lol grrrr. then i'm to bloody blind to see it staring me in the face lol, Quote Link to comment 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.