Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make a messageboard with php.
but I cant't insert data to database.
I dont know what's wrong in my code???
Can someone help me please?

HTML
<!DOCTYPE  HTML>
<html>
<head>
<title> 留言板 </title>
</head>


<body>
<form action="insert.php" method="get">
請輸入名稱: <input type="text" name="name" />
請輸入標題: <input type="text" name="title" />
請輸入留言: <input type="text" name="message"   />
請輸入電子郵件: <input type="text" name="email" />
<input    type="submit"  value="送出留言" name="post"  />
</form>

</body>
</html>

PHP
<?php
//This is insert.php

require_once("connectdb.php");// It is success!!


if(isset($_GET["name"])!=""){
    $query_insert = "INSERT INTO '1100108128'.'MB'
    ('USER','TITLE','MESSAGE','TIME','EMAIL')
VALUES (";$query_insert .= "'".$_GET["name"]."',";
    $query_insert .= "'".$_GET["title"]."',";
    $query_insert .= "'".$_GET["message"]."',";
    $query_insert .= "NOW(),";
    $query_insert .= "'".$_GET["email"]."')";
mysql_query($query_insert);
header("Location:Messageboard.php");
}
 ?>
Posted
Comments
snorkie 24-Dec-12 9:01am    
What is the error you're getting from the database?
陳建勳 24-Dec-12 9:56am    
my code can be execution but my database is not received .
[no name] 24-Dec-12 9:15am    
Tip:
print the query using echo $query_insert
check the printed version and check for any errors.
陳建勳 24-Dec-12 9:51am    
I use the echo and get this: INSERT INTO '1100108128'.'MB' ('USER','TITLE','MESSAGE','TIME','EMAIL') VALUES ('test','test','test',NOW(),'test')
I think it doesn't have any problem!!
snorkie 24-Dec-12 10:01am    
try adding some debugging: http://php.net/manual/en/function.mysql-query.php is a great place to start with query examples and debugging to go with it. see if they query returns true or false. I bet it'll end up being a permission issue.

I Think mistake in if condition...
just remove isset function and then run the code...
 
Share this answer
 
I think the problem is in the way you have quoted the table name - they should be quoted with backtick characters ( ` ), but you have used apostrophes ( ' ). See the manual[^] for details.
 
Share this answer
 
OK!
I have solved the problem.
It seems due to the part of NOW();
PHP
require_once("connectdb.php");


if(isset($_GET["name"])!=""){
	$query_insert = "INSERT INTO `1100108128`.`MB` (`ID`,`USER`,`TITLE`,`MESSAGE`,`TIME`,`EMAIL`) VALUES (";
	$query_insert .= "NULL,";
	$query_insert .= "'".$_GET["name"]."',";
	$query_insert .= "'".$_GET["title"]."',";
	$query_insert .= "'".$_GET["message"]."',";
	$query_insert .= "'" . date('Y-m-d') . "',";
	$query_insert .= "'".$_GET["email"]."');";
	
	if(!mysql_query($query_insert))
		die ("Invalid query");
	
	header("Location:Messageboard.php");
}

 ?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900