Add to Google

Writing To Database Problem With Mysql - Not Writing Forum Post

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Writing To Database Problem With Mysql - Not Writing Forum Post

beeseven
I'm making a forum and I've had several problems tonight which I've come here to ask then found the answer to myself, but this one is stumping me. Whenever it goes to write the post to the database, it saves the poster, and the time, but the part where the message would go is empty. Here's the code, with comments about what it's supposed to do (what I wanted it to do and thought it did):
CODE
$imsg = stripslashes($_POST['msg']); //Get message
if(strlen($imsg) > 5 && strlen($imsg) < 10240) //Check length
{
 $imsg = htmlspecialchars($imsg); //Change stuff to entities
 $imsg = str_replace("&amp;","&",$imsg); //Change ampersands back
 $allowedentities = array('&lt;b&gt;','&lt;/b&gt;','&lt;i&gt;','&lt;/i&gt;','&lt;u&gt;','&lt;/u&gt;',
'&lt;B&gt;','&lt;/B&gt;','&lt;I&gt;','&lt;/I&gt;','&lt;U&gt;','&lt;/U&gt;','&lt;br&gt;',
'&lt;BR&gt;','&lt;Br&gt;','&lt;bR&gt;'); //Tell which entities to change into tags
 $allowedtags = array('<b>','</b>','<i>','</i>','<u>','</u>','<B>','</B>','<I>','</I>','<U>',
'</U>','<br>','<BR>','<Br>','<bR>'); //Tell which tags to turn them into
 $imsg = str_replace($allowedentities,$allowedtags,$imsg); //Replace
 $msg = nl2br($imsg); //Add line breaks
 echo "<table class=\"posts\"><tr><td class=\"msg\">$msg</td></tr></table><br>
<form method=\"post\" action=\"temppost.php\" name=\"f2\"><input type=\"submit\" name=\"post\"
value=\"Post Message\"></form>"; //Display preview of post and post button
}
That's how it takes the message and processes it. The rest is as follows:
CODE
$postedby = $username; //Get user posting
$postedon = date("F jS, Y \a\\t g:i:sa"); //Get date/time
mysql_query("INSERT INTO `tempposts` (`postedby`,`postedon`,`msg`) VALUES ('$postedby','$postedon','$msg')"); //Send it to database
I'm not sure if it's something about the $msg variable being available in the different parts or the mySQL table. I'm kind of new to it. The data type for the message was originally a BLOB, if that matters. I tried changing it to TEXT and it still didn't work.

 

 

 


Reply

mobious
i tested your srcipt by using my own database and substituted a fixed value for $imsg and $postedby. it worked for me so i am really wondering now what happened.

Reply

beeseven
biggrin.gif I figured it out! I feel pround now (and a bit nerdy). The problem had to do with refreshing variables or something similar. I just had it store the message as a session variable, and then it was available to the second part to write to the database. Thanks mobious for figuring out it wasn't a mySQL problem.

Reply

mobious
QUOTE(beeseven @ Apr 4 2005, 04:23 AM)
biggrin.gif I figured it out! I feel pround now (and a bit nerdy). The problem had to do with refreshing variables or something similar. I just had it store the message as a session variable, and then it was available to the second part to write to the database. Thanks mobious for figuring out it wasn't a mySQL problem.
*



no prob! biggrin.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Similar Topics

