hdshngout Posted August 6, 2006 Share Posted August 6, 2006 Ok, im working on a new site and I'm working on another feature. What its meant to do is from a set of radio buttons, you choose somthing and it subtracts X amount from your points depending on the choice. Sounds easy, right? Well of course when I mess with it, it won't work. Anyone see and problems that would cause it not to subtract?[code]<?php if (isset($_POST['submit'])) {function cleanUp($input){ return htmlspecialchars(strip_tags(stripslashes(trim($input))));}$shop_title = cleanUp($_POST['shop_name']);$shop_front = $_POST['shop_front'];$shop_front = str_replace("<", "[", $shop_front);$shop_front = str_replace(">", "]", $shop_front);$shop_desc = cleanUp($_POST['shop_desc']);$shop_desc = nl2br($shop_desc);$shop_size = cleanUp($_POST['shop_size']);$shop_location = cleanUP($_POST['shop_location']);$timestamp = strtotime("now");$username = $logged['username'];if ( (empty($shop_title)) || (empty($shop_desc)) || (empty($shop_size)) ||(empty($shop_location))) {include($_SERVER['DOCUMENT_ROOT']."/connect.php");$sql2 = "SELECT * FROM shops WHERE owner = '$logged[username]'";$result2 = mysql_query($sql2) or print ("Can't select table.<p>" .mysql_query());$number = mysql_num_rows($result2);if ($number != 1) {include("../connect.php");$sql = "INSERT INTO shops (timestamp, owner, shop_name, shop_desc,shop_front, shop_size, Shop_location) VALUES('$timestamp','$username','$shop_title','$shop_desc','$shop_front','$shop_size','$shop_location')";$result = mysql_query( $sql ) or print ( mysql_error());$id = mysql_insert_id();$shop_size2 = $_POST['shop_size'];if ($shop_size2 == "4") {$price = "50";} else if ($shop_size2 == "8") {$price = "100";} else if ($shop_size2 == "12") {$price = "200";} else if ($shop_size2 == "16") {$price = "300";} else if ($shop_size2 == "20") {$price = "400";} else if ($shop_size2 == "60") {$price = "600";}include($_SERVER['DOCUMENT_ROOT']."/connect.php");$sql4 = "SELECT * FROM users WHERE username = '$logged[username]'";$result4 = mysql_query($sql4) or print ("Can't select table.<p>" . mysql_query());while($row4 = mysql_fetch_array($result4)) {$points = $row4['points'];}$equation = ($points - $price);include("../connect.php");$sql5 = "UPDATE users SET points='$equation' WHEREusername='$logged[username]' LIMIT 1";$result5 = mysql_query($sql5) or print (mysql_error());if ($result5 != false) {echo "<span style=\"color: green;\">Success! Your shop has beensuccessfully created!It is located at <p><ahref=\"shop.php?id=$id\">$address/shop.php?id=$id</a></span>";}} else {echo "<span style=\"color: red;\">You Have already created ashop!</span>";}} else {echo "<span style=\"color: red;\">You must fill in all the requiredfields.</span>";}}?>[/code](by the way, I'm sorry if I accidentally broke any of the rules, still new here and learning my way around) Quote Link to comment https://forums.phpfreaks.com/topic/16736-subtracting-with-php/ Share on other sites More sharing options...
ignace Posted August 6, 2006 Share Posted August 6, 2006 i like your sense of humor ;D however what do you want to be substracted?[code]<?php if (isset($_POST['submit'])) {function cleanUp($input){ return htmlspecialchars(strip_tags(stripslashes(trim($input))));// well no-one ever gets passed this :D}$shop_title = cleanUp($_POST['shop_name']);$shop_front = $_POST['shop_front'];$shop_front = str_replace("<", "[", $shop_front);$shop_front = str_replace(">", "]", $shop_front);$shop_desc = cleanUp($_POST['shop_desc']);$shop_desc = nl2br($shop_desc);$shop_size = cleanUp($_POST['shop_size']);$shop_location = cleanUP($_POST['shop_location']);$timestamp = strtotime("now");$username = $logged['username'];if ( (empty($shop_title)) || (empty($shop_desc)) || (empty($shop_size)) ||(empty($shop_location))) {include($_SERVER['DOCUMENT_ROOT']."/connect.php");$sql2 = "SELECT * FROM shops WHERE owner = '" . $logged[username] . "'";$result2 = mysql_query($sql2) or print ("Can't select table.<p>" . mysql_query() . "</p>");$number = mysql_num_rows($result2);if ($number != 1) {include($_SERVER['DOCUMENT_ROOT'] . "/connect.php");$sql = "INSERT INTO shops (timestamp, owner, shop_name, shop_desc, shop_front, shop_size, Shop_location) VALUES ('$timestamp','$username','$shop_title','$shop_desc','$shop_front','$shop_size','$shop_location')";$result = mysql_query( $sql ) or die ( mysql_error());//exit, can also be used$id = mysql_insert_id();$shop_size2 = $_POST['shop_size'];if ($shop_size2 == "4") {$price = "50";} else if ($shop_size2 == "8") {$price = "100";} else if ($shop_size2 == "12") {$price = "200";} else if ($shop_size2 == "16") {$price = "300";} else if ($shop_size2 == "20") {$price = "400";} else if ($shop_size2 == "60") {$price = "600";}include($_SERVER['DOCUMENT_ROOT']."/connect.php");$sql4 = "SELECT * FROM users WHERE username = '" . $logged[username] . "'";$result4 = mysql_query($sql4) or die ("Can't select table.<p>" . mysql_query() . "</p>");// use exit or die, print won't stop the script..while($row4 = mysql_fetch_array($result4)) {$points = $row4['points'];}$equation = ($points - $price);include($_SERVER['DOCUMENT_ROOT'] . "/connect.php");$sql5 = "UPDATE users SET points='$equation' WHERE username='" . $logged[username] . "' LIMIT 1";// you could also just use $sql again, therefore they are called variables :P$result5 = mysql_query($sql5) or die (mysql_error());// same here, use $result instead of always incrementingif ($result5 != false) {echo "<span style=\"color: green;\">Success! Your shop has beensuccessfully created!It is located at <p><ahref=\"shop.php?id=$id\">$address/shop.php?id=$id</a></span>";}} else {echo "<span style=\"color: red;\">You Have already created ashop!</span>";}} else {echo "<span style=\"color: red;\">You must fill in all the requiredfields.</span>";}}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16736-subtracting-with-php/#findComment-70363 Share on other sites More sharing options...
hdshngout Posted August 6, 2006 Author Share Posted August 6, 2006 basically, what the script does is take the total number of points you have (earned from posting and other things around the site), and subtract the price of creating a user shop (cheesy I know). This feature specifically is meant to subtact X amount from your total points depending on the size shop you wish to create. The problem is, the subtraction isn't initiating and I can't figure out why! :P Quote Link to comment https://forums.phpfreaks.com/topic/16736-subtracting-with-php/#findComment-70369 Share on other sites More sharing options...
Chevy Posted August 6, 2006 Share Posted August 6, 2006 [code]<?php if (isset($_POST['submit'])) {function cleanUp($input){ return htmlspecialchars(strip_tags(stripslashes(trim($input))));// well no-one ever gets passed this :D}$shop_title = cleanUp($_POST['shop_name']);$shop_front = $_POST['shop_front'];$shop_front = str_replace("<", "[", $shop_front);$shop_front = str_replace(">", "]", $shop_front);$shop_desc = cleanUp($_POST['shop_desc']);$shop_desc = nl2br($shop_desc);$shop_size = cleanUp($_POST['shop_size']);$shop_location = cleanUP($_POST['shop_location']);$timestamp = strtotime("now");$username = $logged['username'];if ( (empty($shop_title)) || (empty($shop_desc)) || (empty($shop_size)) ||(empty($shop_location))) {include($_SERVER['DOCUMENT_ROOT']."/connect.php");$sql2 = "SELECT * FROM shops WHERE owner = '" . $logged[username] . "'";$result2 = mysql_query($sql2) or print ("Can't select table.<p>" . mysql_query() . "</p>");$number = mysql_num_rows($result2);if ($number != 1) {include($_SERVER['DOCUMENT_ROOT'] . "/connect.php");$sql = "INSERT INTO shops (timestamp, owner, shop_name, shop_desc, shop_front, shop_size, Shop_location) VALUES ('$timestamp','$username','$shop_title','$shop_desc','$shop_front','$shop_size','$shop_location')";$result = mysql_query( $sql ) or die ( mysql_error());//exit, can also be used$id = mysql_insert_id();$shop_size2 = $_POST['shop_size'];if ($shop_size2 == "4") {$price = "50";} else if ($shop_size2 == "8") {$price = "100";} else if ($shop_size2 == "12") {$price = "200";} else if ($shop_size2 == "16") {$price = "300";} else if ($shop_size2 == "20") {$price = "400";} else if ($shop_size2 == "60") {$price = "600";}include($_SERVER['DOCUMENT_ROOT']."/connect.php");$sql4 = "SELECT * FROM users WHERE username = '" . $logged[username] . "'";$result4 = mysql_query($sql4) or die ("Can't select table.<p>" . mysql_query() . "</p>");// use exit or die, print won't stop the script..while($row4 = mysql_fetch_array($result4)) {$points = $row4['points'];}$equation = $points - $price;include($_SERVER['DOCUMENT_ROOT'] . "/connect.php");$sql5 = "UPDATE users SET points='$equation' WHERE username='" . $logged[username] . "' LIMIT 1";// you could also just use $sql again, therefore they are called variables :P$result5 = mysql_query($sql5) or die (mysql_error());// same here, use $result instead of always incrementingif ($result5 != false) {echo "<span style=\"color: green;\">Success! Your shop has beensuccessfully created!It is located at <p><ahref=\"shop.php?id=$id\">$address/shop.php?id=$id</a></span>";}} else {echo "<span style=\"color: red;\">You Have already created ashop!</span>";}} else {echo "<span style=\"color: red;\">You must fill in all the requiredfields.</span>";}}?>[/code]You do not need ('s or )'s in a - Quote Link to comment https://forums.phpfreaks.com/topic/16736-subtracting-with-php/#findComment-70390 Share on other sites More sharing options...
king arthur Posted August 6, 2006 Share Posted August 6, 2006 Think it may be this bit here[code]$sql2 = "SELECT * FROM shops WHERE owner = '$logged[username]'";$result2 = mysql_query($sql2) or print ("Can't select table.<p>" .[/code]If the number of rows returned is zero, the rest of your code doesn't run. The number of rows returned may be zero because I think the query string is not interpolated in the way you want - instead try[code]$sql2 = "SELECT * FROM shops WHERE owner = '" . $logged[username] . "'";$result2 = mysql_query($sql2) or print ("Can't select table.<p>" .[/code]Never sure about these but that's what I'd try! Quote Link to comment https://forums.phpfreaks.com/topic/16736-subtracting-with-php/#findComment-70407 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.