0

I have been trying to create a website for a group, but I ran into some error I don't seem to be able to fix myself. My question is if some of you can find what I am doing wrong, I've been looking and cant seem to find anything left open or anything simular.

Thanks in advance

<?php
session_start();

//Loading template power
include_once("../attritiongaming/tpl/class.TemplatePower.inc");

//Linking templatepower to html
$tpl = new TemplatePower("test.html");

//Connecting to database
$db = new PDO('mysql:host=localhost;dbname=attritiongaming','root', 'solidusaphm8932');
    $db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$tpl->assign("name", "Jessey");

//Echo tables
echo 
"<table border='1'>
<tr>
<th>ID</th>
<th>firstname</th>
<th>lastname</th>
<th>username</th>
<th>emailadress</th>
<th>edit</th>
<th>remove</th>
</tr>";

//defining page
$page = isset($_GET['action']) ? $_GET['action'] : '';

//Start switch for page
switch ($page)
  {
    case 'edit';

      $tpl->newBlock("edit");

     try
{
  $db = new PDO('mysql:host=localhost;dbname=attritiongaming','root', 'solidusaphm8932');
  $db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql ="UPDATE members SET firstname='firstname' WHERE firstname='jessey'";

  //Secure with PDO
  $stmt = $db->prepare($sql);

  $stmt->bindParam(':firstname', $firstname, PDO::PARAM_STR);
  $stmt->bindParam(':lastname', $lastname, PDO::PARAM_STR);
  $stmt->bindParam(':username', $username, PDO::PARAM_STR);
  $stmt->bindParam(':emailadress', $emailadress, PDO::PARAM_STR);
  $stmt->bindParam(':password', $password, PDO::PARAM_STR);

  //execute sql query
  $stmt->execute();
}

//Catch errors and show them.
catch(PDOException $e)
{
  echo '<pre>';
  echo 'line '.$e->getLine().'<br>';
  echo 'file'.$e->getFile().'<br>';
  echo 'Error'.$e->getMessage();
  echo '</pre>';
}

  default:

  $tpl->newBlock("default");

  if (isset($_POST['search'])) 
  {
    $tpl->assign("searchterm", $_POST['search']);
  }

if (isset($_POST['searching']))
{
  $sql ="SELECT * FROM members WHERE username LIKE :search";

  $stmt = $db->prepare($sql);

  $search = $_POST['search']. '%';

  $stmt->bindParam(':search', $search, PDO::PARAM_STR);

  $stmt->execute();
}
  while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
  {
    $tpl->newBlock("");
  }

  $sql= "SELECT * FROM members";
$stmt=$db->prepare($sql);

$stmt->execute();

  //Loop show all members
  while($row = $stmt->fetch(PDO::FETCH_ASSOC))
  {
    echo "<tr>";
    echo "<td>" . $row['ID'] . "</td>";
    echo "<td>" . $row['firstname'] . "</td>";
    echo "<td>" . $row['lastname'] . "</td>";
    echo "<td>" . $row['username'] . "</td>";
    echo "<td>" . $row['emailadress'] . "</td>";
    echo "<td> <a href='?action=edit&id=".$row['ID']."'>Edit</a></td>";
    echo "<td> <a href='?action=remove&id=".$row['ID']."'>Remove</a></td>";
    echo "</tr>";
  }

?>
7
  • 1
    Probably a missing } - use an editor or IDE that matches up braces, or (at the very least) decent indenting Commented Dec 13, 2012 at 12:36
  • 2
    you've missed end bracet of your switch statement, put } at the end Commented Dec 13, 2012 at 12:37
  • @RhoHappy That wouldn't do that. It would not parse the file at all (so no errors) and display the code in the browser. Commented Dec 13, 2012 at 12:40
  • i know i jus wanted him to edit in the code Commented Dec 13, 2012 at 12:40
  • Please indent your code, or get a decent text editor that auto-indent your code for you...... You will find the error. And, you put semicolon ; after case 'edit'... Commented Dec 13, 2012 at 12:46

2 Answers 2

3

You haven't closed the switch and there is no "break" at the end of the default case

Sign up to request clarification or add additional context in comments.

1 Comment

You mean before the default case right? There's no need for a break at the end of the default case.
0

switch case closing braces is not closed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.