NewcastleFan Posted November 8, 2011 Share Posted November 8, 2011 Hey guys, I've got a php form on a page called units.php, which submits to create.php (which has my if function in) I'm trying to get the page to display an error message on the original units.php page somewhere, preferably in a fixed div in the layout. At current I've included units.php in the create.php file and added the error above, however this floats the error message or complete message above my entire template, also breaks part of the site as it is on create.php in the address bar. Is there a way to re-direct it back to units.php and add a error or complete message? units.php: <?php session_start(); // start the session if(!isset($_SESSION['user'])){ // check if the user is logged in // the user is not logged in header("Location: login.php"); // take him/her to the login page } ?> <?php include ('mysql.php'); ?> <?php include ('includes/functions.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Units</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="container"> <div id="header"> <?php include("includes/header.php"); ?> </div> <div id="nav"> <?php include("includes/navlogged.php"); ?> <?php include("includes/resources.php"); ?> <?php include ("includes/pointer.php"); ?> </div> <div id="contentlogged"> <b>Your units:</b><br /><br /> <?php $result = mysql_query("SELECT * FROM userdb WHERE username='$_SESSION[user]'") or die(mysql_error()); echo "<table border='1' cellpadding='10'>"; echo "<th colspan='6'>Offence</th>"; echo "<tr> <th>Unit Name</th> <th>Number</th> <th>Wood Cost</th> <th>Iron Cost</th> <th>TP Cost</th> <th>Create</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr>"; echo '<td>Unit 1</td>'; echo '<td>' . $row['ounit1'] . '</td>'; echo '<td>'. $ounit1w . '</td>'; echo '<td>'. $ounit1i . '</td>'; echo '<td>'. $ounit1tp . '</td>'; echo '<td> <form action="create.php" method="post"> <input type="text" name="number" value="" size="5"> <input type="hidden" name="memberid" value="' . $row['memberid'] . '"> <input type="hidden" name="unit" value="ounit1"> <input type="hidden" name="res1cost" value="'. $ounit1w . '"> <input type="hidden" name="res2cost" value="'. $ounit1i . '"> <input type="hidden" name="tpcost" value="'. $ounit1tp . '"> <input type="submit" name="submit" value="Create"> </form> </td>'; echo "</tr>"; ?> create.php: <?php include ('mysql.php'); ?> <?php //unit costs $ounit1w = 1000; $ounit1i = 1000; $ounit1tp = 100; $ounit2w = 800; $ounit2i = 2500; $ounit2tp = 200; $ounit3w = 1200; $ounit3i = 1500; $ounit3tp = 300; $ounit4w = 2000; $ounit4i = 2000; $ounit4tp = 450; $ounit5w = 100; $ounit5i = 5000; $ounit5tp = 600; $ounit6w = 1900; $ounit6i = 2000; $ounit6tp = 700; $ounit7w = 5000; $ounit7i = 800; $ounit7tp = 800; $ounit8w = 2700; $ounit8i = 2800; $ounit8tp = 930; $ounit9w = 7000; $ounit9i = 1000; $ounit9tp = 1100; $ounit10w = 50; $ounit10i = 10000; $ounit10tp = 1500; $ounit11w = 750; $ounit11i = 15000; $ounit11tp = 1600; $ounit12w = 15000; $ounit12i = 15000; $ounit12tp = 2000; /////////////////////////////// $dunit1w = 1000; $dunit1i = 1000; $dunit1tp = 100; $dunit2w = 800; $dunit2i = 2500; $dunit2tp = 200; $dunit3w = 1200; $dunit3i = 1500; $dunit3tp = 300; $dunit4w = 2000; $dunit4i = 2000; $dunit4tp = 450; $dunit5w = 100; $dunit5i = 5000; $dunit5tp = 600; $dunit6w = 1900; $dunit6i = 2000; $dunit6tp = 700; $dunit7w = 5000; $dunit7i = 800; $dunit7tp = 800; $dunit8w = 2700; $dunit8i = 2800; $dunit8tp = 930; $dunit9w = 7000; $dunit9i = 1000; $dunit9tp = 1100; $dunit10w = 50; $dunit10i = 10000; $dunit10tp = 1500; $dunit11w = 750; $dunit11i = 15000; $dunit11tp = 1600; $dunit12w = 15000; $dunit12i = 15000; $dunit12tp = 2000; ?> <?php $memberid = mysql_real_escape_string($_POST['memberid']); $number = $_POST['number']; $unit = $_POST['unit']; $unitres1 = $_POST['res1cost']; $unitres2 = $_POST['res2cost']; $unittp = $_POST['tpcost']; $result = mysql_query("SELECT * FROM userdb WHERE memberid='$memberid'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $unitstart = $row[$unit]; $res1 = $row['res1']; $res2 = $row['res2']; $tp = $row['trainpoints']; } $unitnumber = $unitstart + $number; $resneeded1 = $number * $unitres1; $resneeded2 = $number * $unitres2; $tpneeded = $number * $unittp; $newres1 = $res1 - $resneeded1; $newres2 = $res2 - $resneeded2; $newtp = $tp - $tpneeded; if ($res1 > $resneeded1 || $res2 > $resneeded2 || $tp > $tpneeded) { $query=("UPDATE userdb SET $unit = '$unitnumber' WHERE memberid='$memberid'"); $query2= ("UPDATE userdb SET res1 = '$newres1' WHERE memberid='$memberid'"); $query3= ("UPDATE userdb SET res2 = '$newres2' WHERE memberid='$memberid'"); $query4= ("UPDATE userdb SET trainpoints = '$newtp' WHERE memberid='$memberid'"); mysql_query($query); mysql_query($query2); mysql_query($query3); mysql_query($query4); include "units.php"; echo "<div class='errorbuild'>You Built $number more $unit, You now have $unitnumber.</div>"; } else { include "units.php"; echo "<div class='errorbuild'>Not enough Resources. You need: $resneeded1 wood, and $resneeded2 iron, and $tpneeded tp's</div>"; exit; } ?> Thanks for any help or advice guys. Quote Link to comment https://forums.phpfreaks.com/topic/250724-php-if-x-this-else-that/ Share on other sites More sharing options...
NewcastleFan Posted November 8, 2011 Author Share Posted November 8, 2011 Ignore me... Put the if function in the same page and add a if submitted doh.. Quote Link to comment https://forums.phpfreaks.com/topic/250724-php-if-x-this-else-that/#findComment-1286355 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.