Kaboom Posted October 19, 2009 Share Posted October 19, 2009 Okay so I am posting this because I need some really quick help and it seems fairly simple but I can't seem to do it .... I need my post.php to post into the database for it's section which is babys so I made a table called babys with this code in it: CREATE TABLE IF NOT EXISTS `baby` ( `id` int(10) unsigned NOT NULL auto_increment, `poster` int(10) unsigned NOT NULL default '0', `subject` varbinary(45) NOT NULL, `content` varbinary(10240) NOT NULL, `date` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; Now that's the structure I used for my database. When they submit a new article it is supposed to place in those fields. Here is the code on newpost.php: <?php include "../func.php"; $_SESSION["code"]=rand(1000, 9999); if (!isset($_SESSION["user"][0])) {header('Location: login.php'); die();} ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <body> <form name="form1" method="post" action="post.php"> <p>Subject: <input class='textbox' name="subject" type="text" size="45" value=""> </p> <p> <textarea class='textbox' name="inhoud" cols="60" rows="20"></textarea> </p> <p> <label><?php echo $lang['typeCode'] ?> '<?php echo $_SESSION["code"];?>' <input class='textbox' type="text" name="code"></label></p> <p><input class='button' type="submit" name="baby" value="Post"> </p> </form> </body> </html> And then post.php is <?php include "../func.php"; $config=config(); if (!$config[3][1]) { msg("Posting closed"); } else { $_POST["subject"]=clean($_POST["subject"]); $_POST["name"]=clean($_POST["name"]); $_POST["inhoud"]=clean($_POST["inhoud"]); if (!is_user2($_POST["name"])) if (($_POST["name"]!="")&&($_POST["subject"]!="")&&($_POST["inhoud"]!="")) if ($_SESSION["code"]==$_POST["code"]) {baby($_POST["name"], ($_POST["subject"]), $_POST["inhoud"]);} else msg($lang['incorCode']); else print_r($_POST); } ?> Okay ... So why isn't this posting into the database then? EDIT: here is the func.php its using function baby($name, $subject, $inhoud) { global $db_id; $query="insert into `baby` (`poster`, `subject`, `content`, `date`) values('".$name."', '".$subject."', '".$inhoud."', now())"; $result=mysql_query($query, $db_id); if ($result) msg("The message was posted successfully."); else msg("Failed.".mysql_error()); } function is_user2($name) { global $db_id; $query="select count(*) from users where name='".$name."'"; $result=mysql_query($query, $db_id); $row=mysql_fetch_row($result); return $row[0]; } Link to comment https://forums.phpfreaks.com/topic/178233-blog-posting-into-a-database/ Share on other sites More sharing options...
Bricktop Posted October 19, 2009 Share Posted October 19, 2009 Hi Kaboom, You are not defining the $name, $subject and $inhoud variables anywhere, these are the variables you're trying to insert into your database. Normally, you would do something like: $subject=clean($_POST["subject"]); But you are doing: $_POST["subject"]=clean($_POST["subject"]); Hope this helps. Link to comment https://forums.phpfreaks.com/topic/178233-blog-posting-into-a-database/#findComment-939711 Share on other sites More sharing options...
Kaboom Posted October 19, 2009 Author Share Posted October 19, 2009 Hi Kaboom, You are not defining the $name, $subject and $inhoud variables anywhere, these are the variables you're trying to insert into your database. Normally, you would do something like: $subject=clean($_POST["subject"]); But you are doing: $_POST["subject"]=clean($_POST["subject"]); Hope this helps. So like $subject=clean($_POST["subject"]); $name=clean($_SESSION["name"]); $inhoud=clean($_POST["inhoud"]); if (!is_user2($_POST["name"])) if (($_POST["name"]!="")&&($_POST["subject"]!="")&&($_POST["inhoud"]!="")) if ($_SESSION["code"]==$_POST["code"]) {baby($_POST["name"], ($_POST["subject"]), $_POST["inhoud"]);} Right? I need them to get the code right to post or else they get an incorrect code error Link to comment https://forums.phpfreaks.com/topic/178233-blog-posting-into-a-database/#findComment-939717 Share on other sites More sharing options...
Bricktop Posted October 19, 2009 Share Posted October 19, 2009 Hi Kaboom, That's right, but with your checking code simply change all $_POST references to the relevant $variable defined previously. For example: $subject=clean($_POST["subject"]); $name=clean($_SESSION["name"]); $inhoud=clean($_POST["inhoud"]); if (!is_user2($name)) if (($name!="")&&($subject!="")&&($inhoud!="")) if ($_SESSION["code"]==$_POST["code"]) {baby($name, ($subject), $inhoud);} Hope this helps. Link to comment https://forums.phpfreaks.com/topic/178233-blog-posting-into-a-database/#findComment-939864 Share on other sites More sharing options...
Kaboom Posted October 19, 2009 Author Share Posted October 19, 2009 Okay heres my post.php no <?php include "../config.php"; include "../func.php"; include "../english.php"; if ($_SESSION["code"]==$_POST["code"]) { $subject=clean($_POST["subject"]); $name=clean($_SESSION["name"]); $inhoud=clean($_POST["inhoud"]); if (!is_user2($name)) if (($name!="")&&($subject!="")&&($inhoud!="")) if ($_SESSION["code"]==$_POST["code"]) {baby($name, ($subject), $inhoud);} } else msg($lang['incorCode']); else print_r($_POST); ?> And I get this error: Parse error: syntax error, unexpected T_ELSE in /home/kaboom/public_html/blogstuff/blog/2009/babys/post.php on line 15 So ... why exactly isn't it posting into the database :'( I just want to be able to make my blog work Link to comment https://forums.phpfreaks.com/topic/178233-blog-posting-into-a-database/#findComment-939895 Share on other sites More sharing options...
cags Posted October 19, 2009 Share Posted October 19, 2009 An if statement can't have two elses. How would it know which to go into? Link to comment https://forums.phpfreaks.com/topic/178233-blog-posting-into-a-database/#findComment-939899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.