Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data couldn't be entered into the database

Status
Not open for further replies.

mancroft

Programmer
Oct 26, 2002
267
GB
I am trying to get the database to work and it is generating the following error:

POST Data couldn't be entered into the database

from the code below.

Two questions:

1. does this mean that:

$con = mysql_connect("localhost","mancroft","xxxx")

and

$db = mysql_select_db("$database")

are working alright?

2. what is wrong with:

#lets strip some chars and slashes
$name = stripslashes($name);
$name = htmlspecialchars($name);
$http = stripslashes($http);
$http = htmlspecialchars($http);
$msg = stripslashes($msg);
$msg = htmlspecialchars($msg);

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

$result = mysql_query($query)

thanks.

................................................................................................



<?php
#change localhost to the sql server, user to the correct username, and pass to the correct

password
$con = mysql_connect(&quot;localhost&quot;,&quot;mancroft&quot;,&quot;xxxx&quot;) or die(&quot;Unable to establish a connection to the database.&quot;);

#change database to the database name
$database = &quot;mancroft_tagboard&quot;;
$db = mysql_select_db(&quot;$database&quot;) or die(&quot;Couldn't select database $database.&quot;);

#lets strip some chars and slashes
$name = stripslashes($name);
$name = htmlspecialchars($name);
$http = stripslashes($http);
$http = htmlspecialchars($http);
$msg = stripslashes($msg);
$msg = htmlspecialchars($msg);

$query = &quot;INSERT INTO mytagboard(name,http,msg) VALUES('$name,$http,$msg')&quot;;

$result = mysql_query($query) or die(&quot;POST Data couldn't be entered into the database.&quot;);

echo &quot;Click <a href='view.php'>here</a>.&quot;;
?>

 
Question 1:
We cannot say. Have you tested the output of those functions against the error returns documented in the manual?

Question 2:
If the column into which you're inserting data is not numeric, then the value should be inside quotes individually, not as a group. Something like:

$query = &quot;INSERT INTO mytagboard(name,http,msg) VALUES('$name','$http','$msg')&quot;;
______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top