Keywords : writing, database, problem, mysql, writing, forum, post

  1. Create Table - Mysql Code - Help
    (1)
  2. Mysql Error
    (3)
    ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
    script, but i'm having a problem with the installer.php file, when it trys to inseret the user
    data into the database i keep getting the following error: CODE mySQL Error: You have an error
    in your SQL syntax; check the manual that corresponds to your MySQL server version for the right
    syntax to use near ';INSERT INTO `members` (`id`, `name`, `username`, `password`, `email`,
    `title`) ' at line 1 the code that is being excuted by the php file is this: C....
  3. Html Form!
    Using MySQL?! (4)
    Hey, I need your help again! I need some good working tutorial how I can update my SQL through HTML
    form. I did use some tutorials online found with the help of google; but they do not work properly;
    I mean there are still small mistakes. I need to have a good tutorial to follow. It should be
    based on security and more things. It has to be done in proper way.......
  4. Best Php And Mysql Editor For Noobs
    anyone any php or mysql editor that is good for noob (6)
    hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
    if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
    ....
  5. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help
    guys...I want to make a simple program that will some values and then store them on a database and
    then retrieve them...uhmm let me give an example out put of what i need. This is the example say..:
    Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those are the
    data needed for input values...my question now is how can I make a database whi....
  6. Ms-access Database Question
    Allowing Web Access to the Informaton (3)
    Hi. I wanna know if there is a way of accessing an MS-Access database so that my site can extract
    data from it and make it avilable online. I have an accounting package that saves everthing in an
    MDB file and I want that info available for my clients from whereever thay are. Split Topic ....
  7. How Do I Connect To Live Database With Php Script?
    while being hosted with ComputingHost (6)
    I am not new to programming. I want to create a form to add some values into my tables, the code
    are all working. But I am not sure what is the URL to connect to my site's database. All along,
    I have been testing through MAMP, which provides a local copy of mySQL. Can anyone lend me a hand?
    My site's URL is http://limetouch.com/ ....
  8. Best Sites For Learning Php-mysql
    (4)
    Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
    php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
    a better 1) but I wan't to know what is the best site for using php with mysql (using
    phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
    postgresql version of phpmyadmin whatever it's called looks better (visually)!....
  9. Tools Needed!
    PHP & MySQL (9)
    Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
    database on my laptop, instead checking them on a web-server which takes time.....
  10. Forum Script
    (3)
    Hello, i'm wanting to start making my own forum software but i dont know where to start or what
    i need to know in order to do this. I know i will need php and mysql but what else, and could some
    one point me to a good site were i could learn php and mysql. Thanks ....
  11. Php + Mysql Question!
    While inserting data into MySQL, how can I know if the data I'm in (4)
    Basically, I want to know if the Data I'm inserting through a Form is already there or not. Sort
    of a Username registration page. I have this, but it doesn't appear to work... CODE
    $result = mysql_query("SELECT * FROM users WHERE username='$username'"); if($result == 1)
        {     echo ' ERROR! The username you have chosen already exists!';     } ....
  12. Mysql Won't Update
    (5)
    Ok, so I'm making some arcade administration software so I don't have to add games the hard
    way, well anyway, one of the features I have is that on the homepage is a featured author and as
    such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
    varibles fine and the updating page recieves them because I echoed everything, then I build the
    query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
    database itself won't update even though all the varibles are there. Here's....
  13. [php/mysql]id Trouble [resolved]
    (3)
    session_start(); include "database.php"; if (!$_SESSION || $_SESSION { // User not logged in,
    redirect to login page Header("Location: main.php"); } $result = mysql_query("select * from users
    order by id asc"); while($r=mysql_fetch_array($result)) { $username=$r ; $info=$r ; $msn=$r ;
    $email=$r ; $id=$r ; $password=$r ; $userlevel=$r ; echo " user ID
    User Level Username
    Password Email: ....
  14. [mysql/php]need Som Basic Help
    (13)
    QUOTE session_start(); include "database.php"; include "edit.inc.php"; if (!$_SESSION ) { //
    User not logged in, redirect to login page Header("Location: main.php"); } if(isset($_POST )){
    $email = $_POST ; $msn = $_POST ; $info = $_POST ; $updateemail = "UPDATE users SET email =
    '$email', msn = '$msn', info = '$info' WHERE username =
    '$username'"; mysql_query($updateemail) or die("culd not edit your info");
    echo "info updated"; } // Display logout link echo " Click here to go back to info page! "; echo
    "$email"; e....
  15. [mysql]get Id Of Loged In User?
    (7)
    how to get the id number of the loged in user? my db is id. username. password. i have tryed a
    few things.. but i never seem to get it right /ohmy.gif" style="vertical-align:middle" emoid=":o"
    border="0" alt="ohmy.gif" />....
  16. Forum Last Post And Avatar
    need little help here (5)
    hi guys. I have a little problem here. Im making my own version of forum, just got into this
    problem on the last post from the topic and displaying the users avatar. i already have a upload
    script but not for images. I tried making some experiments but it didnt work. maybe someone here
    could help me. /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
    just want to: 1.) query the last post. 2.)display the avatar of the user....
  17. Creating A Login Box That Links To My Phpbb Forum
    Have my phpBB Forum Intergrated with my Website (4)
    Can someone please give me a code that I can use to put a login box on my website, that will login a
    user into my phpBB Forum? Sort of like Having my phpBB Forum Intergrated with my Website? Thank you
    so much if you can! /angel.gif" style="vertical-align:middle" emoid=":angel:" border="0"
    alt="angel.gif" /> Ex. ....
  18. Connecting Php Site To Database
    (6)
    Please Help Me with this site's error http://gatewaybiz.x10hosting.com/surf/ ....
  19. The Artists Tutorials :mysql Basic Commands
    The Artists is an online programming unit and gfx designing clan. (0)
    Let's Talk about basic mysql commands used in php. I will now show you a list of the most common
    MySQL FUNCTIONS : QUOTE mysql_connect(MySQL server name,username,password) - opens a connection
    to a MySQL server. mysql_select_db(database name,connection id) - selects a database residing on
    the MySQL server. The database name parameter referes to an active database on the MySQL server that
    was opened with the mysql_connect function. The connection identifier is a reference to the current
    MySQL connection. mysql_query(sql query) - sends a query to the currently ac....
  20. Problem With A Mysql Join
    Problem with a mysql join (2)
    Hello I am trying to write a script whereby I can pull an image out of one database table and
    display it in relation to its category_id in another table. I am using a my_sql join function that
    is joining the tables correctly, however it only shows the one same image from the top field of
    those combined rows on every single page. I need it display the image according to its category_id
    for that particular page. I am thinking I need to set variables to represent those specific rows but
    I'm not sure how to do that. Here is my code CODE { $result = mysql_query("S....
  21. Some Mysql Basics
    (4)
    Greetings this tutorial will show you some mysql basics.. MySQL is one of the most used database. a
    simple config file at the top add this CODE ?> after $username= "root"; // Username that
    has access to your database $password= ""; //Password that has access to your database $host =
    "localhost"; // The host where the database is (mostly this is localhost) $db = "databasename"; //
    The name of the database where you want to work with //connect to the database
    mysql_connect($host,$username,$password); mysql_select_db($db); Some basic statements Now
    we'r....
  22. Evilboard (forum Software) - Multiple Categorys - Don't Work :(
    I am creating a forum and i can't fix more then 1 category. (6)
    I am at the moment trying to program my own forum, but i need more then a single category, here is
    my source: CODE function cat () { include("functions/functions.php"); echo '  
    Forum ';      global $catid;   $db = new db;   $db->connect();   $connect =
    $db->query("SELECT * FROM eb_forum WHERE catecory = '1'");   # START GET CATEGORYS #
      $catz = array();   while ( $cat = mysql_fetch_object( $connect ) ) {   /*echo "         
    {$cat->name}      Topics:      Replies:      ";*/     $catz .= "        {$cat->name}
      ....
  23. Php Search Engine Script For Mysql Database
    (11)
    A search engine is provided to facilitate the user with undemanding and clear-cut search options.
    The search facility includes simple search, search by title, search by word/phrase, ect… Thus, the
    user is at a safe distance from the risk of selecting files/folders ambiguously. In addition, a
    history of recent searches can be preserved for future perusal. Now
    day’s visitors have a large option for his needs on internet and so visitors are not vesting their
    time by following the dead links on your site. So a search engine is essential for your....
  24. Creating Profiles In Php/mysql ?
    (7)
    i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
    that some user can register to my website , and after that he can Login and log out , and he can see
    his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  25. Subquery In Mysql
    (5)
    Is there anyway to make subqueries work in MySQL? I'm pretty certain someone out there knows
    how. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Can anyone help?
    CODE Select * from ITEMS where ID="Select Max(ID) from ORDERS"; This works for MSAccess and
    SQL Server but why not in MySQL? I'll be writing some reports and I've shifted database
    from MSAccess to MySQL. Help! Thanks.....
  26. Can You Add Images Into A Mysql Database?
    Using Php? (21)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  27. Increment A Mysql Column
    how to increment a MySQL column one unit (7)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue.....
  28. Php News Script
    how to make news script that uses MySQL writen in PHP (19)
    How to make a News script with PHP + MySQL So..in this tutorial i will explain how to create PHP
    news script. first we have to create the table in My SQL.. with the code below you will do this (
    you have to enter it into SQL field ..in PHPmyADMIN) CODE CREATE TABLE news ( id int(10)
    unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title varchar(50) NOT NULL
    default '', content text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate), FULLTEXT KEY
    content (content) ) >>>> script files 1 file will show the news ,1 file will....
  29. Wap Forum
    several questions on WAP forums (9)
    /blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' /> Right i want to set up a
    wap forum for rap battling. I think i need to use php, although i might need wml not sure. so
    questions: 1) WML or PHP? 2) Can i get a forum/message board script? 3) Where can i get it? Thanks
    in advance Not making helpful thread topics and titles results in warnings, or in extreme cases, a
    ban. Don't fall into the crack. ....
  30. Problem On Mysql "order By"
    (5)
    Can someone please help...? I have a problem with using "ORDER BY" in mysql... CODE SELECT *
    FROM `foo` WHERE b='abc' ORDER BY 'number' ASC i want to sort the table out by
    the value in "number" which is a number.. but it came out to be sort by like this way...
    1->10->2->20 it only sort out the front digit.... but what i want is it will sort by how great the
    number is like this... 1->2->3........->10....->20 sorry my english isn't good enough...to
    describe my problem properly... hope you can understand and help me on this.....thx....




    1. Looking for writing, database, problem, mysql, writing, forum, post






