hello, I am having some trobble with a short script I made. I am trying to call some text from a database. I need to call "fulltext" when "ID" is 1. Here is what I have <?php $con = mysql_connect("localhost","xxxxxx","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxx", $con); $result = mysql_query("SELECT * FROM xxxxx WHERE ID='1'"); while($row = mysql_fetch_array($result)) { echo $row['fulltext ']; } mysql_close($con); ?> Code (markup): Dose anyone see anything wrong?
yeah... echo $row['fulltext ']; PHP: there might be a whitespace too much in text '] removing that space it should work
TheOtherOne is right you seem to have some whitespace there. Also try changing WHERE ID='1' to WHERE `ID`='1'
Also, even though this won't affect the end result, its always best to "ask" for just the fields that you want, instead of pulling every single field in your table. in other words use: SELECT FullText FROM xxxxx WHERE ID='1' instead of SELECT * FROM xxxxx WHERE ID='1' and if ID is an integer, wouldn't you leave out the apostrophes?
Ok, now I am getting a diffrent error. realtyworlddeserthomes.com/test2.php Now there is a diffrent error. What is it now? (I took the white space out of fulltext
I don't know if it was a problem when you copied over or what, but try this change. Put your mysql query on one line From: $result = mysql_query("SELECT * FROM xxxxx WHERE ID='1'"); to $result = mysql_query("SELECT * FROM xxxxx WHERE ID='1'");
I put it on one line, but it still doesen't work. Here is what I have now: <?php $con = mysql_connect("xxxxxx","xxxxx","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxx", $con); $result = mysql_query("SELECT * FROM xxxxx WHERE `ID`='1'); while($row = mysql_fetch_array($result)) { echo $row['fulltext']; } mysql_close($con); ?> Code (markup): It seems like I never get it right, even though I copied it from a site that shows you php/mysql (w2schools). I just copied it, and put my info in it instead of their stuff.
You can try replacing: $result = mysql_query("SELECT * FROM xxxxx WHERE `ID`='1'); with: $result = mysql_query("SELECT * FROM xxxxx WHERE ID='1'");
ok, took out the quotes, and nothing happend. Then I put the dobble quote at the end, and it gave me an error that there was a problem with that line of code. Maby this would be eaiser. Could someone re-write this block of code? Its not that long and it would really help. I need to take fulltext with ID of one and display it. Thanks in advanced.
Ahh, sometimes I forget to use hakim's razor. Try renaming the fulltext field to something else. it looks like fulltext actually means something in mysQL http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html Here is my code that I used and that works. You will notice my code is more complicated. That is because I like to use functions for tasks that I will use a lot. Normally, my vars and my function will be store in an include file and included on every page. $GLOBALS["mysql_server"] = "localhost"; $GLOBALS["mysql_username"] = "test"; $GLOBALS["mysql_password"] = "test"; $GLOBALS["mysql_db"] = "temptb"; function OpenDB() { global $link; $link=mysql_connect($GLOBALS["mysql_server"],$GLOBALS["mysql_username"],$GLOBALS["mysql_password"]); if(!$link){die("Could not connect to MySQL");} mysql_select_db($GLOBALS["mysql_db"],$link) or die ("could not open db".mysql_error()); } OpenDB(); $sql = "select temptext from temptable where ID = 1;"; $result = mysql_query($sql); echo mysql_error(); while($row = mysql_fetch_array($result)) { $fulltext = $row["temptext"]; echo $fulltext; } mysql_close($link); PHP:
Well, the reason I am using fulltext is because I am using, my html template, and using a joomla admin panel, I was just going to call the id of that page, and have it display the text (fulltext). So without re-building the database and recoding the admin panel, I can't do that. It must work since it works with joomla with that name. I am getting diffrent errors now with the script you just provided me with. again the site is realtyworlddeserthomes.com/test2.php.
Change where ID = 1' to where ID='1'... Edit: If you are using the imvain2 script, remove the ; after 1 in the line: $sql = "select temptext from temptable where ID = 1;"; Code (markup):
The semi colon is valid SQL statement. GPG, try this. Echo out your SQL command before it is actually being ran. Then copy and paste it in here, because without seeing the complete SQL command, its hard to determine what the actual problem is. Right now its just educated guesses.
well, I'm not that good with php/mysql, so I am not exactally sure what you mean. I think I am just going to give up on this script. Thank you for your help. I'll let you know if I have any more questions.
basically I was wanting to see what the exact sql command was being ran, as mySQL was seeing it. right before $result = mysql_query($sql); add echo $sql;