Page 1 of 1

Problem with (if ()and $id in this script)

Posted: Wed Nov 27, 2002 8:15 am
by harsha
<style type="text/css">
a.nav:link {color: #AD4110; font-size:9px;font-family:Verdana, Arial, Helvetica, sans-serif;text-decoration: none}
a.nav:visited {color: #73717B;font-size:9px;font-family:Verdana, Arial, Helvetica, sans-serif;text-decoration: none}
a.nav:hover {color: #000000;font-size:9px;font-family:Verdana, Arial, Helvetica, sans-serif;text-decoration: none}
</style>
<?php

// Connects to sql server and logs in with username and password and select the required database
$connect = @mysql_connect('shadows', 'root', '') or die ('couldnt connect to sql server');
@mysql_select_db('articles') or die ('couldnt select database');

$id=$HTTP_GET_VARS["id"];
$page=$HTTP_GET_VARS["page"];
$title=$HTTP_POST_VARS["title"];
$info=$HTTP_POST_VARS["info"];
$body=$HTTP_POST_VARS["body"];

$form = "<form method=\"post\" action=\"".$PHP_SELF."\">";
$form.= "<b>Name:</b><br><input type=\"text\" name=\"name\"><br>";
$form.= "<b>Email:</b><br><input type=\"text\" name=\"email\"><br>";
$form.= "<b>Comments:</b><br><textarea name=\"msg\" cols=\"18\" rows=\"5\"></textarea><br>";
$form.= "<input type=\"submit\" name=\"submit\" value=\"comment\">";

if(isset($id)){

$query ="SELECT * FROM artikle WHERE id=$id";
$result= mysql_query($query) or die(mysql_error());
$row=mysql_fetch_row($result,MYSQL_ASSOC);
echo "<FORM>";
echo "<table width=\"85%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"379\" align=\"center\">";
echo "<tr bgcolor=\"#9C9AB6\"><td width=\"2%\" height=\"21\">&nbsp;</td>";
echo "<td width=\"98%\" height=\"21\" bgcolor=\"#9C9AB6\"><font color=\"#FAFAD2\" size=\"2\" face=\"verdana\"><b>".ucfirst($row['title'])."</b></font></td>";
echo "</tr><tr bgcolor=\"#666666\">";
echo "<td width=\"2%\" height=\"340\" bgcolor=\"#cccccc\">&nbsp;</td>";
echo "<td width=\"98%\" height=\"340\" valign=\"top\" bgcolor=\"#cccccc\"><font face=\"arial\" size=\"2\" color=\"#000000\">".$row['body']."</font></td>";
echo "</tr><tr bgcolor=\"#999999\"><td width=\"2%\"></td><td width=\"98%\"><font face=\"verdana\" size=\"2\" color=\"#ffffff\"><i>-".ucfirst($row['author'])."</i></font></td></tr></table>";
echo "<br><INPUT TYPE=\"Button\" VALUE=\"<< Back to List\" onClick=\"history.go(-1)\"></FORM>";


$sqlqry="Select * from fback where art_id=".$id;
$res=mysql_query($sqlqry) or die(mysql_error());
while($ro=mysql_fetch_array($res))
{
echo "<b>".$ro['name']."</b><br><b>".$ro['email']."</b><br><i>".$ro['msg']."</i><p>";
}

if($HTTP_POST_VARS['submit']){
echo $id;
$qry="insert into fback(art_id,name,email,msg)values('$id','$name','$email','$msg')";
$result = mysql_query($qry) or die('Query error');
echo "<b>Thank you! Information entered.<b><br>";
}
else{
echo $form;
}

}

else
{

// This is where you choose the amount you want to display in one page
$per_page = 4;

// Selects all of the data from database
$sql_text = "SELECT * FROM artikle ORDER BY ID DESC";

// Sets page number, if no page is specified, it will create page 1
if(!isset($HTTP_GET_VARS['page'])) {
$page = 1;
} else {
$page = $HTTP_GET_VARS['page'];
}

$prev_page = $page - 1;
$next_page = $page + 1; [/color]
$query = @mysql_query($sql_text);

if(mysql_num_rows($query)== 0){
echo "<b>No articles found in the database</b>";
}

// Sets up specified page

$page_start = ($per_page * $page) - $per_page;

$num_rows = @mysql_num_rows($query);

if($num_rows <= $per_page) {
$num_pages = 1;
} elseif (($num_rows % $per_page) == 0) {
$num_pages = ($num_rows / $per_page);
} else {
$num_pages = ($num_rows / $per_page) + 1;
}
$num_pages = (int) $num_pages;

if ($page > $num_pages || $page <= 0) {
echo '<p>You have specified an invalid page number.</p>';
}

$sql_text = $sql_text." LIMIT $page_start, $per_page";
$query = mysql_query($sql_text);

echo "<html><head><title>^*Articles*^Shadows - Students Educational Network</title><link rel=\"stylesheet\" href=\"index.css\" type=\"text/css\"></head>";
echo "<table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" bordercolor=\"#ffffff\" class=\"lnks\">";
echo "<font color=\"#993300\"face=\"verdana\" size=\"2\"><b>Articles Archive</b></font><font size=\"1\" face=\"verdana\">&nbsp;&nbsp; No. of Articles </font>:<font color=\"green\" size=\"1\">";
echo $num_rows."</font><p>";
while ($info = mysql_fetch_assoc($query)) {
echo "<tr><td bgcolor=\"#9C9AB6\" align=\"left\" width=\"85%\" height=\"15\" bordercolor=\"9C9AB6\">";
echo"&nbsp;<b><a href=\"$PHP_SELF?id=".$info['id']."\" class=\"lnks\">".ucfirst($info['title'])."</a></b>";
//echo "<td bgcolor=\"#9999CC\" align=\"center\" width=\"49%\"> ";
echo "<font color=\"#ffffff\" size=\"1\" face=\"verdana\">&nbsp;&nbsp;-<i>".ucfirst($info['author'])."</i></font></td></tr><tr>";
echo "<td height=\"62\" valign=\"top\" colspan=\"1\" bgcolor=\"#cccccc\" bordercolor=\"9C9AB6\">";
echo "<p><font color=\"#FFFFFF\" face=\"arial\" size=\"2\">&nbsp;&nbsp;".$info['info']."</font></p>";
echo "</td></tr><tr><td height=\"9\" colspan=\"1\" ></td></tr>";
}

//echo "<div align=\"right\">";
// This displays the "Previous" link
echo "<tr><td><table width=\"100%\" height=\"10\"><tr><td>";
echo "<div align=\"center\"><b>";
if ($prev_page != 0) {
echo "<b><a class=\"nav\" href=$PHP_SELF?page=".$prev_page."><< Prev</a>";
}

// This loops the Pages and displays individual links =

for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $page) {
echo "<a class=\"nav\" href=$PHP_SELF?page=".$i.">.$i</a>";
} else {
echo '<font size="2"> '.$i.'</font> ';
}
}

// This displays the "Next" link.
if ($page != $num_pages) {
echo "<a class=\"nav\" href=$PHP_SELF?page=".$next_page."> Next >></a>";
}
echo "</b></div></td></tr></table>";
echo "</td></tr></table>";
}
?>


hi this is the script i have for displaying the articles and i am facing problem in the part highligted in red

i am trying to have comments facility so i have made few alterations

when i try to print $id in side the if statement
if($HTTP_POST_VARS['submit'])
it is not printing, infact the data from the form is not getting inserted in to the database.

plz can any one explain whatz the problem out there in that pirticular block
can any one help me out
i am :? :? :?

Posted: Wed Nov 27, 2002 8:29 am
by volka

Code: Select all

"&lt;form method="post" action="".$PHP_SELF.""&gt;";
$form.= "&lt;b&gt;Name:&lt;/b&gt;&lt;br&gt;&lt;input type="text" name="name"&gt;&lt;br&gt;";
$form.= "&lt;b&gt;Email:&lt;/b&gt;&lt;br&gt;&lt;input type="text" name="email"&gt;&lt;br&gt;";
$form.= "&lt;b&gt;Comments:&lt;/b&gt;&lt;br&gt;&lt;textarea name="msg" cols="18" rows="5"&gt;&lt;/textarea&gt;&lt;br&gt;";
$form.= "&lt;input type="submit" name="submit" value="comment"&gt;";
that's the only form I found containing an element with the name "submit" but the url contains no parameter id
So where is it supposed to come from?