You CANNOT execute the PHP script until the form is submitted.  You are
attempting to do both at the same time.
Second, ALL your text fields muse be surrounded by quotes in your INSERT
statement.
Third, use NULL, not UNIX_TIMESTAMP() to insert a timestamp field.

In the following, assume the name of your script is "thisscript.php".

<?php
if isset($submit)
{
$link=mysql_connect("localhost","myid","mypassword");
if ($link){
print "link id is $link";
} else {
print "error connecting to database";
}
$query="INSERT INTO news (newsid,title, author, body, posted)
         VALUES(\"$newsid\",\"$title\", \"$author\", \"$body\", NULL)";
IF (mysql_query($query)){
  print "Row added to table";
  } else {
  print "error adding row";
  }
exit;
}
?>
<form name="form1" method="post" action="thisscript.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>
-----Original Message-----
From: Denis L. Menezes [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 01, 2002 10:09 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Please help with code


Hello friends,

can someone tell me what is wrong with this code :


<form name="form1" method="post" action="">
  <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>
<?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, UNIX_TIMESTAMP())";
IF (mysql_query($query)){
  print "Row added to table";
  } else {
  print "error adding row";
  }
?>


It gives the link ID. But then gives "error adding row"

Thanks in advance

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