>  $query="INSERT INTO news (newsid,title, author, body, posted)
>         //VALUES($newsid,'$title','$author', '$body', $posted)";)

What's with the // in front of VALUES?  Change to:

$query="INSERT INTO news (newsid,title, author, body, posted) ".
 "VALUES($newsid,'$title','$author', '$body', $posted)";

When you have an error indicating that a record was not inserted:
1)  Print $query to ensure it contains what you expect
2)  Change query to:  mysql_query($query) or die(mysql_error())

This will save you much frustration and unnecessary posting

Finally, show us your table structure

-----Original Message-----
From: Denis L. Menezes [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 01, 2002 11:54 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Can anyone help?


Hello friends. I have two files as follows :

1. The test.htm is as follows :

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="testphp1.php">
  <p>
    <input type="text" name="newsid">
  </p>
  <p>
    <input type="text" name="title">
  </p>
  <p>
    <input type="text" name="author">
  </p>
  <p>
    <input type="text" name="body">
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
  </form>
</body>



</html>



2. The testphp1.php is as follows:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body bgcolor="#FFFFFF" text="#000000">
<?php
$link=mysql_connect("localhost","myid","Mypassword");
if ($link){
print "link id is $link";
} else {
print "error connecting to database";
}
$posted=time();

$query="INSERT INTO news (newsid,title, author, body, posted)
         //VALUES($newsid,'$title','$author', '$body', $posted)";)
//Newsid is an INT, title is a VARCHAR author is a VARCHAR, body is a
VARCHAR
IF (mysql_query($query)){
  print "Row added to table";
  } else {
  print "error adding row";
  }
  ?>
</body>



</html>

Explanation : I run the test.htm and then the testphp1.php executes well.
The databse is connected, but the error
"error adding row" appears all the time.

Can someone tell me my error in SDyntax?

Thanks
Denis




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to