Jump to content

[SOLVED] need help with code


skbanta

Recommended Posts

I'm not sure whats wrong with this but I keep getting and error.

 

<?php
$con=mysql_connect(******) or die
('A problem has occurred');
mysql_select_db(write);

$query="INSERT INTO articles (title, article, author, topic) 
VALUES ('$_POST[title]','$_POST[article]','$_POST[author]','$_POST[topic])";


if (!mysql_query($query,$con))
  {
  die('Problem Encountered');
  }
echo "Thank You";
mysql_close($con)
?>

Link to comment
https://forums.phpfreaks.com/topic/106013-solved-need-help-with-code/
Share on other sites

I went through and commented your mistakes. If this doesn't fix it, tell us what the error is.

 

<?php
$con=mysql_connect(******) or die
('A problem has occurred');

//You should use quotes around the DB name
mysql_select_db("write");

//Your were missing a single quote on the last variable
$query="INSERT INTO articles (title, article, author, topic) 
VALUES ('$_POST[title]','$_POST[article]','$_POST[author]','$_POST[topic]')";


if (!mysql_query($query,$con))
  {
  die('Problem Encountered');
  }
echo "Thank You";

//Missing a semi-colon after line
mysql_close($con);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.