*SIMILAR VIDEOS*
Searching Video's for writing, database, problem, mysql, writing, forum, post

*MORE FROM TRAP17.COM*
Similar
Create Table - Mysql Code - Help
Mysql Error
Html Form! - Using MySQL?!
Best Php And Mysql Editor For Noobs - anyone any php or mysql editor that is good for noob
Php And Mysql Programming - anyone knows a code for mysql and php
Ms-access Database Question - Allowing Web Access to the Informaton
How Do I Connect To Live Database With Php Script? - while being hosted with ComputingHost
Best Sites For Learning Php-mysql
Tools Needed! - PHP & MySQL
Forum Script
Php + Mysql Question! - While inserting data into MySQL, how can I know if the data I'm in
Mysql Won't Update
[php/mysql]id Trouble [resolved]
[mysql/php]need Som Basic Help
[mysql]get Id Of Loged In User?
Forum Last Post And Avatar - need little help here
Creating A Login Box That Links To My Phpbb Forum - Have my phpBB Forum Intergrated with my Website
Connecting Php Site To Database
The Artists Tutorials :mysql Basic Commands - The Artists is an online programming unit and gfx designing clan.
Problem With A Mysql Join - Problem with a mysql join
Some Mysql Basics
Evilboard (forum Software) - Multiple Categorys - Don't Work :( - I am creating a forum and i can't fix more then 1 category.
Php Search Engine Script For Mysql Database
Creating Profiles In Php/mysql ?
Subquery In Mysql
Can You Add Images Into A Mysql Database? - Using Php?
Increment A Mysql Column - how to increment a MySQL column one unit
Php News Script - how to make news script that uses MySQL writen in PHP
Wap Forum - several questions on WAP forums
Problem On Mysql "order By"
advertisement



Writing To Database Problem With Mysql - Not Writing Forum Post