Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2010-06-08 14:10:46

kokkie20
New member
Registered: 2010-06-08
Posts: 5

Cant get the textarea into a database

Hello,
i am using since today xinha to test some stuff,
To keep it simple for you guys to explain this:
i got a database, and there i want to add some stuff in
i got these records:

ID
gtekst
datum
titel

(its for a news system i am building)
When i use the form to add new stuff into the database, everything works, except for the textarea,

here is the query that i use to insert it:

$query="INSERT INTO gegevens (ID, gtekst, datum, titel) VALUES (NULL,'$_POST[nieuwsbericht]',NOW(),'$_POST[titel]')";

and this is the code of the text area:

<td><textarea id="newbiearea1" name="nieuwsbericht" rows="10" cols="50" style="width: 100%"></textarea></td>

anyone got a suggestion cause i tryed a lot of things, but cant get it to work.
It does insert the ID,datum and titel, but not the gtekst.

thanks.

Offline

#2 2010-06-08 21:46:18

gogo
Xinha Leader
From: New Zealand
Registered: 2005-02-11
Posts: 1,015
Website

Re: Cant get the textarea into a database

First: print_r($_POST) to see what is in there, iff you see nothing, then there are three main possibilities
  a) your form is a GET not a POST
  b) you have invalid html on the page where your textarea is, ensure your page where the textarea is validates
  c) you are submittign the form with javascript calling form.submit(), you must call the onsubmit event first if you do that
Second: $_POST[nieuwsbericht] is not valid syntax, nieuwsbericht is not a constant, you are missing quotes
Third: you should use braces when embedding variables in strings
Fourth: You are not escaping the strings leaving a potential security hole

$query="INSERT INTO gegevens (ID, gtekst, datum, titel) VALUES (NULL,'".mysql_escape_string($_POST['nieuwsbericht'])."',NOW(),'".mysql_escape_string($_POST['titel'])."')";

James Sleeman

Offline

#3 2010-06-09 07:29:51

kokkie20
New member
Registered: 2010-06-08
Posts: 5

Re: Cant get the textarea into a database

A) the form i use is not a GET form, it's a POST form wink

B) as far as i know i got valid html (i use xhtml) but will check everything out.

C) I dont use javascript to submit the form, just simple html that is referring to a php page to store the information in the database.

And i will look at the query u made for me.

thanks for helping, and i will let u know if it worked smile

and about the print_r:

Array
(
    [titel] => etas
    [submit] => Submit
)


that's all wink

Last edited by kokkie20 (2010-06-09 07:46:16)

Offline

#4 2010-06-09 08:00:03

kokkie20
New member
Registered: 2010-06-08
Posts: 5

Re: Cant get the textarea into a database

sorry for the double post but maybey this helps a little bit more to see what is wrong, (i checked everything)

### nieuwsinvoeren.php (here is the xinha page) ###

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Testing Page 1</title>
  <script type="text/javascript">
    _editor_url  = "/xinha/"  // (preferably absolute) URL (including trailing slash) where Xinha is installed
    _editor_lang = "nl";      // And the language we need to use in the editor.
    _editor_skin = "silva";   // If you want use a skin, add the name (of the folder) here
  </script>
  <script type="text/javascript" src="/xinha/XinhaCore.js"></script>
  <script type="text/javascript" src="/xinha/my_config.js"></script>
</head>
<body>

<table border="1">
<form action="bla.php" method="post">
<tr>
<td>Titel:</td>
<td><input type="text" name="titel" /></td>
</tr>
<tr>
<td>Grote tekst:</td>
<td><textarea id="newbiearea1" name="nieuwsbericht" rows="10" cols="50" style="width: 100%"></textarea></td>
</tr>
<tr colspan="">
<td><input type="submit" value="Submit" name="submit" /></td>
</tr>
</form>
</table>

</body>
</html>

### bla.php (for putting the stuff in the database, it is a testing page) ###

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
mysql_connect("localhost","root","");
mysql_select_db("nieuws");

$special = addslashes($_POST['nieuwsbericht']);

if(isset($_POST['submit'])){
    $query="INSERT INTO gegevens (ID, gtekst, datum, titel) VALUES (NULL,'".mysql_escape_string($special)."',NOW(),'".mysql_escape_string($_POST['titel'])."')";
    $sql = mysql_query($query);
    $bla = "het is gelukt!";
} else {
    $bla = "Er is iets fout gegaan!";
}

echo $bla;


echo '<pre>' . print_r( $_POST,true ) . '</pre>';

?>
<body>
</body>
</html>

### after i putted stuff in the textarea, and press submit i go to the bla.php page ###

het is gelukt!

Array
(
    [titel] => ydy
    [submit] => Submit
)

### and how it looks in the database ###


ID     gtekst          datum                            titel

38                       2010-06-09 13:56:37     ydy

---------------------------------

I know most of the php is crap i write, but i am still working on to get xinha combined with php scripting (am not a good scripter lol)
and i know i gotta check for more errors and such, but i want first that it works to insert the text into the database.

Offline

#5 2010-06-09 08:05:05

gogo
Xinha Leader
From: New Zealand
Registered: 2005-02-11
Posts: 1,015
Website

Re: Cant get the textarea into a database

Yoru HTML is invalid

<table border="1">
<form action="bla.php" method="post">
<tr>

Here is the specification for the TABLE element in html.

<!ELEMENT TABLE - -
     (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)>

FORM is not one of those.


James Sleeman

Offline

#6 2010-06-09 08:11:23

kokkie20
New member
Registered: 2010-06-08
Posts: 5

Re: Cant get the textarea into a database

edit:

thanks it works now !
thanks for the support !

if u where a girl (i assume u are a boy ^^) i would kiss u lol big_smile

Last edited by kokkie20 (2010-06-09 08:27:42)

Offline

Board footer

Powered by FluxBB