Zoofu Posted August 23, 2009 Share Posted August 23, 2009 <?php $id = $_GET['id']; $query = mysql_query("SELECT * FROM users WHERE id = '$id'"); $fetch_array = mysql_fetch_array($query); $username = $fetch_array['username']; $id = $fetch_array['id']; $tokens = $fetch_array['tokens']; $views = $fetch_array['views']; echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"80%\">\n"; echo "<tr><td class=\"forum_header\"><center><b>".$username."</b><br>UserID: ".$id."</center></td></tr>\n"; echo "<br>\n"; echo "</table>\n"; echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"30%\">\n"; echo "<tr><td class=\"forum_header\"><center><img src=\"http://gaiaonline.forumn.net/users/a5/22/21/00/album/base12.png\"></center><br><center>Tokens: ".$tokens."</center></td></tr>\n"; echo "</table>\n"; echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"50%\">\n"; echo "<tr><td class=\"forum_header\"><center><b>Statistics</center></b><br><br>Profile Views: ".$views."</td>\n"; echo "</tr></table>\n"; ?> I need it so when someone views your profile (./index?act=profile&id=#) it adds a view. Quote Link to comment Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 You can't get it to work? That's because columns in tables don't automatically update themselves. Looks like you're going to need another query call that issues an UPDATE statement to update the views column. Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 The problem is, I want it to add 1 and update everytime you view someone's profile. Quote Link to comment Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 Yes, I know what you want to happen. I was simply pointing out that it looks like you haven't even tried anything. It's my feelings (and most other people's here) that we're here to assist people in coming to an answer, not just crank out code for people. This should essentially answer your question: http://dev.mysql.com/doc/refman/5.0/en/update.html Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 Thanks for the link. Does anyone know why this doesn't work? <?php $id = mss($_GET['id']); $toks = mss($_GET['tokens']); if($id){ $sql = "SELECT * FROM `forum_subcats` WHERE `id`='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid Path!\n"; }else { $row1 = mysql_fetch_assoc($res); if($row1['admin'] == 1 && $admin_user_level == 0){ echo "You do not have permission!\n"; }else { if(!$_POST['submit']){ echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\">\n"; echo "<form method=\"post\" action=\"./index.php?act=create&id=".$id."\">\n"; echo "<tr><td>Post in:</td><td><select name=\"cat\"></center>\n"; $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row = mysql_fetch_assoc($res2)){ $sql3 = "SELECT * FROM `forum_subcats` WHERE `cid`='".$row['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">".$row['name']."</option>\n"; while($row2 = mysql_fetch_assoc($res3)){ $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"".$row2['id']."\"".$selected.">     ".$row2['name']."</option>\n"; } } echo "</select></td></tr>\n"; echo "<center><tr><td>Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n"; echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n"; echo "</form></table></center>\n"; }else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss($_POST['message']); if($cat && $title && $msg){ $sql = "SELECT admin FROM `forum_subcats` WHERE `id`='".$cat."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid path!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 && $admin_user_level != 1){ echo "You do not have permission!\n"; }else { if(strlen($title) < 3 || strlen > 32){ echo "Title must range from 3-32 characters!\n"; }else { if(strlen($msg) < 3 || strlen > 10000){ echo "Message must range from 3-10000 characters!\n"; }else { $date = date("m-D-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); $toks+1; // Here's what I want it to do. But it's not adding 1 onto your token field. topic_go($tid); } } } } }else { echo "Please fill in all fields!\n"; } } } } }else { if(!$_POST['submit']){ echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form method=\"post\" action=\"./index.php?act=create\">\n"; echo "<tr><td>Post in:</td><td><select name=\"cat\">\n"; $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row = mysql_fetch_assoc($res2)){ $sql3 = "SELECT * FROM `forum_subcats` WHERE `cid`='".$row['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">".$row['name']."</option>\n"; while($row2 = mysql_fetch_assoc($res3)){ $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"".$row2['id']."\"".$selected.">     ".$row2['name']."</option>\n"; } } echo "</select></td></tr>\n"; echo "<tr><td>Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n"; echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n"; echo "</form></table>\n"; }else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss($_POST['message']); if($cat && $title && $msg){ $sql = "SELECT admin FROM `forum_subcats` WHERE `id`='".$cat."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid path!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 && $admin_user_level != 1){ echo "You do not have permission!\n"; }else { if(strlen($title) < 3 || strlen > 32){ echo "Title must range from 3-32 characters!\n"; }else { if(strlen($msg) < 3 || strlen > 10000){ echo "Message must range from 3-10000 characters!\n"; }else { $date = date("m-D-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); header("Location: index.php?act=topic&id=".$tid.""); } } } } }else { echo "Please fill in all fields!\n"; } } } ?> Quote Link to comment Share on other sites More sharing options...
AngelicS Posted August 23, 2009 Share Posted August 23, 2009 Have you tried the link that corbin sent you? Because you have the answer there. Try using the update statement: Let's say I have selected the total views on my page, and then I want to echo it. I'd do it like this: $sel=mysql_query("SELECT * FROM `statistics` WHERE `id`=1") OR die(mysql_error()); $row=mysql_fetch_array($sel); echo $row['views']; Now everytime a user visits the page, I want to increase the $row['views'] with one. I'd need to add the following rows. $row['views']+=1; mysql_query("UPDATE `statistics` SET views='{$row['views']}' WHERE `id`=1") OR die(mysql_error()); The first row, $row['views']+=1; , increases the value of "views" by one. The second row, Updates the value of "views" inside the database, where the ID is one (of course you can change that). Now the final code looks like this: <?php include("config.php"); $sel=mysql_query("SELECT * FROM `statistics` WHERE `id`=1") OR die(mysql_error()); $row=mysql_fetch_array($sel); $row['views']+=1; mysql_query("UPDATE `statistics` SET views='{$row['views']}' WHERE `id`=1") OR die(mysql_error()); echo $row['views']; ?> Check this site for more information about the UPDATE statement: W3Schools http://www.w3schools.com/php/php_mysql_update.asp Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 Thanks! I've got it working, I read up on that. Quite useful. Anyone know what went wrong here? <?php $id = mss($_GET['id']); if($id){ $sql = "SELECT * FROM `forum_subcats` WHERE `id`='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid Path!\n"; }else { $row1 = mysql_fetch_assoc($res); if($row1['admin'] == 1 && $admin_user_level == 0){ echo "You do not have permission!\n"; }else { if(!$_POST['submit']){ echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\">\n"; echo "<form method=\"post\" action=\"./index.php?act=create&id=".$id."\">\n"; echo "<tr><td>Post in:</td><td><select name=\"cat\"></center>\n"; $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row = mysql_fetch_assoc($res2)){ $sql3 = "SELECT * FROM `forum_subcats` WHERE `cid`='".$row['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">".$row['name']."</option>\n"; while($row2 = mysql_fetch_assoc($res3)){ $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"".$row2['id']."\"".$selected.">     ".$row2['name']."</option>\n"; } } echo "</select></td></tr>\n"; echo "<center><tr><td>Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n"; echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n"; echo "</form></table></center>\n"; }else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss($_POST['message']); if($cat && $title && $msg){ $sql = "SELECT admin FROM `forum_subcats` WHERE `id`='".$cat."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid path!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 && $admin_user_level != 1){ echo "You do not have permission!\n"; }else { if(strlen($title) < 3 || strlen > 32){ echo "Title must range from 3-32 characters!\n"; }else { if(strlen($msg) < 3 || strlen > 10000){ echo "Message must range from 3-10000 characters!\n"; }else { $date = date("m-D-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); topic_go($tid); $sel=mysql_query("SELECT * FROM `users` WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); $rowt=mysql_fetch_array($sel); $rowt['tokens']+=6; mysql_query("UPDATE `users` SET tokens='{$rowt['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); // This lot here works! } } } } }else { echo "Please fill in all fields!\n"; } } } } }else { if(!$_POST['submit']){ echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form method=\"post\" action=\"./index.php?act=create\">\n"; echo "<tr><td>Post in:</td><td><select name=\"cat\">\n"; $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row = mysql_fetch_assoc($res2)){ $sql3 = "SELECT * FROM `forum_subcats` WHERE `cid`='".$row['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">".$row['name']."</option>\n"; while($row2 = mysql_fetch_assoc($res3)){ $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"".$row2['id']."\"".$selected.">     ".$row2['name']."</option>\n"; } } echo "</select></td></tr>\n"; echo "<tr><td>Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n"; echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n"; echo "</form></table>\n"; }else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss($_POST['message']); if($cat && $title && $msg){ $sql = "SELECT admin FROM `forum_subcats` WHERE `id`='".$cat."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid path!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 && $admin_user_level != 1){ echo "You do not have permission!\n"; }else { if(strlen($title) < 3 || strlen > 32){ echo "Title must range from 3-32 characters!\n"; }else { if(strlen($msg) < 3 || strlen > 10000){ echo "Message must range from 3-10000 characters!\n"; }else { $date = date("m-D-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); header("Location: index.php?act=topic&id=".$tid.""); $sel2=mysql_query("SELECT * FROM `users` WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); $rowt2=mysql_fetch_array($sel2); $rowt2['tokens']+=6; mysql_query("UPDATE `users` SET tokens='{$rowt2['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error());<?php $id = mss($_GET['id']); if($id){ $sql = "SELECT * FROM `forum_subcats` WHERE `id`='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid Path!\n"; }else { $row1 = mysql_fetch_assoc($res); if($row1['admin'] == 1 && $admin_user_level == 0){ echo "You do not have permission!\n"; }else { if(!$_POST['submit']){ echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\">\n"; echo "<form method=\"post\" action=\"./index.php?act=create&id=".$id."\">\n"; echo "<tr><td>Post in:</td><td><select name=\"cat\"></center>\n"; $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row = mysql_fetch_assoc($res2)){ $sql3 = "SELECT * FROM `forum_subcats` WHERE `cid`='".$row['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">".$row['name']."</option>\n"; while($row2 = mysql_fetch_assoc($res3)){ $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"".$row2['id']."\"".$selected.">     ".$row2['name']."</option>\n"; } } echo "</select></td></tr>\n"; echo "<center><tr><td>Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n"; echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n"; echo "</form></table></center>\n"; }else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss($_POST['message']); if($cat && $title && $msg){ $sql = "SELECT admin FROM `forum_subcats` WHERE `id`='".$cat."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid path!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 && $admin_user_level != 1){ echo "You do not have permission!\n"; }else { if(strlen($title) < 3 || strlen > 32){ echo "Title must range from 3-32 characters!\n"; }else { if(strlen($msg) < 3 || strlen > 10000){ echo "Message must range from 3-10000 characters!\n"; }else { $date = date("m-D-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); topic_go($tid); $sel=mysql_query("SELECT * FROM `users` WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); $rowt=mysql_fetch_array($sel); $rowt['tokens']+=6; mysql_query("UPDATE `users` SET tokens='{$rowt['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); } } } } }else { echo "Please fill in all fields!\n"; } } } } }else { if(!$_POST['submit']){ echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form method=\"post\" action=\"./index.php?act=create\">\n"; echo "<tr><td>Post in:</td><td><select name=\"cat\">\n"; $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row = mysql_fetch_assoc($res2)){ $sql3 = "SELECT * FROM `forum_subcats` WHERE `cid`='".$row['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">".$row['name']."</option>\n"; while($row2 = mysql_fetch_assoc($res3)){ $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"".$row2['id']."\"".$selected.">     ".$row2['name']."</option>\n"; } } echo "</select></td></tr>\n"; echo "<tr><td>Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n"; echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n"; echo "</form></table>\n"; }else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss($_POST['message']); if($cat && $title && $msg){ $sql = "SELECT admin FROM `forum_subcats` WHERE `id`='".$cat."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid path!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 && $admin_user_level != 1){ echo "You do not have permission!\n"; }else { if(strlen($title) < 3 || strlen > 32){ echo "Title must range from 3-32 characters!\n"; }else { if(strlen($msg) < 3 || strlen > 10000){ echo "Message must range from 3-10000 characters!\n"; }else { $date = date("m-D-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); header("Location: index.php?act=topic&id=".$tid.""); $sel2=mysql_query("SELECT * FROM `users` WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); $rowt2=mysql_fetch_array($sel2); $rowt2['tokens']+=6; mysql_query("UPDATE `users` SET tokens='{$rowt2['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); // This is the lot that's not working. It won't add 6 tokens. The other one does. } } } } }else { echo "Please fill in all fields!\n"; } } } ?> } } } } }else { echo "Please fill in all fields!\n"; } } } ?> Quote Link to comment Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 No, you obviously did not read up on it. Do we know what went wrong there? Yeah, I know what went wrong. You ignored advice twice. AngelicS even told you how to do it. (Although, really UPDATE table SET views = views+1 WHERE id = 1 would be better since the views can change in the time it's stored in the $row array.) Will you stop lying and telling us you've tried when you obviously haven't? We offer our time here to help people achieve their coding goals. HELP them. Not do it for them; there's a freelancing forum for that. Will you take 3 minutes of your time to actually think about what we've said? If you've actually tried then I apologize. Surely you understand though that it looks like you've tried nothing since I don't see a single line of code in your most recent post that has anything to do with changing view count. Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 No, I have read up on http://www.w3schools.com/php/php_mysql_update.asp, but it doesn't really help with what went wrong, I've gotten 2 things working since reading it, but the 3rd one, i've been trying to get working but it just... Isn't adding the 6 tokens. I'll try reading all of the 1st link you gave me. Thanks. Quote Link to comment Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 In that case, I apologize. I didn't realize you had added the token code. I assumed you were just trying to increment page views. So.... What exactly is the problem in the code posted above? Hrmm, perhaps it's this: mysql_query("UPDATE `users` SET tokens='{$rowt2['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error());<?php That <?php tag appears to be misplaced. Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 In that case, I apologize. I didn't realize you had added the token code. I assumed you were just trying to increment page views. So.... What exactly is the problem in the code posted above? Hrmm, perhaps it's this: mysql_query("UPDATE `users` SET tokens='{$rowt2['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error());<?php That <?php tag appears to be misplaced. What? There is no <?php tag at the end of it... Erm... I've got it marked, if you scroll over... I've got the part that works marked, and the part that doesn't work... For some reason, the 1st one works, and the 2nd doesn't. Quote Link to comment Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 There are multiple syntax errors, the first of which is on line 134. mysql_query("UPDATE `users` SET tokens='{$rowt2['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error());<?php The code is already inside of a <?php, so that <?php causes an error. Also, towards the end there are two ?> tags. Or is that code up there supposed to be broken up or something? Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 Oh crud, I accidently posted the script wrong. Stupid keyboard. <?php $id = mss($_GET['id']); if($id){ $sql = "SELECT * FROM `forum_subcats` WHERE `id`='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid Path!\n"; }else { $row1 = mysql_fetch_assoc($res); if($row1['admin'] == 1 && $admin_user_level == 0){ echo "You do not have permission!\n"; }else { if(!$_POST['submit']){ echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\">\n"; echo "<form method=\"post\" action=\"./index.php?act=create&id=".$id."\">\n"; echo "<tr><td>Post in:</td><td><select name=\"cat\"></center>\n"; $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row = mysql_fetch_assoc($res2)){ $sql3 = "SELECT * FROM `forum_subcats` WHERE `cid`='".$row['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">".$row['name']."</option>\n"; while($row2 = mysql_fetch_assoc($res3)){ $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"".$row2['id']."\"".$selected.">     ".$row2['name']."</option>\n"; } } echo "</select></td></tr>\n"; echo "<center><tr><td>Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n"; echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n"; echo "</form></table></center>\n"; }else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss($_POST['message']); if($cat && $title && $msg){ $sql = "SELECT admin FROM `forum_subcats` WHERE `id`='".$cat."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid path!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 && $admin_user_level != 1){ echo "You do not have permission!\n"; }else { if(strlen($title) < 3 || strlen > 32){ echo "Title must range from 3-32 characters!\n"; }else { if(strlen($msg) < 3 || strlen > 10000){ echo "Message must range from 3-10000 characters!\n"; }else { $date = date("m-D-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); topic_go($tid); $sel=mysql_query("SELECT * FROM `users` WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); $rowt=mysql_fetch_array($sel); $rowt['tokens']+=6; mysql_query("UPDATE `users` SET tokens='{$rowt['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); } } } } }else { echo "Please fill in all fields!\n"; } } } } }else { if(!$_POST['submit']){ echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form method=\"post\" action=\"./index.php?act=create\">\n"; echo "<tr><td>Post in:</td><td><select name=\"cat\">\n"; $sql2 = "SELECT * FROM `forum_cats` WHERE `admin` < ".$admin_user_level."+1"; $res2 = mysql_query($sql2) or die(mysql_error()); while($row = mysql_fetch_assoc($res2)){ $sql3 = "SELECT * FROM `forum_subcats` WHERE `cid`='".$row['id']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<option value=\"0\">".$row['name']."</option>\n"; while($row2 = mysql_fetch_assoc($res3)){ $selected = ($row2['id'] == $id) ? " SELECTED" : ""; echo "<option value=\"".$row2['id']."\"".$selected.">     ".$row2['name']."</option>\n"; } } echo "</select></td></tr>\n"; echo "<tr><td>Title</td><td><input type=\"text\" name=\"title\"></td></tr>\n"; echo "<tr><td>Message</td><td><textarea name=\"message\" style=\"width:300px;height:100px;\"></textarea></td></tr>\n"; echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Create Topic\"></td></tr>\n"; echo "</form></table>\n"; }else { $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss($_POST['message']); if($cat && $title && $msg){ $sql = "SELECT admin FROM `forum_subcats` WHERE `id`='".$cat."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ echo "Invalid path!\n"; }else { $row = mysql_fetch_assoc($res); if($row['admin'] == 1 && $admin_user_level != 1){ echo "You do not have permission!\n"; }else { if(strlen($title) < 3 || strlen > 32){ echo "Title must range from 3-32 characters!\n"; }else { if(strlen($msg) < 3 || strlen > 10000){ echo "Message must range from 3-10000 characters!\n"; }else { $date = date("m-D-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO `forum_topics` (`cid`,`title`,`uid`,`date`,`time`,`message`) VALUES('".$cat."','".$title."','".$_SESSION['uid']."','".$date."','".$time."','".$msg."')"; $res2 = mysql_query($sql2) or die(mysql_error()); $tid = mysql_insert_id(); header("Location: index.php?act=topic&id=".$tid.""); $sel2=mysql_query("SELECT * FROM `users` WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); $rowt2=mysql_fetch_array($sel2); $rowt2['tokens']+=6; mysql_query("UPDATE `users` SET tokens='{$rowt2['tokens']}' WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); } } } } }else { echo "Please fill in all fields!\n"; } } } ?> Quote Link to comment Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 So do the fields just not update? Or do they reset to 0? Or what happens? Have you tried echoing out the queries to make sure the variables are being put into them correctly? Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 It just doesn't update whatsoever. it should work, since it's the same script from above just editted. Quote Link to comment Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 Are you sure it's executing the UPDATE statement? Perhaps the if() conditions are not going as you would expect and the mysql_query call is never executed. Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 Well, that shouldn't be the problem if it worked previously in the same script... Setup the same way. Quote Link to comment Share on other sites More sharing options...
Zoofu Posted August 23, 2009 Author Share Posted August 23, 2009 It's.... A mystery. I really need this to work, at the moment.. They can only get tokens from making topics, I need it for the posts too 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.