FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


unexpected T_VARIABLE, expecting





DanielXP
Im making an online notepad for my VIP users

i have got this code i have made so far but i keep getting this error

Parse error: syntax error, unexpected T_VARIABLE, expecting T_CASE or T_DEFAULT or '}' in notepad.php on line 17

This is the code i have made:

Code:
<?
// Connects to the config
include("config.php");



   if ($logged[username] && $logged[level] ==2)
   {
      echo("");
   }
   else
   {
      die("You must be VIP to view this page!");
   }
   switch($_GET['action']) {

$check = mysql_query("SELECT COUNT(id) AS totaal FROM notepad WHERE username = '".$logged['username']."'") or die(mysql_error());
if(mysql_result($check, 0, "totaal") == 0) {

$insert = mysql_query("INSERT INTO notepad (`username`) VALUES ('".$logged['username']."')") or die(mysql_error());
echo "You notepad account is now created!";
echo "<br><br>";
echo "<a href=\"notepad.php\"><font color=\"#000000\">Click here to continue.</font></a>";
}

else{

$notepad = mysql_query("SELECT * from notepad where username = '$logged[username]'");
$notepad = mysql_fetch_array($notepad);

echo "<style type=\"text/css\">
<!--
.style1 {color: #000000}
-->
</style>


<table width=\"630\" border=\"3\" cellspacing=\"0\" cellpadding=\"0\">

  <tr>
    <td width=\"622\">$logged[username] Notepad</td>
  </tr>

  <tr>
    <td height=\"407\"><textarea name=\"textarea\" rows=\"26\" cols=\"101\" type=\"text\" name=\"notepad\">$notepad[notepad]</textarea></td>
  </tr>
  <tr>
    <td height=\"27\"><center>
      <a href=\"notepad.php?action=update\" class=\"style1\">UPDATE</a>
    </center></td>
  </tr>
</table>
}



case "update":

$notepad = $_POST[notepad];

$update = mysql_query("Update users set notepad = '$notepad' where username = '$logged[username]'");
echo "Notepad Updated!";
echo "<a href=\"notepad.php\">Back</a>";
break;

}
?>


Cheers if you can help
AftershockVibe
Your syntax for SWITCH is wrong. You need cases directly afterward and I believe you are missing a bracket.
DanielXP
- Fixxed -

1st time i went on it it created the thing in the database

then it just wont update it

new code

Code:
<?
// Connects to the config
include("config.php");



   if ($logged[username] && $logged[level] ==2)
   {
      echo("");
   }
   else
   {
      die("You must be VIP to view this page!");
   }
switch($_GET['action']) {
default:
$check = mysql_query("SELECT COUNT(id) AS totaal FROM notepad WHERE username = '".$logged['username']."'") or die(mysql_error());
if(mysql_result($check, 0, "totaal") == 0) {

$insert = mysql_query("INSERT INTO notepad (`username`) VALUES ('".$logged['username']."')") or die(mysql_error());
echo "You notepad account is now created!";
echo "<br><br>";
echo "<a href=\"notepad.php\"><font color=\"#000000\">Click here to continue.</font></a>";
}

else{

$notepad = mysql_query("SELECT * from notepad where username = '$logged[username]'");
$notepad = mysql_fetch_array($notepad);

echo "<style type=\"text/css\">
<!--
.style1 {color: #000000}
-->
</style>


<table width=\"630\" border=\"3\" cellspacing=\"0\" cellpadding=\"0\">

  <tr>
    <td width=\"622\">$logged[username] Notepad</td>
  </tr>

  <tr>
    <td height=\"407\"><textarea name=\"textarea\" rows=\"26\" cols=\"101\" type=\"text\" name=\"notepad\">$notepad[notepad]</textarea></td>
  </tr>
  <tr>
    <td height=\"27\"><center>
      <a href=\"notepad.php?action=update\" class=\"style1\">UPDATE</a>
    </center></td>
  </tr>
</table>";
}

break;

case "update":

$notepad = $_POST[notepad];

$update = mysql_query("Update users set notepad = '$notepad' where username = '$logged[username]'");
echo "Notepad Updated!";
echo "<a href=\"notepad.php\">Back</a>";
break;

}
?>
AftershockVibe
Defaults need to be at the end of case statements otherwise they will always execute. Also, if they have a BREAK at the end they will also prevent the correct case from executing.
DanielXP
moved the default to the bottom and both of them already had the breaks

still does not update
BlackSkad
Does it still give an error? Does it set the value of the notepad to an empty string?

In the latter case, it means that it doesn't know what value $_POST['notepad'] contains. You'll need to use a form to show the textfield. Like this:
Code:
            <form action='notepad.php?action=update' method='post'>
               <table width=\"630\" border=\"3\" cellspacing=\"0\" cellpadding=\"0\">

                 <tr>
                   <td width=\"622\">{$logged['username']} Notepad</td>
                 </tr>

                 <tr>
                   <td height=\"407\"><textarea name=\"textarea\" rows=\"26\" cols=\"101\" type=\"text\" name=\"notepad\">$notepad[notepad]</textarea></td>
                 </tr>
                 <tr>
                   <td height=\"27\"><center>
                     <input type='submit'  name='submit' value='UPDATE' class='style1' />
                   </center></td>
                 </tr>
               </table>
            </form>";
DanielXP
1. it didn't set the field to blank
2. that code did not work as well
BlackSkad
DanielXP wrote:
1. it didn't set the field to blank
2. that code did not work as well


Then give us an error or something, because we can't keep guessing....
DanielXP
it don't give a error
it just says its updated
BlackSkad
Never use arrays with indeces in a dubble-quoted string (or you need to surround it with curly braces). And when using indeces, always surround them with single quotes (like $logged['username']).

Replace this line:
Code:
$update = mysql_query("Update users set notepad = '$notepad' where username = '$logged[username]'");

With this one:
Code:
$update = mysql_query("Update users set notepad = '$notepad' where username = '".$logged['username']."'");


BlackSkad
DanielXP
Still don't work

go on msn
Related topics
How To : Secure Your PHP Website
Help with PhpBB
[PHP] Error link
Code help
Why "unexpected T_ENCAPSED_AND_WHITESPACE"?
array question
Vraagje over PHP
Parse Error in PHP I can't figure out.
Problems with a Guess a Number Code.
Problems with php + mysql script.
Sending Varible back to page
Problem with Member system(or template) and $_GET[id]
php msql problem
Editing files online
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.