Jump to content

Help Needed


marcus

Recommended Posts

Making a view email thingy, just keep getting the same error, can't find the problem.

[code]
<?php
require('../header.php');

if(!$_SESSION['admin']){
header ("Location: login.php");
}else {

$act = $_GET['act'];
$p = $_GET['p'];

if(!$act){
echo "Choose: <a href='emails.php?act=view'>View Unread</a> | <a href='emails.php?act=viewall'>View All</a>";
}else

if($act == view){

$sql = "SELECT * FROM `contact`";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) == 0){
echo "There are no pending emails at the moment!";
}else {
echo "<table border=0 cellspacing=3 cellpadding=2>\n";
echo "<tr><td style='border:1px solid #CCCCCC;'>ID<td style='border:1px solid #CCCCCC;'>Subject<td style='border:1px solid #CCCCCC;'>From<td style='border:1px solid #CCCCCC;'>Date Sent\n";

while($row = mysql_fetch_assoc($res)){
echo "<tr><td style='border:1px solid #CCCCCC;'>$row[id]<td style='border:1px solid #CCCCCC;'><a href=emails.php?act=view&p=read&id=$row[id]>$row[subject]</a><td style='border:1px solid #CCCCCC;'>$row[from]<td style='border:1px solid #CCCCCC;'>$row[date]\n";
}
echo "</table>";
mysql_free_result($res);
}
}

if($act == view && $p == read && isset($_GET['id'])){
$sql = "SELECT * FROM `contact` WHERE id =$_GET['id']";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);

if(mysql_num_rows($res) == 0){
echo "This email is not available";
}else {
echo "<table border=0 cellspacing=3 cellpadding=2 width=350>\n";
echo "<tr><td style='border: 1px solid #CCCCCC;'>From: $row['from']\n";
echo "<tr><td style='border: 1px solid #CCCCCC;'>Sent: $row['date']\n";
echo "<tr><td style='border: 1px solid #CCCCCC;'>Email: $row['email']\n";
echo "<tr><td style='border: 1px solid #CCCCCC;' valign=top>Message:<br>$row['body']";
echo "<tr><td style='border: 1px solid #CCCCCC;'>\n
<a href=emails.php?act=del&id=$row['id']>Delete</a> | <a href=emails.php?act=reply&id=$row['id']>Reply</a>\n";
echo "</table>";
}
}
}

require('../footer.php');

?>
[/code]

error:

[code]

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/marcus/public_html/admin/emails.php on line 35

[/code]
Link to comment
Share on other sites

Well, Line 35 is this one

[code=php:0]$sql = "SELECT * FROM `contact` WHERE id =$_GET['id']";[/code]


I dont usually use $_GET or $_POST etc as variables in my mysql queries, so not sure on the exact rules.

I would try redefining the variable as a more simple one, then use that in the query, eg:

[code=php:0]$id = $_GET['id'];
$sql = "SELECT * FROM `contact` WHERE id = '$id'";[/code]


See if that helps
Link to comment
Share on other sites

[code]
<?php
require('../header.php');

if(!$_SESSION['admin']){
header ("Location: login.php");
}else {

$act = $_GET['act'];
$p = $_GET['p'];
        $id = $_GET['id'];

if(!$act){
echo "Choose: <a href='emails.php?act=view'>View Unread</a> | <a href='emails.php?act=viewall'>View All</a>";
}else

if($act == view){

$sql = "SELECT * FROM `contact`";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) == 0){
echo "There are no pending emails at the moment!";
}else {
echo "<table border=0 cellspacing=3 cellpadding=2>\n";
echo "<tr><td style='border:1px solid #CCCCCC;'>ID<td style='border:1px solid #CCCCCC;'>Subject<td style='border:1px solid #CCCCCC;'>From<td style='border:1px solid #CCCCCC;'>Date Sent\n";

while($row = mysql_fetch_assoc($res)){
echo "<tr><td style='border:1px solid #CCCCCC;'>$row[id]<td style='border:1px solid #CCCCCC;'><a href=emails.php?act=view&p=read&id=$row[id]>$row[subject]</a><td style='border:1px solid #CCCCCC;'>$row[from]<td style='border:1px solid #CCCCCC;'>$row[date]\n";
}
echo "</table>";
mysql_free_result($res);
}
}

if($act == view && $p == read && isset($id)){

$sql = "SELECT * FROM `contact` WHERE `id` = $id";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);

if(mysql_num_rows($res) == 0){
echo "This email is not available";
}else {
echo "<table border=0 cellspacing=3 cellpadding=2 width=350>\n";
echo "<tr><td style='border: 1px solid #CCCCCC;'>From: $row['from']\n";
echo "<tr><td style='border: 1px solid #CCCCCC;'>Sent: $row['date']\n";
echo "<tr><td style='border: 1px solid #CCCCCC;'>Email: $row['email']\n";
echo "<tr><td style='border: 1px solid #CCCCCC;' valign=top>Message:<br>$row['body']";
echo "<tr><td style='border: 1px solid #CCCCCC;'>\n
<a href=emails.php?act=del&id=$row['id']>Delete</a> | <a href=emails.php?act=reply&id=$row['id']>Reply</a>\n";
echo "</table>";
}
}
}

require('../footer.php');

?>
[/code]

*on 45 now
Link to comment
Share on other sites

personally i like to concat my variables with strings

so where you have

$foo = "this is a string $var, some more...";

id do:

$foo = "this is a string". $var .", some more...";

it makes it a lot easier to see where your vars are and where you've made mistakes at

and, you never close  your table tags on lines 45 etc

you start off <tr><td> and just end it. they need to close with </td></tr>
Link to comment
Share on other sites

[quote author=mgallforever link=topic=118810.msg485840#msg485840 date=1166229196]
It really wouldn't matter if my table cells/data were closed or not, I'm not testing it in a doctype xhtml strict yet
[/quote]

well it doesnt, but its apart of being a good programmer. i doubt that anyone with some experience, while just testing, would leave table tags unclosed.

anyway, try concating the vars and see what happens with your errors
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.