superhoops Posted September 4, 2006 Share Posted September 4, 2006 I have a table on my database with 5 categories and when someone submits the form, all the data appears on the database correctly apart from a field called Comments where people submit data on a textarea on the form and nothing shows up on the database:Here is the code for my insert page:[code]$Name = addslashes($_POST['Name']);$Comment = addslashes($_POST['Comment']);$sql="INSERT INTO Pre SET Name = '".$Name."', Team = '".$_POST['Team']."', Rating = '".$_POST['Rating']."', Comment = '".$Comment."'";// echo $sql; for testing purposes[/code]And here is the code for the text area part of the form:[code]<textarea rows="5" name="Comment" cols="34"></textarea>[/code]IM sure its an easy thing to fix but if anyone would be able to tell me how to do it or slightly amend the insert page code bit i would be very greatful. Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 Please?[b]EDITED BY WILDTEEN88: DO NOT BUMP YOUR THREAD UNLESS IT IS ATLEAST A COUPLE OF HOURS OLD (2HRS MIN). IDEALLY YOU SHOULD BUMP YOUR THREAD EVERY 12-24 HOURS, BUT AS THE PHP HELP FORUM CAN MOVE ALONG VERY FAST 2 HOURS IS FINE[/B] Quote Link to comment Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 sanitise all input for mysql with mysql_real_escape_string(); Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 I don't understand sorry. I had a previous table in my database and the form i had submitted all the data correctly and i put the addslashes command for the fields with a textbox in. I haven't yet before this one had a text area though so i was wondering what i do? Quote Link to comment Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 The form:[code]<form action="page.php" method="post"> <textarea name="mytextarea" cols="50" rows="5"></textarea> <br /> <input type="submit" /></form>[/code]The php for page.php:[code]<?php$link = mysql_connect('host', 'user', 'pass');mysql_select_db('db', $link);if (!empty($_POST['mytextarea'])) { $sql = "INSERT INTO `table`(`column`) VALUES('" . mysql_real_escape_string($_POST['mytextarea']) . "'";} else { echo 'Input something you numpty!';}//mysql_query etc down here.?>[/code] Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 I think you thought i meant that if someone submitted nothing into the textarea nothing would happen, sorry but this is not the problem.The problem is when people submit data, they fill out all forms and all the results from the forms appear in the databse except what is submitted in the textbox. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 4, 2006 Share Posted September 4, 2006 What is shown after $sql is echoed? Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 Do you mean after the form is submitted? it goes blank but thats fine, it did that with my other page as well. Its getting the textarea info into the database. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Do you have a comment field in the database? If theres no comment field in the database, it wont add the commnt. Post your table structure for the table called [b]Pre[/b] here.ALso follow GingerRobots suggestion of echoing $sql, to whether the SQL query is actually correct. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 4, 2006 Share Posted September 4, 2006 Ah i only just noticed that you had commented this line out:// echo $sql; for testing purposesremove the comments to see what the query is showing. Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 Yes i have a field called Comments in my table. here is the code for my createtable.phpmysql_select_db("fmpsite_reg", $con);$sql = "CREATE TABLE Pre (id INT AUTO_INCREMENT PRIMARY KEY,Name varchar(30),Team varchar(30),Rating int(2),Comment varchar(300))";I have checked the database, it definately has a field called Comments.When I echo $sql should i delete the insert into Pre stuff? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 4, 2006 Share Posted September 4, 2006 It doesn't matter. We just need to see what the query actually is doing. Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 I added it, submitted the form and the page went blank after the form was submitted like before. Quote Link to comment Share on other sites More sharing options...
Jenk Posted September 4, 2006 Share Posted September 4, 2006 dude.. echo the value of $sql and paste it here.. for the love of god.. Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 ive given you all the code that is required right? This is the code i need to use to run $sql is [code]echo '$sql';[/code]That correct? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Well your not performing the query if you are just echo'ing $sql. All what [code=php:0]echo $sql[/code] will do is print whats in $sql to the browser. It wont perform the query.To run the sql query you need to run it through the mysql_query function. Before you run the query you must be connected to mysql. Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 I am connected, could someone just give me this code to run this query. Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 The whole code of the insertpre page is:<?$db = mysql_connect("username", "db", "password") or die("Could not connect.");if(!$db) die("no db");if(!mysql_select_db("fmpsite_reg",$db)) die("No database selected.");if(!get_magic_quotes_gpc())mysql_select_db("fmprotasy_reg", $con);$Name = addslashes($_POST['Name']);$Comment = addslashes($_POST['Comment']);$sql="INSERT INTO Pre SET Name = '".$Name."', Team = '".$_POST['Team']."', Rating = '".$_POST['Rating']."', Comment = '".$Comment."'";echo $sql;if (!mysql_query($sql)) { die('Error: ' . mysql_error()); }?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Now I'm confused. You are running the query, see:[code]if (!mysql_query($sql)) { die('Error: ' . mysql_error()); }[/code] Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 I always had that in the page just i didn't show that code. Do you know how to solve the problem of the textarea data not showing on the databse now? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 As many other people have requested, and you have failed to do. Post the output of [code=php:0]echo $sql;[/code] here. Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 As i said before the page goes blank when i submit the form, is that what you mean? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 So you get no outout what so ever. Looks like there is an error in there somewhere then. Tidied up the code a little. Try this:[code=php:0]<?phperror_reporting("E_ALL");echo "connecting to MySQL";$db = mysql_connect("username", "db", "password") or die("Could not connect.<br /><br />" . mysql_error());echo "connected to mysql<br /><br />";echo "Selecting database";mysql_select_db("fmpsite_reg", $db) or die("No database selected.<br /><br />" . mysql_error());echo "Database selected<br /><br />";//if(!get_magic_quotes_gpc())// mysql_select_db("fmprotasy_reg", $con);// NOT SURE ABOUT THE ABOVE SO I COMMENTED IT OUT;echo "Attempting to insert data into database<br /><br />"$Name = mysql_real_escape_string($_POST['Name']);$Comment = mysql_real_escape_string($_POST['Comment']);$sql = "INSERT INTO `Pre` SET `Name`='".$Name."', `Team`='".$_POST['Team']."', `Rating`='".$_POST['Rating']."', `Comment`='".$Comment."'";echo "SQL OUTPUT:<br /><code>{$sql}</code><br /><br />";mysql_query($sql) or die('Error: ' . mysql_error());echo "Inserted data into database";?>[/code] Quote Link to comment Share on other sites More sharing options...
superhoops Posted September 4, 2006 Author Share Posted September 4, 2006 I get this message with your code:[b]Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/www/fmprotasy.com/insertpre.php on line 23[/b] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Add a semi-colon at the end of this line:[nobbc]echo "Attempting to insert data into database<br /><br />"[/nobbc]It should be this[nobbc]echo "Attempting to insert data into database<br /><br />";[/nobbc] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.