Jump to content

[SOLVED] Please help me with this send comment code


littlepeg

Recommended Posts

:)Hi everybody. Would you please have a look at this code for me. It shows the error message:

  "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\snyp\~phpdesigner_outputlocal_tmp~6749.php on line 41"

  I could not find out where is the problem ( :'( a new learner for php)

  Any help would be grately and appreciated. Thank you.

 

 

Here is the code

 

<?php //sendcomment.php

session_name ('YourVisitID');

session_start(); // Start the session.

 

// If no session value is present, redirect the user.

if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])) ) {

 

// Start defining the URL.

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

// Check for a trailing slash.

if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {

$url = substr ($url, 0, -1); // Chop off the slash.

}

$url .= '/index.php'; // Add the page.

header("Location: $url");

exit(); // Quit the script.

}

 

// Check if the form has been submitted.

if (isset($_POST['submitted'])) {

 

require_once ('snypdb.php'); // Connect to the db.

 

$errors = array(); // Initialize error array.

 

// Check for a user name.

if (empty($_POST['topic'])) {

$errors[] = 'Please choose your topic.';

} else {

$topic = $_POST['topic'];

}

 

if (empty($_POST['comment'])) {

$errors[] = 'Please write your ideas or recommendation.';

} else {

$comment = $_POST['comment'];

}

 

if (empty($errors)) { // If everything's OK.

// Make the query.

$query = "INSERT INTO comments (user_id, topic,comment, comment_date, approve) VALUES ('($_SESSION['user_id'])', '$topic','$comment', NOW(), 'n')";

$result = @mysql_query ($query); // Run the query.

if ($result) { // If it ran OK.

 

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);

 

// Check for a trailing slash.

if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {

$url = substr ($url, 0, -1); // Chop off the slash.

}

 

// Add the page.

$url .= '/userpanel.php';

header("Location: $url");

exit();

 

} else { // If it did not run OK.

$errors[] = 'You could not be send your comments due to a system error. We apologize for any inconvenience.'; // Public message.

$errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.

}

 

 

 

} // End of if (empty($errors)) IF.

 

mysql_close(); // Close the database connection.

 

} else { // Form has not been submitted.

 

$errors = NULL;

 

} // End of the main Submit conditional.

 

if (!empty($errors)) { // Print any error messages.

echo '<h1 id="mainhead">Error!</h1>

<p class="error">The following error(s) occurred:<br />';

foreach ($errors as $msg) { // Print each error.

echo " - $msg<br />\n";

}

echo '</p><p>Please try again.</p>';

}

// Create the form.

?>

 

<form action="sendcomment.php" method="post">

   

 

<fieldset><legend><b>Enter your comments in the form below:</b></legend>

<p><b>Choose your topic:</b> <select name='topic'>

<option>Select...</option>

<option <?php if ($topic=="Youth_club") echo ("Selected")?>> Youth Club </option>

<option <?php if ($topic=="magazine_study") echo ("Selected")?>> Magazine/Study

support Club </option>

<option <?php if ($topic=="Junior_club") echo ("Selected")?>> Junior Club </option>

<option <?php if ($topic=="girl_group") echo ("Selected")?>> Girls Group </option>

<option <?php if ($topic=="ICT") echo ("Selected")?>> ICT Education and Training </option>

<option <?php if ($topic=="Opportunity") echo ("Selected")?>> Opportunity Development Work </option>

<option <?php if ($topic=="other") echo ("Selected")?>> Other </option> </select></p>

<p><b>Your ideas or recommendations:</b> <textarea name="comment" rows="10" cols="40"></textarea></p>

</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit" /></div>

<input type="hidden" name="submitted" value="TRUE" />

<input type="hidden" name="approve" value="n"/>

</form>

 

 

What I try to do is that after a user logged in, he/she can send comments. But these comments can not publish directly unless have been approved. But somehow, I could not manage insert the user's information into database. Please help me with it.  :'( :'(

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.