coalduststar Posted August 26, 2011 Share Posted August 26, 2011 I started using dreamweaver to do part of this and now i've made and epic hash up it's for a game of killer- to log a kill you select a player and his killer from the database which is one table with the unique email as a primary key when someone is killed the score has to be calculated and then the dead person's target (also email) has to be reassigned to the killer (hence the select query in the middle of the update) it's not making it through and i was wondering if someone could help me http://www.arts.ulster.ac.uk/IMAK/admin <?php require_once('../Connections/IMAK.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "kill") && ($email != $target)) { //explode killer $target = $_POST['players']; $weapon = $_POST['weapon']; $killer = $_POST['killer']; $piece = explode(" ", $killer); $piece[0] = $email; $piece[1] = $year; //score = year+weapon+tweet*evidence $youtube = "youtube"; $proof = strpos($_POST['evidence'], $youtube); if($proof === true){ $kill_score = ($year + $weapon + $tweet)*2; }else{ $kill_score = ($year + $weapon + $tweet); } mysql_select_db($database_IMAK, $IMAK); $query_players2 = "SELECT current_target FROM IMAK_player WHERE email = $target"; $players2 = mysql_query($query_players2, $IMAK) or die(mysql_error()); $row_players2 = mysql_fetch_assoc($players2); $totalRows_players2 = mysql_num_rows($players2); $updateSQL = sprintf("UPDATE IMAK_player SET killer=%s, evidence=%s, weapon=%s, tweet=%s, current_target=%s, kill_score=%s WHERE email=%s", GetSQLValueString($email, "text"), GetSQLValueString($_POST['evidence'], "text"), GetSQLValueString($weapon, "text"), GetSQLValueString(isset($_POST['tweet']) ? "true" : "", "defined","1","0"), GetSQLValueString($row_players2['current_target'], "text"), GetSQLValueString($kill_score, "text"), GetSQLValueString($target, "text")); mysql_select_db($database_IMAK, $IMAK); $Result1 = mysql_query($updateSQL, $IMAK) or die(mysql_error()); $updateGoTo = "yeo.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } //populate player list mysql_select_db($database_IMAK, $IMAK); $query_players = "SELECT * FROM IMAK_player WHERE active = 1"; $players = mysql_query($query_players, $IMAK) or die(mysql_error()); $row_players = mysql_fetch_assoc($players); $totalRows_players = mysql_num_rows($players); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/ Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 it's not making it through and i was wondering if someone could help me but what exactly is the error you're getting in your error logs? have you echo'ed the POST vars to see if they're all reaching the page correctly? Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262241 Share on other sites More sharing options...
coalduststar Posted August 26, 2011 Author Share Posted August 26, 2011 in the middle of troubleshooting it now- just wanted to make sure there weren't any glaring disasters. there's no error so my guess is it's dying when it's trying to get the current_target out Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262244 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 $email doesn't seem to be defined before this: if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "kill") && ($email != $target)) { Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262245 Share on other sites More sharing options...
kworld Posted August 26, 2011 Share Posted August 26, 2011 If I am right in what you are saying it sounds like your database isn't allowing you to save details into it using a custom primary key, your database may not be setup properly. Also you shouldn't realy use email addresses as a primary key, thats personal information. All those email addresses are viewable in your websites html source, use an autoincrement value in your databse for a PK. I think you have more than one problem going on here. Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262247 Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2011 Share Posted August 26, 2011 if($proof === true){ ^^^ $proof in the above is the result from a strpos statement and will never be exactly a true value and that conditional test will always fail. You would need to use !== false Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262250 Share on other sites More sharing options...
coalduststar Posted August 26, 2011 Author Share Posted August 26, 2011 yeah the email variable has to be made from another variable as all the info is in a drop down list of players email and what year they're in. the problem is that because it's a drop down list all the calculations have to happen after the submit button is clicked? at least i think so. as for the database- how might that be set up incorrectly? I have email as the primary key etc. i have a strpos but i'm gonna have to use a stristr so thanks for flagging that Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262252 Share on other sites More sharing options...
coalduststar Posted August 26, 2011 Author Share Posted August 26, 2011 //score = year+weapon+tweet*evidence $youtube = "youtube"; if (stristr($_POST['evidence'], $youtube) === TRUE){ $kill_score = ($year + $weapon + $tweet)*2; }else{ $kill_score = ($year + $weapon + $tweet); } is this more correct or should i still use ==? Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262255 Share on other sites More sharing options...
kworld Posted August 26, 2011 Share Posted August 26, 2011 Sorry i miss understood what you need help on, what exactly is the problem you have? Is the script producing errors? Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262260 Share on other sites More sharing options...
coalduststar Posted August 26, 2011 Author Share Posted August 26, 2011 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@email.ulster.ac.uk 3' at line 1 i wasn't getting anything- it was just dying and now i have this one above which isn't really pointing at anything Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262262 Share on other sites More sharing options...
coalduststar Posted August 26, 2011 Author Share Posted August 26, 2011 could that SQL error be a symptom of the database not accepting an email as a primary key? @kworld Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262290 Share on other sites More sharing options...
kworld Posted August 26, 2011 Share Posted August 26, 2011 Have you got the SQL query your error refers to as wrong? Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262304 Share on other sites More sharing options...
coalduststar Posted August 26, 2011 Author Share Posted August 26, 2011 Hi guys I figured out the error- it was because I hadn't used quotes so it wasn't pulling in the email- i rectified that. Got this now- and it's going to yeo.php but not updating the database at all- i've also attached the form under the code- stumped <?php require_once('../Connections/IMAK.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "kill")) { //explode killer $target = $_POST['players']; $weapon = $_POST['weapon']; $killer = $_POST['killer']; $piece = explode(" ", $killer); $piece[0] = $email; $piece[1] = $year; //score = year+weapon+tweet*evidence $youtube = "youtube"; if (stristr($_POST['evidence'], $youtube) == TRUE){ $kill_score = ($year + $weapon + $tweet)*2; }else{ $kill_score = ($year + $weapon + $tweet); } mysql_select_db($database_IMAK, $IMAK); $query_players2 = "SELECT current_target FROM IMAK_player WHERE email = '$target'"; $players2 = mysql_query($query_players2, $IMAK) or die(mysql_error()); $row_players2 = mysql_fetch_assoc($players2); $totalRows_players2 = mysql_num_rows($players2); $row_players2['current_target'] = $current_target; $updateSQL = sprintf("UPDATE IMAK_player SET killer=%s, evidence=%s, weapon=%s, tweet=%s, current_target=%s, kill_score=%s WHERE email=%s", GetSQLValueString($email, "text"), GetSQLValueString($_POST['evidence'], "text"), GetSQLValueString($weapon, "text"), GetSQLValueString(isset($_POST['tweet']) ? "true" : "", "defined","1","0"), GetSQLValueString($current_target, "text"), GetSQLValueString($kill_score, "text"), GetSQLValueString($target, "text")); mysql_select_db($database_IMAK, $IMAK); $Result1 = mysql_query($updateSQL, $IMAK) or die(mysql_error()); $updateGoTo = "yeo.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } //populate player list mysql_select_db($database_IMAK, $IMAK); $query_players = "SELECT * FROM IMAK_player WHERE active = 1"; $players = mysql_query($query_players, $IMAK) or die(mysql_error()); $row_players = mysql_fetch_assoc($players); $totalRows_players = mysql_num_rows($players); ?> here's the form <form action="<?php echo $editFormAction; ?>" method="POST" name="kill"> <li> <select name="players" title="select player"> <?php do { ?> <option value="<?php echo $row_players['email']?> <?php echo $row_players['year']; ?>"><?php echo $row_players['name']?> <?php echo $row_players['surname']?> (<?php echo $row_players['year']; ?>)</option> <?php } while ($row_players = mysql_fetch_assoc($players)); $rows = mysql_num_rows($players); if($rows > 0) { mysql_data_seek($players, 0); $row_players = mysql_fetch_assoc($players); } ?> </select> <img src="../images/murdah.png" alt="has assassinated" width="100" height="49" border="0" align="middle" /> <select name="killer" title="select killer"> <?php do { ?> <option value="<?php echo $row_players['email']?>"><?php echo $row_players['name']?> <?php echo $row_players['surname']?> (<?php echo $row_players['year']; ?>)</option> <?php } while ($row_players = mysql_fetch_assoc($players)); $rows = mysql_num_rows($players); if($rows > 0) { mysql_data_seek($players, 0); $row_players = mysql_fetch_assoc($players); } ?> </select></li> <li> <input name="evidence" type="text" size="30" /></li> <li> <img src="../images/weapons/gun.png" alt="gun" width="70" height="47" align="middle" /> <input name="weapon" type="radio" value="1" checked/> <img src="../images/weapons/dagger.png" alt="dagger" width="50" height="47" align="middle" /> <input name="weapon" type="radio" value="2" /> <img src="../images/weapons/poison.png" alt="poison" width="50" height="47" align="middle" /> <input name="weapon" type="radio" value="3" /> <img src="../images/weapons/garotte.png" alt="garotte" width="50" height="47" align="middle" /> <input name="weapon" type="radio" value="4" /> </li> <li> <img src="../images/twitter.png" alt="twitter" width="50" height="50" align="middle" /> <input name="tweet" type="checkbox" value="1" /> </li> <li><input name="submit" type="submit" value="KILL" /> </li> <input type="hidden" name="MM_update" value="kill" /> <input type="hidden" name="<?php echo $row_players['year']; ?>" value="kill" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1262305 Share on other sites More sharing options...
coalduststar Posted August 29, 2011 Author Share Posted August 29, 2011 bump * database isn't recording anything and it appears the variable aren't being passed in :/ Quote Link to comment https://forums.phpfreaks.com/topic/245755-biting-off-more-than-i-can-chew/#findComment-1263139 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.