babygurl Posted January 19, 2012 Share Posted January 19, 2012 Got some of the coding but I think my issues are with the syntax:( any help would be amazing thank you in advance:) can i make the code query the sql from the cookie only? instead of &_post[user]??? so maybe $sql="INSERT INTO register_vote (id, user) VALUES (''isset($_COOKIE["user"]')";?? http://pastebin.com/BuRVSbG3 <?php //get cookie and query user else echo false user if (isset($_COOKIE["user"])) //if user exist query sql for user and echo table below echo "false|gtop100:false|mcservers:false|xtremetop100:false"; else echo "false|gtop100:false|mcservers:false|xtremetop100:false"; //and somehow "setcookie" when user submits $_POST['user'] from interface.php ?> <?php mysql_connect("localhost", "root", ""); mysql_select_db("register_db"); $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_POST['user']}'"); if ($result) while($row = mysql_fetch_array($result)){ echo $row['name'] . "|gtop100:" . $row['gtop100'] . "|mcservers:" . $row['mcservers'] . "|xtremetop100:" . $row['xtremetop100']; else $sql="INSERT INTO register_vote (id, user) VALUES ('','$_POST[user]')"; $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_POST['user']}'"); echo $row['name'] . "|gtop100:" . $row['gtop100'] . "|mcservers:" . $row['mcservers'] . "|xtremetop100:" . $row['xtremetop100']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/255325-syntax-error-in-codeing/ Share on other sites More sharing options...
joel24 Posted January 19, 2012 Share Posted January 19, 2012 you have no closing parenthesis on the while loop - while(condition) { } and yes you can use isset $_COOKIE, I would use an if and set $user to contain the user id variable at the start of the code, then continue with your logic using $user if (isset($_COOKIE['user'])) { $user = $_COOKIE['user']; } else if (isset($_POST['user'])) { $user = $_POST['user']; } else { #user not set, error exit("User not set."); } #code in here ## $sql="INSERT INTO register_vote (id, user) VALUES ('','$user')"; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/255325-syntax-error-in-codeing/#findComment-1309097 Share on other sites More sharing options...
babygurl Posted January 19, 2012 Author Share Posted January 19, 2012 so would something like this work or is this just completely wrong <?php //get cookie and query user else echo false user if (isset($_COOKIE["user"])) $user = $_COOKIE['user']; } else if (isset($_POST['user'])) { $user = $_POST['user']; mysql_connect("localhost", "root", ""); mysql_select_db("register_db"); $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_COOKIE["user"]}'"); while($row = mysql_fetch_array($result)){ echo $row['name'] . "|gtop100:" . $row['gtop100'] . "|mcservers:" . $row['mcservers'] . "|xtremetop100:" . $row['xtremetop100']; else echo "false|gtop100:false|mcservers:false|xtremetop100:false"; //and somehow "setcookie" when user submits $_POST['user'] from interface.php setcookie("DWcookie", $_POST[user], time()+3600); ?> <?php mysql_connect("localhost", "root", ""); mysql_select_db("register_db"); $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_COOKIE["user"]}'"); if ($result) while($row = mysql_fetch_array($result)){ echo $row['name'] . "|gtop100:" . $row['gtop100'] . "|mcservers:" . $row['mcservers'] . "|xtremetop100:" . $row['xtremetop100']; else $sql="INSERT INTO register_vote (id, user) VALUES ('','$_COOKIE["user"')"; $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_COOKIE["user"]}'"); echo $row['name'] . "|gtop100:" . $row['gtop100'] . "|mcservers:" . $row['mcservers'] . "|xtremetop100:" . $row['xtremetop100']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/255325-syntax-error-in-codeing/#findComment-1309117 Share on other sites More sharing options...
babygurl Posted January 19, 2012 Author Share Posted January 19, 2012 WISH CODING WAS THIS EASY!!! LOL <?php //get cookie do step1,step2,step3 if (isset($_COOKIE["user"])) //step1 mysql_connect("localhost", "root", ""); mysql_select_db("register_db"); $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_COOKIE["user"]}'"); //step2 if ($result) while($row = mysql_fetch_array($result)){ //step3 echo $row['name'] . "|gtop100:" . $row['gtop100'] . "|mcservers:" . $row['mcservers'] . "|xtremetop100:" . $row['xtremetop100']; //if user has not inserted usernmae just echo false user else echo "false|gtop100:false|mcservers:false|xtremetop100:false"; //if user submited username set cookie and start at step 1 ?> Quote Link to comment https://forums.phpfreaks.com/topic/255325-syntax-error-in-codeing/#findComment-1309129 Share on other sites More sharing options...
joel24 Posted January 19, 2012 Share Posted January 19, 2012 you have many ifs with no enclosing parenthesis, the same with your while loops. <?php //get cookie do step1,step2,step3 if (isset($_COOKIE["user"])) { //step1 mysql_connect("localhost", "root", ""); mysql_select_db("register_db"); $result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_COOKIE["user"]}'"); //step2 if ($result) { while($row = mysql_fetch_array($result)){ //step3 echo $row['name'] . "|gtop100:" . $row['gtop100'] . "|mcservers:" . $row['mcservers'] . "|xtremetop100:" . $row['xtremetop100']; } //close the while loop } //end if result true //if user has not inserted usernmae just echo false user } else { //else if cookie not set echo "false|gtop100:false|mcservers:false|xtremetop100:false"; //if user submited username set cookie and start at step 1 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255325-syntax-error-in-codeing/#findComment-1309174 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.