Jump to content

syntax error, unexpected $end


gaugeboson

Recommended Posts

<?php

session_start();

require("config.php");

 

$db = mysql_connect($dbhost, $dbuser, $dbpassword);

mysql_select_db($dbdatabase, $db);

 

if(isset($_SESSION['USERNAME']) == FALSE) {

header("Location: " . $config_basedir);

 

if($_POST['submit']) {

  $sql = "INSERT INTO categories(cat) VALUES('" . $_POST['cat'] . "');";

  mysql_query($sql);

  header("Location: " . $config_basedir . " viewcat.php");

}

else {

require("header.php");

 

?>

<form action="<?php echo $SCRIPT_NAME ?>" method="post">

 

<table>

<tr>

  <td>category</td>

    <td><input type="text" name="cat"></td>

    </tr>

    <tr>

    <td></td>

  <td><input type="submit" name="submit" value="add entry"></td>

  </tr>

  </table>

  </form>

<?php

}

require("footer.php");

?>

syntax error, unexpected $end (last line)

Link to comment
Share on other sites

 

Try it this way...

<?php session_start();

require("config.php");

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);

if(isset($_SESSION['USERNAME']) == FALSE) {
header("Location: " . $config_basedir);

if($_POST['submit']) {

  $sql = "INSERT INTO categories(cat) VALUES('" . $_POST['cat'] . "');";
  mysql_query($sql);
  header("Location: " . $config_basedir . " viewcat.php");
}

require("header.php");

?>
<form action="<?php echo $SCRIPT_NAME ?>" method="post">

<table>
<tr>
  <td>category</td>
    <td><input type="text" name="cat"></td>
    </tr>
    <tr>
    <td></td>
  <td><input type="submit" name="submit" value="add entry"></td>
  </tr>
  </table>
  </form>
<?php
}
require("footer.php");
?>

Link to comment
Share on other sites

<form action="<?php echo $SCRIPT_NAME ?>" method="post">

 

Needs to be:

<form action="<?php echo $SCRIPT_NAME; ?>" method="post">

 

Remember, you must always have a semicolon for things like that.

[edit below](Fixed code)

<?php
session_start();
require("config.php");

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);

if(isset($_SESSION['USERNAME']) == FALSE) {
header("Location: " . $config_basedir);

if($_POST['submit']) {
  $sql = "INSERT INTO categories(cat) VALUES('" . $_POST['cat'] . "');";
  mysql_query($sql);
  header("Location: " . $config_basedir . " viewcat.php");
}
else {
require("header.php");

?>
<form action="<?php echo $SCRIPT_NAME; ?>" method="post">

<table>
<tr>
  <td>category</td>
    <td><input type="text" name="cat"></td>
    </tr>
    <tr>
    <td></td>
  <td><input type="submit" name="submit" value="add entry"></td>
  </tr>
  </table>
  </form>
<?php
}
require("footer.php");
?>

Link to comment
Share on other sites

Well none of those modifications makes a difference.  It links to the config_basedir and then says 404 error, is there something about this config_basedir?  I have used it without issue for other pages though.

 

thats because the var doesnt exist, which leads you to a page that doesnt exist (404)

 

header("Location: " . $config_basedir);

 

Where did you set the config_basedir?

 

Should be:

 

Change the value of the $config_basedir to your own

 

<?php
session_start();
require("config.php");

$config_basedir = "http://www.somewhereInyoursite.com";

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);

if(isset($_SESSION['USERNAME']) == FALSE) {
header("Location: " . $config_basedir);

if($_POST['submit']) {
  $sql = "INSERT INTO categories(cat) VALUES('" . $_POST['cat'] . "');";
  mysql_query($sql);
  header("Location: " . $config_basedir . " viewcat.php");
}
else {
require("header.php");

?>
<form action="" method="post">

<table>
<tr>
  <td>category</td>
    <td><input type="text" name="cat"></td>
    </tr>
    <tr>
    <td></td>
  <td><input type="submit" name="submit" value="add entry"></td>
  </tr>
  </table>
  </form>
<?php
}
require("footer.php");
}
?>

Link to comment
Share on other sites

What should exactly be in place for the config_basedir?  The current value I have is http://127.0.0.1/sites/blogtastic -which isn't a page.  I guess I am kinda confused as to the purpose of this. 

 

I will get to that in a minute, but you see your code doesnt make sense.

 

Once The Username Session is False, then that missing bracket you were asked to put at the end of your script was wrong. First of all, change that piece of code:

 


if(isset($_SESSION['USERNAME']) == FALSE) {
header("Location: " . $config_basedir);

 

to

 


if(isset($_SESSION['USERNAME']) == FALSE) {
header("Location: " . $config_basedir);

  }

 

And Remove the bracket you were asked to add.

 

Now the config_basedir is up to you, or who ever coded this. Its the url the user is redirected to if the user isnt logged in. I supose it would be the Login page of your site? Or I might be wrong, but who ever coded this intented the config_basedir to be a directory plugged into the header location...

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.