MySQL_Narb Posted October 24, 2009 Share Posted October 24, 2009 PHP Code: <?php require "global_settings.php"; ?> <title><?php echo $sitetitle; ?></title> <center><style type="text/css"> a:link { color:#24374C; text-decoration:bold; } a:visited { color:#24374C; text-decoration:bold; } a:active { outline: none; color:#24374C; text-decoration:bold; } body {background-color:#b0c4de} div.box { width:250px; padding:10px; border:3px double #000000; margin:10px; background-color:#74AFF2; } p { border-top-style:dotted; border-right-style:solid; border-bottom-style:dotted; border-left-style:solid; } div.menu-blue { BORDER-RIGHT: #333366 1px solid; BORDER-LEFT: #6699cc 1px solid; BORDER-TOP: #6699cc 1px solid; BORDER-BOTTOM: #333366 1px solid; FONT-WEIGHT: normal; FONT-SIZE: 2px; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #23559C; TEXT-DECORATION: none; font-stretch : condensed; } .menu-top { BORDER-RIGHT: 1px solid #333366; BORDER-TOP: 1px solid #6699CC; FONT-WEIGHT: normal; FONT-SIZE: 2px; BORDER-LEFT: 1px solid #6699CC; COLOR: #FFFFFF; BORDER-BOTTOM: 1px solid #333366; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #23559C; TEXT-DECORATION: none; font-stretch : condensed } </style> <center> <div class='menu-blue'> <div align="center"> <table width="600" cellspacing="1" cellpadding="5" style="background-color:#23559C"> <tr> <td style="background-color:#FFFFFF"> <div align="center"> <table border="0"> </form> </table> <?php $con = mysql_connect("$dbhost", "$dbuser", "$dbpassword") or die(mysql_errno()); if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $_POST = array_map('stripslashes', $_POST); } $name = $_POST['name']; $message = $_POST['message']; //getting the data if the user is banned or not $get = mysql_query("SELECT * FROM users"); while ($row = mysql_fetch_assoc($get)) { // get data $ban_check = $row['banned']; if ($ban_check ==1) { echo "Your account has been disabled. You are no longer allowed to post."; } else { if (!$name) { echo "<div class='box'><b><span style='color:red'>You must be logged in to post!</span></b></div>"; } else { //connect $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); //write $write = mysql_query("INSERT INTO posts VALUES ('','$name','$message')") or die(mysql_error()); $postcount = mysql_query("UPDATE users SET post_count = post_count + 1 WHERE username='$name'"); echo "<div class='box'><font face='arial'><b><span style='color:green'>Posted! Your name was:</span> $name</b> - Your message was....<br><br><b>$message - <a href='bbdemo.php'>View it!</a></b>"; } } } ?> Error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a5488351/public_html/post.php on line 86 Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/ Share on other sites More sharing options...
MySQL_Narb Posted October 24, 2009 Author Share Posted October 24, 2009 Hello? Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943294 Share on other sites More sharing options...
mikesta707 Posted October 24, 2009 Share Posted October 24, 2009 this is where the error is popping up right? $get = mysql_query("SELECT * FROM users"); while ($row = mysql_fetch_assoc($get)) that means that the query is failing. Put or die(mysql_error()) after that, and see what error you get Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943296 Share on other sites More sharing options...
MySQL_Narb Posted October 24, 2009 Author Share Posted October 24, 2009 After adding that to my code, I receive this: Parse error: syntax error, unexpected T_LOGICAL_OR in /home/a5488351/public_html/post.php on line 86 Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943320 Share on other sites More sharing options...
mikesta707 Posted October 24, 2009 Share Posted October 24, 2009 then you didnt do it right. post it. in the future, if you add some code and your code isn't fixed, just don't say its not working. post the updated code Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943322 Share on other sites More sharing options...
MySQL_Narb Posted October 24, 2009 Author Share Posted October 24, 2009 then you didnt do it right. post it. in the future, if you add some code and your code isn't fixed, just don't say its not working. post the updated code Well if you you were smart you'd just look at the code again just seeing a little code added at the end. But if you need it that damn bad, here: <?php require "global_settings.php"; ?> <title><?php echo $sitetitle; ?></title> <center><style type="text/css"> a:link { color:#24374C; text-decoration:bold; } a:visited { color:#24374C; text-decoration:bold; } a:active { outline: none; color:#24374C; text-decoration:bold; } body {background-color:#b0c4de} div.box { width:250px; padding:10px; border:3px double #000000; margin:10px; background-color:#74AFF2; } p { border-top-style:dotted; border-right-style:solid; border-bottom-style:dotted; border-left-style:solid; } div.menu-blue { BORDER-RIGHT: #333366 1px solid; BORDER-LEFT: #6699cc 1px solid; BORDER-TOP: #6699cc 1px solid; BORDER-BOTTOM: #333366 1px solid; FONT-WEIGHT: normal; FONT-SIZE: 2px; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #23559C; TEXT-DECORATION: none; font-stretch : condensed; } .menu-top { BORDER-RIGHT: 1px solid #333366; BORDER-TOP: 1px solid #6699CC; FONT-WEIGHT: normal; FONT-SIZE: 2px; BORDER-LEFT: 1px solid #6699CC; COLOR: #FFFFFF; BORDER-BOTTOM: 1px solid #333366; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #23559C; TEXT-DECORATION: none; font-stretch : condensed } </style> <center> <div class='menu-blue'> <div align="center"> <table width="600" cellspacing="1" cellpadding="5" style="background-color:#23559C"> <tr> <td style="background-color:#FFFFFF"> <div align="center"> <table border="0"> </form> </table> <?php $con = mysql_connect("$dbhost", "$dbuser", "$dbpassword") or die(mysql_errno()); if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $_POST = array_map('stripslashes', $_POST); } $name = $_POST['name']; $message = $_POST['message']; //getting the data if the user is banned or not $get = mysql_query("SELECT * FROM users"); while ($row = mysql_fetch_assoc($get)) or die(mysql_error()) { // get data $ban_check = $row['banned']; if ($ban_check ==1) { echo "Your account has been disabled. You are no longer allowed to post."; } else { if (!$name) { echo "<div class='box'><b><span style='color:red'>You must be logged in to post!</span></b></div>"; } else { //connect $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); //write $write = mysql_query("INSERT INTO posts VALUES ('','$name','$message')") or die(mysql_error()); $postcount = mysql_query("UPDATE users SET post_count = post_count + 1 WHERE username='$name'"); echo "<div class='box'><font face='arial'><b><span style='color:green'>Posted! Your name was:</span> $name</b> - Your message was....<br><br><b>$message - <a href='bbdemo.php'>View it!</a></b>"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943326 Share on other sites More sharing options...
mikesta707 Posted October 24, 2009 Share Posted October 24, 2009 Well if you you were smart you'd just look at the code again just seeing a little code added at the end. But if you need it that damn bad, here: if you did what i said to do correctly, then it wouldn't have thrown an error. There are an infinite amount of ways for you to do it wrong, so how am I going no which way you did it wrong. Being smart has nothing to do with knowing how you failed to follow my advice or die can't go in if/while/etc statements. you should put it after the mysql query $get = mysql_query("SELECT * FROM users") or die(mysql_query()); Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943338 Share on other sites More sharing options...
Alex Posted October 24, 2009 Share Posted October 24, 2009 It's not very nice to insult people who are taking time out of their day to help you. Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943340 Share on other sites More sharing options...
marcus Posted October 24, 2009 Share Posted October 24, 2009 The query is fine, at the point you're trying to execute that query though there is no establishment to an actual database. Try this: <?php require "global_settings.php"; ?> <title><?php echo $sitetitle; ?></title> <center><style type="text/css"> a:link { color:#24374C; text-decoration:bold; } a:visited { color:#24374C; text-decoration:bold; } a:active { outline: none; color:#24374C; text-decoration:bold; } body {background-color:#b0c4de} div.box { width:250px; padding:10px; border:3px double #000000; margin:10px; background-color:#74AFF2; } p { border-top-style:dotted; border-right-style:solid; border-bottom-style:dotted; border-left-style:solid; } div.menu-blue { BORDER-RIGHT: #333366 1px solid; BORDER-LEFT: #6699cc 1px solid; BORDER-TOP: #6699cc 1px solid; BORDER-BOTTOM: #333366 1px solid; FONT-WEIGHT: normal; FONT-SIZE: 2px; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #23559C; TEXT-DECORATION: none; font-stretch : condensed; } .menu-top { BORDER-RIGHT: 1px solid #333366; BORDER-TOP: 1px solid #6699CC; FONT-WEIGHT: normal; FONT-SIZE: 2px; BORDER-LEFT: 1px solid #6699CC; COLOR: #FFFFFF; BORDER-BOTTOM: 1px solid #333366; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #23559C; TEXT-DECORATION: none; font-stretch : condensed } </style> <center> <div class='menu-blue'> <div align="center"> <table width="600" cellspacing="1" cellpadding="5" style="background-color:#23559C"> <tr> <td style="background-color:#FFFFFF"> <div align="center"> <table border="0"> </form> </table> <?php $connect = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection failed!"); mysql_select_db($db, $connect) or die("Database fail!"); if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $_POST = array_map('stripslashes', $_POST); } $name = $_POST['name']; $message = $_POST['message']; //getting the data if the user is banned or not $get = mysql_query("SELECT * FROM users"); while ($row = mysql_fetch_assoc($get)) { // get data $ban_check = $row['banned']; if ($ban_check == 1) { echo "Your account has been disabled. You are no longer allowed to post."; } else { if (!$name) { echo "<div class='box'><b><span style='color:red'>You must be logged in to post!</span></b></div>"; } else { //write $write = mysql_query("INSERT INTO posts VALUES ('','$name','$message')") or die(mysql_error ()); $postcount = mysql_query("UPDATE users SET post_count = post_count + 1 WHERE username='$name'"); echo "<div class='box'><font face='arial'><b><span style='color:green'>Posted! Your name was:</span> $name</b> - Your message was....<br><br><b>$message - <a href='bbdemo.php'>View it!</a></b>"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943341 Share on other sites More sharing options...
PFMaBiSmAd Posted October 24, 2009 Share Posted October 24, 2009 And why do you have two separate sets of code in that one script connecting to the database? If you compare what each set of mysql funcitons is doing, you will see why the one you are currently having a problem with is not working. Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943342 Share on other sites More sharing options...
MySQL_Narb Posted October 24, 2009 Author Share Posted October 24, 2009 I've fixed the code. (I used another code, I believe the current one I was using didn't work for this type of function.) Quote Link to comment https://forums.phpfreaks.com/topic/178809-solved-weird-mysql-error-why-am-i-recieving-this/#findComment-943343 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.