Jump to content

MySQL not working...


mattd8752

Recommended Posts

This outputs "Successful" everytime, but nothing is put into MySQL.  The database setup is working since my other pages work.

<?php
include "./includes/dbconnect.php";
if(isset($_POST['Post'])){
$errors = 0;
if(!isset($_POST['title'])){
$errors++;
}
if(!isset($_POST['message'])){
$errors++;
}
if(!isset($_POST['forumid'])){
$errors++;
}
if(!isset($_POST['type'])){
$error++;
}else{
	if($_POST['type'] != "new" && $_POST['type'] != "reply"){
	$errors++;
	}
}


if($errors == 0){
$query = "INSERT INTO topic VALUES ('2','".$_POST['forumid']."','".$_POST['title']."','".$_POST['message']."','Guest','N/A','N/A','0','0')";
	if(!$query){
	echo "Error, ".mysql_error();
	}else{
	echo "Successful".mysql_error();
	}
}


}
if($errors != 0 || !isset($_POST['Post'])){
?>
<h1>Post a New Topic/Reply</h1>
<br>

<?php
if($errors != 0){
echo "There were " . $errors . " errors.  Please make sure all fields are filled.";
}
?>
<form method="POST" action="post.php">
  Title: <input type="text" name="title" size="20"><br><br><br>
  Message:<br>
  <textarea rows="10" name="message" cols="72"></textarea><br>
  <input type="hidden" name="forumid" value="1">
  <input type="hidden" name="type" value="new">
  <input type="submit" value="Post" name="Post">

</form>
<?php
}
include "footer.php";
?>

Link to comment
https://forums.phpfreaks.com/topic/37897-mysql-not-working/
Share on other sites

You have fotgotten mysql_query

 

if($errors == 0){

$query = mysql_quey("INSERT INTO topic VALUES ('2','".$_POST['forumid']."','".$_POST['title']."','".$_POST['message']."','Guest','N/A','N/A','0','0')");

if(!$query){

echo "Error, ".mysql_error();

}else{

echo "Successful".mysql_error();

}

}

Link to comment
https://forums.phpfreaks.com/topic/37897-mysql-not-working/#findComment-181417
Share on other sites

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.