Jump to content

maxim

Members
  • Posts

    48
  • Joined

  • Last visited

    Never

Everything posted by maxim

  1. any takers ? still cant work this one out
  2. for whatever reason i think the problem is with PDO.
  3. i can var_dump the database handle (connection) and it is definatly there. the database hande is within the same scope. i dont even have any user defined functions at all. im using SQLite not MySQL and PDO for databse access/abstration. sorry i should have said that before. it is a update query. it updates 1 row and returns the number of rows effected. in my case it returns nothing, however if i remove these lines form the code i posted $sql = "SELECT * FROM posts WHERE id = '".$_GET['id']."';"; $result = $db_handle->query($sql); $selected_post = $result->fetch(); then it will return 1, meaning that it works. i however need to run BOTH querys. the first query populates a HTML form with a record from the database and works fine the second query UPDATES the record with the information the user types(edits) in the html form. it is this query that dose not work. is only works if i remove the first. which i cant do as i need the form feild populated so the data can be edited.
  4. it just echos the SQL statement, just to see if the submit button works which it dose because it echos teh SQL string. remove the echo nothing happens this is the line that wont work $db_handle->exec($edit); now if i remove the following code from what i posted. $sql = "SELECT * FROM posts WHERE id = '".$_GET['id']."';"; $result = $db_handle->query($sql); $selected_post = $result->fetch(); then this line $db_handle->exec($edit); WILL work. my question is why or at least how do i get it to work ?
  5. interesting, i did as you suggested putting the UPDATE condition statement out side the SELECT condition, with the same results, the code works the same when it is nested or outside. so im still at square 1. its defiantly possible to have a GET and POST at the same time. i have a delete query which works this way.
  6. no it wont, the echo is simply there as i stated in my first post to see if any code will work after a user presses the submit button. the echo simply echos the sting. the string is still a vaild and working SQL statement. it just wont get executed while the above SELECT statement is there
  7. i use PHP5's PDO for database access/abstration query returns a result set. (select statments where you want to see what has been returned) exec just returns the number of rows effected by your query. (Its a UPDATE query so i dont do the query method because i dont need anything returned) i also removed the ";" from the end of the SQL statements. but this didnt seem to do anything. thanks for the suggestions tho.
  8. im pretty baffed by this problem im having. Basicly i have a script which displays a entry from a database. i then call that same database record again so i can display it in a HTML form. now the code works the values of the database record get displayed in a text feild and text area of this form (so the user can edit its content). however when the submit button gets pressed the query to update the record never gets executed. to make sure the code is being run when the user presses the submit button i put and echo statement. and sure enough the button works and it echos the sting to the screen. the problem is the the UPDATE sql statement never happens. now if i take the SELECT statement,query call and fetch call and remove it from this code. the UPDATE statement will work. so my question is WHY ? why cant i execute 2 calls to my database ? <?php if ($_GET['action'] == 'edit') { $sql = "SELECT * FROM posts WHERE id = '".$_GET['id']."';"; $result = $db_handle->query($sql); $selected_post = $result->fetch(); //<input type="text" name="title" value=" $selected_post['title']"/> (this form is in an include) // submit button code // (this form is in an include and is there for edited its fine tho) if ($_POST['submit'] == true) { //this line echos just fine echo $edit = "UPDATE posts SET title='".$_POST['title']."',content='".$_POST['content']."',author_id=1,page='".$_POST['pages']."' WHERE id=".$_GET['id'].";"; //this db query never gets called it wont work (it will work when the previous slect query is removed however) $db_handle->exec($edit); } } ?>
  9. you can use output buffering, and to it with text like using dots for example. check out hudzilla.org
  10. easy just use file_get_contents, and it will put a local or a remote file in one big string.
  11. take a look at PHP's exec(); function
  12. maby in your parent class use a accessor method ie (set and get method) to set your data members. and then extend the parent class with a subclass. and access them through the subclass which would extend the patent class through inheritance. now you could set up a constructor in you parent class to set your data members OR just invoke your methods to set them so they can be accessed. failing that maby read up on OOP more in depth
  13. in my opinion the best book for bigginers is the one thorpe is talking about. http://www.hudzilla.org/php/ theres a slightly updated wiki version of this book. but i find it hard to read and like the one i linked better. its not like its out of date or anything
  14. i fixex the problem by useing and absolute path to the sqlite db. eg c:\model\database.sqlite. im also now using PDO instead of direct sqlite calls.
  15. long story shot my problem is with PHP5's built in "sqlite_open" function. basically im teaching my self PHP. and after getting to build a complex web site which got messy with procedural programming. to better understand OOP i a using a Model / View / Controller approach. not really using a "framework" at all just doing it my self. now on to the problem. i got 3 folders. model, View and controller. in my model i have a class that connects to a sqlite database and returns the database handle i have a class im my controller folder that need to manipulate that database so it uses the handle that the model provides. naturally i use includes. to include my model class's but because there is no data base in the controllers folder. the "sqlite_open" creates a NEW database if it cant connect to one. so basically i have a database with no tables. i cant put all my files in the "model" folder it kinda defeats the whole MVC way of thinking. so how where so i got from here ?
  16. so basically there is absolutely no point what so ever in declaring a instance variable public. and i realize why they are meant to be private its so you cant access it directly form the instance, correct ?
  17. im having trouble understanding whey we need to create instance variables (data members) in a class consider this code. <?php /* Filename: DataMember.php * Created on: May 15, 2007 * Author: maxim * Email: ocaumaxim@gmail.com */ $instance = new DataMember(); $instance->printString(); class DataMember { private $str; public function __construct() { $this->str = 'Hello World!'; } public function printString() { print $this->str; } } ?> now if you comment out or delete the data member declaration <? private $str; ?> the script will still work fine. it has something to do with the $this variable. could someone please explain
  18. print "x 0 0 0 0\n"; print "0 x 0 0 0\n"; print "0 0 x 0 0\n"; print "0 0 0 x 0\n"; print "0 0 0 0 x\n";
  19. i dont believe there is a PHP fuction for that. sounds like you need to find the metadata of files, like the tags on a mp3 file, the resolution ect of movie files. im pretty sure python can do this. so you could get python to output a xml file of metadata of what ever files/s you wans and get php the get the info from the xml file. OR you could extend PHP by writing a C program do do what you which (very hard)
  20. i would say its ok. but a site advertising Web Site Design should display the current standards of modern website design and at least be xhtml valid. i don't mind orange, but the theme could be tweaked a little.
  21. try and re word your question a little better. I think you will want to use the $_GET superglobal and pass in a database unique ID number to idedtify the post with the content you want. you could pass in this id as a hyperlink pointing to www.yoursite.com/update.php?id=$var. you can then use $var in a databse query to update or delete what ever you want. i hope this helps, but re-word your question so a PHP pro can help you - thats why no one has posted yet
  22. if have what will be a easy q for most of you. consider the following code if (0 and 1 > -1) { print "true"; } that if statment will never be read. im not sure why, my guess is because PHP thinks the 0 is false ?? this code how ever will work as expected if (1 and 0 > -1) { print "true"; } any one care to explain why. is it precedence ?
  23. i actualy just did this. basicly i use php 5. it has the simpleXML extension. i iterate throgh the xml file and store the values i want into one array, like so $movielist = simplexml_load_file('http://www.path to XML file'); //retrive the array of movie titles from the xml file foreach ($movielist->movie as $movie) { $array[] = $movie->title; } now all my values i want are in the $array variable. now ill chuck them into a database (assuming one is already created and has a table to put the data into) foreach ($array as $xml_title) { $sql = "INSERT INTO movie_list (title,date) VALUES(\"$xml_title\",\"$timestamp\");"; sqlite_query($dbase_connection,$sql); } for mysql specific functions - i find this book healpfull http://www.hudzilla.org/php/ i hope this helps edit, if the $timestamp var throws you off its just a simple $timestamp = time();
  24. just like to say thanks i got the ball rolling - i just had a brain freeze and didnt know where to start. still got a few issues but should be able to iron them out. so yeah, thanks again
  25. Heres my situation. theres a XML file located on the internet. every week or so. this xml file gets updated with one or two new entry's. i have a php script which can read all the entrys i want from this xml file. and then put it into a database. the problem is say i run the php script again to update the database and add the new entry's that the xml file has. every thing gets added again. each time the script is run. the enter xml file entry's are added again. so the database get full with duplicates triplcate records ect ect. how would i go about preventing the same record being added over and over. database is sqlite
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.