Jump to content

syntax error in codeing


babygurl

Recommended Posts

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'];
?>

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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'];
?>

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.