View Full Version : didnt query?
Daimz
July 24th, 2006, 01:45 AM
I am using this code to try make a Content management system in flash but when I run the reading.php file I get the message "DIDNT QUERY" nothing eles just that lol so I quessing that there a problem with my query:pleased:. But I dont really understand what a query is so I dont actually know how to fix the problem.
here is my php code:
<?
$dbh=mysql_connect ("localhost", "arctosde_damz", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("arctosde_cms");;
$query = "SELECT VALUES[id, title, author, date, body] FROM news WHERE id=1";;
$result = mysql_query( $query ) or die ("didn't query");
$num = mysql_num_rows( $result );
//echo ($num);
if ($num == 1){
while ($line=mysql_fetch_array($result)) {
$ourtext = "My_text_xxx=" . $line['paramValue'];
//My_text_xxx is the variable in flash of the dynamic text field
}
print $ourtext;
} else {
print "My_text_xxx=Sorry, but I can't read the text";
}
?>
could someone please tell me where I have messed up in my query?
thanx alot
nobody
July 24th, 2006, 01:55 AM
A query is basically the PHP code connecting to the MySQL database in one way or another, whether that be looking up data, adding data, whatever, it's literally querying the database.
Now your issues comes from the line
$result = mysql_query( $query ) or die ("didn't query");
Which may or may not be obvious. Now that line is actually referencing the $query variable which comes from the line before it, which is this
$query = "SELECT VALUES[id, title, author, date, body] FROM news WHERE id=1";;
Right off the bat it would appear that the issue is the extra semi-colon ( ; ) at the end of that line, try removing that, and if that doesn't fix it I'll take a deeper look at the code for ya =)
redrum87
July 24th, 2006, 02:01 AM
I see quite a few problems. First:
this doesn't need two semicolons at the end.
mysql_select_db ("arctosde_cms");;
and instead of this for your $query variable...
$query = "SELECT VALUES[id, title, author, date, body] FROM news WHERE id=1";;
try this...
$query = "SELECT id, title, author, date, body FROM news WHERE id=1";
there's probably other errors, but those are just the ones i saw right away. in addition, the id for the $query variable should probably be a runtime variable.
edit: you beat me to it xxviii! i should see who's reading a thread before i post
Daimz
July 24th, 2006, 07:36 PM
Ok cool thanx guys it now comes up with
"My_text_xxx=Sorry, but I can't read the text" which I think acording to the code means that it is working just because I'm not running it in the swf it comes up with that but to be totally honest I dont the(the beauty of being a newb lol ahhhh).
WOuld you guys be able to help me with my next bit of code to its preety similar. I did a (;) cheack and got rid of the doubles but dont know how to layout the query and that was the prob with my other code.
<?
$My_text_xxx = $_GET['My_text_xxx'];
$dbh=mysql_connect ("localhost", "arctosde_damz", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("arctosde_cms");
$query = "UPDATE news SET VALUES [id, title, author, date, body] = '$My_text_xxx' WHERE id = 1";
$result = mysql_query( $query ) or die ("didn't query");
$num = mysql_num_rows( $result );
//this echo is just a test to see if it works don't worry bout this just leave it
//echo ($num);
if ($num == 1){
//$My_text_xxx = "My_text_xxx=" . $My_text_xxx;
//print $My_text_xxx;
} else {
//print "My_text_xxx=Sorry, but I can't write the text";
}
?>
thanx again appriciate the help.:D
Daimz
July 25th, 2006, 01:29 AM
I have had a go at trying to get the query in the writing.php to work but I still says that there is a query problem.
Heres what I did thought I do a similar thing to what you sujested with the reading.php query which was:
$query = "SELECT id, title, author, date, body FROM news WHERE id=1";
$result = mysql_query( $query ) or die ("didn't query"); which was changed from "SELECT VALUE[id, title, author]. ect"
So I thought if i changed the writing.php in a similar way from:
$query = "UPDATE news SET Values [id, title, author, date, body] = '$My_text_xxx' WHERE id = 1";
to
$query = "UPDATE news SET id, title, author, date, body = '$My_text_xxx' WHERE id = 1";
$result = mysql_query( $query ) or die ("didn't query");
it might wor. But unfortunatly lol I was wrong. Any ideas?
redrum87
July 25th, 2006, 01:42 AM
no, your original query is fine. i think what your problem is, is the "WHERE" SQL keyword. If theres no id that is equal to 1, it's probably going to spit out an error. Like I said, in most cases, anything after WHERE is usually a runtime variable. Not always, but in most cases. Try this instead...
$query = "SELECT id, title, author, date, body FROM news";
$result = mysql_query( $query ) or die ("didn't query");
That will return all the news results in whatever order they were inserted into the DB. Most of the time, things like this are ordered by the date, such as in this query...
$query = "SELECT id, title, author, date, body FROM news ORDER BY date";
$result = mysql_query( $query ) or die ("didn't query");
See if that works.
bwh2
July 25th, 2006, 09:22 AM
$query = "UPDATE news SET id, title, author, date, body = '$My_text_xxx' WHERE id = 1";
$result = mysql_query( $query ) or die ("didn't query");
^the problem with this query is that you should only be referring to columns that you are updating. so let me give some examples:
/* updates body column where id = 1 */
$query = "UPDATE news SET body = '$new_body_text' WHERE id = 1";
/* updates author and body columns where id = 1 */
$query = "UPDATE news SET author = '$new_author', body = '$new_body_text' WHERE id = 1";
/* updates title, author, and body columns where id = 1 */
$query = "UPDATE news SET title='$new_title', author = '$new_author', body = '$new_body_text' WHERE id = 1";
so that's how to write an update query.
the select query you have should work fine.
raz
July 25th, 2006, 04:31 PM
Also with PHP that is out right, on most servers a "@" sign is required in front of most mysql strings... Meaning you may want to try this:
$foo = @mysql_query($string);
$foo = @mysql_num_rows($string);
$foo = @mysql_fetch_array($string);
Just look out for those silly PHP errors =) Good luck with finding your problem.
GrzKax
July 25th, 2006, 04:39 PM
I thought that the only reason for using "@", was to get information if an error occurs but isn't fatal.
bwh2
July 25th, 2006, 04:46 PM
I thought that the only reason for using "@", was to get information if an error occurs but isn't fatal.yeah, it's used in error control. it is not required for mysql functions.
http://www.php.net/manual/en/language.operators.php#45289
raz
July 25th, 2006, 04:48 PM
Maybe its just my localhost? Sorry for my input then :(
bwh2
July 25th, 2006, 04:51 PM
nah, don't be sorry. there's very little accessible online documentation about it. a php book might actually be the best reference.
raz
July 25th, 2006, 04:54 PM
nah, don't be sorry. there's very little accessible online documentation about it. a php book might actually be the best reference.
Ya... But I'd try to help a little more except those queries in the PHP files are more confusing then my code of writing my own forum :puzzle: Maybe you could try to rewrite a few of those queries to clean them up. Just my suggestion because thats not how I write my strings. But again, everyone has their ways!
bwh2
July 25th, 2006, 05:09 PM
the queries i posted are standard SQL and PHP. not really sure how to make them any clearer than they are.
raz
July 25th, 2006, 05:14 PM
the queries i posted are standard SQL and PHP. not really sure how to make them any clearer than they are.
I meant the original posters. Yours will work but I was just stating that about the original post =\ Again, I apologize.
Daimz
July 26th, 2006, 01:29 AM
bwh2 would you be able to explain those querys a little easier because I dont quite understand. My problem comes when I have to try relate the querys back to my flash because remember it is for a flash cms. see the reason I am using
= '$My_text_xxx' is because that is the variable name of the text box in flash. Illl attatch the fla so you can see what i mean. 38047. With the way you were explaining would that mean for each different query i'd need to make a new text box and give it the variable "body_text" "news_text". Anyways thanx for all the help. Oh and I didnt wirte the php script so I'm sorry I dont actually know how to lay it out better as I a complete newb to php.:D
Daimz
July 27th, 2006, 07:18 PM
Can some one please help I am really suck with this and would really appricaite the help.
bwh2
July 28th, 2006, 10:46 AM
bwh2 would you be able to explain those querys a little easier because I dont quite understand. My problem comes when I have to try relate the querys back to my flash because remember it is for a flash cms.well, your problem was that your queries weren't in good SQL form, so nothing was going to PHP. when you run into problems like this, it's easiest to break it down into smaller, more manageable steps. so really, a flash CMS has these basic steps:
flash->php : asking for data
php->mysql : run query
mysql->php: get results
php: echo results
php->flash : load echoed results
so in this case, you can isolate the problem to step 2. you could not run the queries, because the syntax was wrong. because step 2 was broken, all steps after it did not give you the results you expected. steps 3, 4, and 5 might work, but you will not know it if step 2 is broken. now that step 2 is fixed, you test step 3 to see if it works. so on and so forth.
With the way you were explaining would that mean for each different query i'd need to make a new text box and give it the variable "body_text" "news_text".i'm not 100% sure what you're talking about. i was just giving sample queries to show you the proper form for writing an SQL UPDATE query. that's step 2.
Daimz
July 29th, 2006, 05:39 AM
hey thanx alot man appriciate the help. I have been looking at another way of doing this and I found this thread http://www.kirupa.com/forum/showthread.php?t=190375&page=1 I dont know if you are familure with it but I really like how it works and I have got it working. I am just wanting now to be able to instead of having to use the component he has put together use a simple dynamic text box with my on scrollbar to read the database content. Do you know if that is possible??
bwh2
July 29th, 2006, 09:18 AM
i'm sure it's possible. but i can't tell you how to do it as my AS days are pretty much behind me.
JoshuaJonah
July 29th, 2006, 12:49 PM
If you want more help doing it, respond and I can help with the Flash end of it.
Daimz
July 29th, 2006, 09:45 PM
I would really appricate the help man, as I a bit outa my depth:) so yeh would love all the help I can get thanx
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.