shadowmist82
New Member
- Messages
- 10
- Reaction score
- 0
- Points
- 0
I've created a form that will send data into a database. the form is done and works fine. my issue is with the INSERT INTO (code, well so it seems from the error)
here is my code:
<?php
function query($query){
$dbhost='localhost';
$dbuser='cpanel name_ database user name';
$dbpass='*************';
$dbname='database';
$conn=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$conn);
if(!$result) {
die("$query --"Invalid query -- $query --".mysql_error());
}
return $result;
}
//sql code starts here
$occurred = $_POST['occurred'];
if ($occurred == 1){
$name= $_POST['name'];
$comment = $_POST['comment'];
$sql_insert = "INSERT INTO table(user, article) VALUES('$name','$comment')";
query($sql_insert);
$result=query("SELECT * FROM table");
while($record=mysql_fetch_object($result)){
print $record->user;
print '<br />';
print $record->article;
}
?>
i already have the user set in the database, and the table has been created.
this is the error i get when i run the program:
Invalid query -- INSERT INTO article_table(user, article) VALUES('3','hi') --
for some reason there is not sql error, and no data gets added to the table. not sure where i went wrong.
Can someone help?
here is my code:
<?php
function query($query){
$dbhost='localhost';
$dbuser='cpanel name_ database user name';
$dbpass='*************';
$dbname='database';
$conn=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$conn);
if(!$result) {
die("$query --"Invalid query -- $query --".mysql_error());
}
return $result;
}
//sql code starts here
$occurred = $_POST['occurred'];
if ($occurred == 1){
$name= $_POST['name'];
$comment = $_POST['comment'];
$sql_insert = "INSERT INTO table(user, article) VALUES('$name','$comment')";
query($sql_insert);
$result=query("SELECT * FROM table");
while($record=mysql_fetch_object($result)){
print $record->user;
print '<br />';
print $record->article;
}
?>
i already have the user set in the database, and the table has been created.
this is the error i get when i run the program:
Invalid query -- INSERT INTO article_table(user, article) VALUES('3','hi') --
for some reason there is not sql error, and no data gets added to the table. not sure where i went wrong.
Can someone help?