Page 1 of 1

tag board not works

Posted: Thu Jan 01, 2004 3:00 am
by Vietboy
here is a conf.php file

Code: Select all

<?php
$host = "host"; // server address 
$user = "xxx"; // database username 
$pass = "xxx"; // database password 
$db = "tag"; // database name 
$limit = "50"; // number of tags to show 

$pass = addslashes($pass); // just incase $pass contains special chars 
$con = mysql_pconnect($host,$user,$pass); 

if($con == FALSE) // if the connection fails 
{ 
  print "connection error."; 
  die(); 
} 

$db = mysql_select_db($db); 

if($db == FALSE) // if the database selection fails 
{ 
  print "connection error."; 
  die(); 
} 

if(eregi("conf.php",$_SERVER["PHP_SELF"])) 
    die("You may not access this page."); 
?> 

here is post.php

<?php 
require("conf.php") or die("Main configuration file is missing, execution may not proceed."); 

$name = $_REQUEST["name"]; 
$http = $_REQUEST["http"]; 
$msg = $_REQUEST["msg"]; 

if(!isset($name)) 
    die("You must enter a name."); 
if(!isset($msg)) 
    die("You must enter a message."); 

if(empty($name) == TRUE) 
    die("You must enter a name."); 

if(empty($msg) == TRUE) 
    die("You must enter a message."); 

$name = addslashes($name); 
$name = trim($name); 
$name = strip_tags($name); 
$name = urldecode($name); 

$http = addslashes($http); 
$http = trim($http); 
$http = strip_tags($http); 
$http = urldecode($http); 

$msg = addslashes($msg); 
$msg = strip_tags($msg); 
$msg = urldecode($msg); 

$query = "INSERT INTO `tagboard`(`name`,`http`,`msg`) VALUES('$name','$http','$msg')"; 
$result = mysql_query($query); 

print "Click <a href=view.php>here</a>."; 
?> 

here is view.php

<?php 
require("conf.php") or die("Main configuration file is missing, execution may not proceed."); 

$query = "SELECT * FROM `tagboard` ORDER BY `id` DESC LIMIT ". $limit; 
$result = mysql_query($query); 

while($rows = mysql_fetch_row($result)) 
{ 
  $r[0] = stripslashes($row["http"]); 
  $r[1] = stripslashes($row["name"]); 
  $r[2] = stripslashes($row["msg"]); 
  print "<a href=. $r[0] . target=_blank>". $r[1] ."</a>: ". $r[2] ."<br>"; 
} 
?> 

I already inserted the mysql databse as "tag"

Here is the tag.php

<!-- Insert this HTML where you would like the tagboard displayed --> 
<iframe src=view.php border=0 name=tagboard></iframe><br> 
<form action=post.php method=post target=tagboard> 
<input type=text name=name value=name><br> 
<input type=text name=http value=http://><br> 
<input type=text name=msg value=message><br> 
<input type=submit value=Submit> <input type=reset value=Reset> 
</form> 

All these files upload and up.. and i test up tag.php. 
when i clicked submit.. no entries was added or didn't show up in the view.php ifram

why is that?

?>

Posted: Thu Jan 01, 2004 3:02 am
by infolock
print "<a href=. $r[0] .

shouldn't this be

print "<a href=" . $r[0] . "

?


also, take out the quotes ( ' ) marks around your field names..

$query = "INSERT INTO `tagboard`(name,http,msg) VALUES('$name','$http','$msg')";

Posted: Thu Jan 01, 2004 3:04 am
by Vietboy
isn't that " makes end that code?

Posted: Thu Jan 01, 2004 3:14 am
by infolock
no. you are exiting the print statement, adding the variable to the end of it, adding another string, and then exiting ..

see, look , here is what you code says right now at that line :

print "<a href=. $r[0] . target=_blank>". $r[1] ."</a>: ". $r[2] ."<br>";


you are saying "<a href = .$r[0].

which is just putting a . before your value of $r[0].

so, if you are going to keep the ., exit the string and just add teh variable.

otherwise, remove the .'s around $r[0]


yes, this method :

print "<a href=". $r[0] ."


does exit the string, but again, you are exiting it, but only to ADD a variable's data to it.. and t hen telling it ." which says "ok, i added the variable, now i want to add more"

also, check out my edit. i think if you put an "or die(mysql_error())" you will see that your query isn't processed..

Code: Select all

$query = "INSERT INTO `tagboard`(`name`,`http`,`msg`) VALUES('$name','$http','$msg')"; 
$result = mysql_query($query) or die(mysql_error());
the above will give you a query error, something like

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near


instead, use this :

Code: Select all

$query = "INSERT INTO tagboard (name,http,msg) VALUES('$name','$http','$msg')"; 
$result = mysql_query($query) or die(mysql_error());

Posted: Thu Jan 01, 2004 3:28 am
by Vietboy

Code: Select all

<?php
print "<a href=". $r[0] ." target="_blank">". $r[1] ."</a>": ". $r[2] ."<br>";  

?>
still not work. what would be the right way?

Posted: Thu Jan 01, 2004 3:34 am
by infolock
yeah. did you change your sql query though?

Posted: Thu Jan 01, 2004 3:40 am
by infolock
in your VIEW.PHP file, change this :

$result = mysql_query($query);

to this :

$result = mysql_query($query) or die(mysql_error());


and see if you get an error.

Posted: Thu Jan 01, 2004 3:39 pm
by Vietboy
hmm.. nothing happen..
it just said done in status bar and the message in the field box stay the same :?: