cloudll Posted October 8, 2011 Share Posted October 8, 2011 Hey guys, I have made an admin page for a game Im working on to quickly allow me to update many aspects of the game. My form is sending the correct data because i can echo the $_post but for some reason it isnt updating my database. I just get a blank white page. Could anyone see what i have done wrong. Thanks <?php require($DOCUMENT_ROOT . "/game/includes/connection.php"); require($DOCUMENT_ROOT . "/game/includes/settings.php"); ?> <?php $name = $_POST['admin_name']; $img = $_POST['admin_img']; $current_hp = $_POST['admin_current_hp']; $max_hp = $_POST['admin_max_hp']; $current_energy = $_POST['admin_current_energy']; $max_energy = $_POST['admin_max_energy']; $level = $_POST['admin_level']; $exp_total = $_POST['admin_exp_total']; $exp = $_POST['admin_exp']; $exp_level = $_POST['admin_exp_level']; $pos_x = $_POST['admin_pos_x']; $pos_y = $_POST['admin_pos_y']; $potion = $_POST['admin_potion']; $ether = $_POST['admin_ether']; $elixir = $_POST['admin_elixir']; $zenni = $_POST['admin_zenni']; $sector = $_POST['admin_sector']; $battle = $_POST['admin_battle']; ?> <?php $sql_1 = "UPDATE game_character SET name='$name', img='$img', current_hp='$current_hp', max_hp='$max_hp', current energy='$current_energy', max_energy='$max_energy', level='$level', exp_total='$exp_total', exp='$exp', exp_level='$exp_level', pos_x='$pos_x', pos_y='$pos_y', potion='$potion', ether='$ether', elixir='$elixir', zenni='$zenni' WHERE id=1"; $sql_2 = "UPDATE game_status SET sector='$sector', battle='$battle' WHERE id=1"; $statement_1 = $dbh->prepare($sql_1); $statement_2 = $dbh->prepare($sql_2); $statement_1->execute(); $statement_2->execute(); ?> <SCRIPT LANGUAGE="JavaScript"> redirTime = "1"; redirURL = "<?php echo $r_admin ?>"; function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); } </script> <BODY onLoad="redirTimer()"> Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/ Share on other sites More sharing options...
cloudll Posted October 9, 2011 Author Share Posted October 9, 2011 Anyone? still cant figure this one out Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/#findComment-1277427 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 9, 2011 Share Posted October 9, 2011 In your Javascript.. <?php echo $r_admin ?> should be <?php echo $r_admin; ?> Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/#findComment-1277430 Share on other sites More sharing options...
cloudll Posted October 9, 2011 Author Share Posted October 9, 2011 this may make me sound very stupid, but does that make a difference, i have always used <?php echo $test ?> without the ; and never ran into a problem Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/#findComment-1277434 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 9, 2011 Share Posted October 9, 2011 I'm 99% sure its necessary in that case. Try it, see what happens. If still failure, check your servers error log to see what PHP says. Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/#findComment-1277437 Share on other sites More sharing options...
awjudd Posted October 9, 2011 Share Posted October 9, 2011 Yes it is very different. Are you sure you weren't using the shorttags echo? <?= $test ?>. The ; means end of the current statement and is a core element for many languages. ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/#findComment-1277440 Share on other sites More sharing options...
cloudll Posted October 9, 2011 Author Share Posted October 9, 2011 Nope, i havnt used any short tags, my entire site hasnt used ; after an echo. Lol, oops. Its gonna be fun finding them all to change them :'( Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/#findComment-1277442 Share on other sites More sharing options...
cloudll Posted October 9, 2011 Author Share Posted October 9, 2011 Got it working using an arrray <?php require($DOCUMENT_ROOT . "/game/includes/connection.php"); require($DOCUMENT_ROOT . "/game/includes/settings.php"); ?> <?php $name = htmlentities($_POST['admin_name']); $img = $_POST['admin_img']; $current_hp = $_POST['admin_current_hp']; $max_hp = $_POST['admin_max_hp']; $current_energy = $_POST['admin_current_energy']; $max_energy = $_POST['admin_max_energy']; $level = $_POST['admin_level']; $exp_total = $_POST['admin_exp_total']; $exp = $_POST['admin_exp']; $exp_level = $_POST['admin_exp_level']; $pos_x = $_POST['admin_pos_x']; $pos_y = $_POST['admin_pos_y']; $potion = $_POST['admin_potion']; $ether = $_POST['admin_ether']; $elixir = $_POST['admin_elixir']; $zenni = $_POST['admin_zenni']; $sector = $_POST['admin_sector']; $battle = $_POST['admin_battle']; $id = "1"; $sql_1 = "UPDATE game_character SET name=?, img=?, current_hp=?, max_hp=?, current_energy=?, max_energy=?, level=?, exp_total=?, exp=?, exp_level=?, pos_x=?, pos_y=?, potion=?, ether=?, elixir=?, zenni=? WHERE id=?"; $sql_2 = "UPDATE game_status SET sector=?, battle=? WHERE id=?"; $statement_1 = $dbh->prepare($sql_1); $statement_2 = $dbh->prepare($sql_2); $statement_1->execute(array($name,$img,$current_hp,$max_hp,$current_energy,$max_energy,$level,$exp_total,$exp,$exp_level,$pos_x,$pos_y,$potion,$ether,$elixir, $zenni,$id)); $statement_2->execute(array($sector,$battle,$id)); ?> <?php echo $name; ?><br /> <?php echo $img; ?><br /> <?php echo $current_hp; ?><br /> <?php echo $max_hp; ?><br /> <?php echo $current_energy; ?><br /> <?php echo $max_energy; ?><br /> <?php echo $level; ?><br /> <?php echo $exp_total; ?><br /> <?php echo $exp; ?><br /> <?php echo $exp_level; ?><br /> <?php echo $pos_x; ?><br /> <?php echo $pos_y; ?><br /> <?php echo $potion; ?><br /> <?php echo $ether; ?><br /> <?php echo $elixir; ?><br /> <?php echo $zenni; ?><br /> <?php echo $battle; ?><br /> <?php echo $sector; ?><br /> Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/#findComment-1277463 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 9, 2011 Share Posted October 9, 2011 Your welcome. Quote Link to comment https://forums.phpfreaks.com/topic/248702-trouble-updating-database-from-form/#findComment-1277464 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.