Jump to content

mpsn

Members
  • Posts

    264
  • Joined

  • Last visited

Everything posted by mpsn

  1. Yes, I meant to store to variable, but I can't even display it to browser screen, once I press submit it just redirects me to the text area form again! Any help much appreciated!
  2. Hi, I want to be able to let user type in xml text and it will be parsed and uploaded to db, but it doesn't work, it just keeps redirecting me back to this form below! here is html form: <html> <body> <form method='post' method='form.php'> <p> <textarea name="pastedXML" rows="10" cols="30"> Please paste your xml file here. </textarea> </p> <p> <input type="submit" value="Convert to SQL" name="textXML" /> </p> </form> </body> </html> Here is script (form.php;I just want to retrieve the contents typed in text area to store to variable...how??) <?php //get the text in textarea and shred it! if(isset($_POST['textXML'])) print $_POST['pastedXML']; ?> Any help much appreciated!
  3. Solved it, it's just $node=$_FILES['file']['name']; so I actually just wanted to get the xml file name and extension (so I changed $_filePath to just $node) BUT now I want to store the file path to a new variable $_filePath that I will pass to the function: writeXMltoDBviaDOM, so how do I do this? Any help much appreciated!
  4. Hi, I want to be able to let user upload XML form, and then in the action page it needs to extract that so that I can add it to the database. Here is the upload form: <html> <head></head> <body> <form method='post' action="uploadFileToDB.php" enctype="multipart/form-data"> <p> <label> Upload image<input type='file' name='imageFileType' id='imageFileType' /> </label> </p> <p> <input type='submit' value='Upload this image' name='upload' id='upload' /> </p> </form> </body> </html> Here is the uploadFileToDB.php: <?php require("PHP_xml_parsing_via_DOM.php"); //NB: this script does the actual shreddering (XML to SQL) //IF User uploaded dir or XML file successful, then: if(isset($_POST['upload'])) { //SHRED NOW //NB: how to retrieve the uploaded xml file $_filePath=?? $node=basename($_filePath); $dom=new DOMDocument(); $dom->load($node); $labelPath=array(); mysql_connect("localhost","root"); mysql_select_db("dummydpev7"); $isXdocExist=mysql_query("SELECT file_Path,file_Name FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; if(mysql_num_rows($isXdocExist)==1) { print "Entry already exists!"; $docId=mysql_next_id("xdocument")-1; } else { mysql_query("INSERT INTO xdocument (file_Path,file_Name) VALUES ('$_filePath','$node')"); $docId=mysql_next_id("xdocument")-1; } print "<br />".$docId; writeXMLtoDBViaDOM($dom->documentElement,$labelPath,$docId,$_filePath); } //ELSE else //Please upload Valid XML print "Problem with XML file being uploaded."; ?> The question in point is how do I extract the file I uploaded to set to $_filePath?? in the script so that I pass it to my function writeXMLtoDBviaDOM?? Please any help much appreciated!
  5. Yes, it was the parenthesis around the (title) in the SELECT query, thanks everyone!
  6. No, I'm saying that it doesn't work if I am trying to check if duplicate record/entry across multiple columns. Help!
  7. Hi, I need help to check multiple rows for many columns, so that the script won't re-insert a duplicate entry. For eg: $isRowExist=mysql_query("SELECT (field1,field2) from table1 WHERE field1='$f1' AND field2='$f2' "); if(mysql_num_rows($isRowExist)==1) print "already in table1!"; else //proceed to insert into table table1 *BUT I tried this and it says mysql_num_rows expects resource, and this warning only shows when I have multipel columns I want to compare (it works just fine with one column in the WHERE clause above) Please help!
  8. Yes, it is the checking of multiple fields in WHERE clause that causes problems with the mysql_num_rows, please help!
  9. Ok, I tried to put in UNIQUE, but now it doesn't insert at all into db table. <?php mysql_connect("localhost","root"); mysql_select_db("dummydpev2"); //$isXdocExist=mysql_query("SELECT (file_Path,file_Name) FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; $title="cashier"; $name="bob"; $isToyEntryExist=mysql_query("SELECT (title,name) FROM toy WHERE title='$title'"); //INSERT entry if NOT in table if(mysql_num_rows($isToyEntryExist)==0) { mysql_query("INSERT INTO toy (title,name) UNIQUE VALUES ('$title','$name')"); } else print "Already in db dummpdpev2.toy!"; ?> Please help!
  10. Why does it still keep adding the SAME entry when I refresh the page? I though the condition below $isXdocExist=mysql_query("SELECT (file_Path,file_Name) FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; if(mysql_num_rows($isXdocExist)==0) { //INSERT INTO table xdocument will ensure if I refresh browser, script SHOULDN'T re-enter same entry or is it b/c my query ($isXdocExist) is all condisered UNIQUE b/c of different primary keys? Any help much appreciated!
  11. Hi, I am trying to get the previous id for the table xdocument, but browser outputs this warning: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given for this code: <?php //HELPER FCN used by FCN: writeXMLtoDBviaDOM function mysql_next_id($table) { $result = mysql_query('SHOW TABLE STATUS LIKE "'.$table.'"'); $rows = mysql_fetch_assoc($result); return $rows['Auto_increment']; } //TEST RUN: $_filePath="C:\dir\email.xml"; $node=basename($_filePath); $dom=new DOMDocument(); $dom->load($node); $labelPath=array(); mysql_connect("localhost","root"); mysql_select_db("dummydpev"); $isXdocExist=mysql_query("SELECT (file_Path,file_Name) FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; if(mysql_num_rows($isXdocExist)==0) { mysql_query("INSERT INTO xdocument (file_Path,file_Name) VALUES ('$_filePath','$node')"); $docId=mysql_next_id("xdocument")-1; } else $docId=mysql_next_id("xdocument")-1; writeXMLtoDBViaDOM($dom->documentElement,$labelPath,$docId,$_filePath); ?> So I think my problem is with the multiple WHERE clause conditions, can I do it like what I have above? Any help much appreciated!
  12. Hi, can someone explain what: $return = $xml[$error->line - 1] . "\n"; $return .= str_repeat('-', $error->column) . "^\n"; these two lines exactly do in the display_xml_error function. Another related question to the first post in this thread is, why does nothing appear when I use (so I mean nothing is outputted in browser screen): $doc=new DOMDocument(); $doc->loadXML($xmlstr);$xml = explode("\n", $xmlstr); instead of: $doc = simplexml_load_string($xmlstr); $xml = explode("\n", $xmlstr); Btw, I got it to work, just curious about these two points. Any help much appreciated
  13. Hi, I modified the php.net's xml validate function slightly to just print "Valid XML" or else print all the errors, but it is not working. It keeps outputting "Valid XML" even though I intentionally appended "SS" to the closing message tag. Here is the script: $dom_=<<<START <?xml version="1.0" encoding="ISO-8859-1" ?> <email> <message> <to> <toFirstName type="common">Bob</toFirstName> <toLastName kind="swag">Smith</toLastName> </to> <from> <fromFirstName>Steve</fromFirstName> <fromLastName>Yzerman</fromLastName> </from> </messageSS> </email> START; //validate($dom_); //FCN SOURCE:php.net in section on libxml_get_errors libxml_use_internal_errors(true); $xml = explode("\n", $dom_); $errors = libxml_get_errors(); if(empty($errors)) print "Valid XML"; else { foreach ($errors as $error) { echo display_xml_error($error, $xml); } libxml_clear_errors(); } function display_xml_error($error, $xml) { $return = $xml[$error->line - 1] . "\n"; $return .= str_repeat('-', $error->column) . "^\n"; switch ($error->level) { case LIBXML_ERR_WARNING: $return .= "Warning $error->code: "; break; case LIBXML_ERR_ERROR: $return .= "Error $error->code: "; break; case LIBXML_ERR_FATAL: $return .= "Fatal Error $error->code: "; break; } $return .= trim($error->message) . "\n Line: $error->line" . "\n Column: $error->column"; if ($error->file) { $return .= "\n File: $error->file"; } return "$return\n\n--------------------------------------------\n\n"; } Any help is much appreciated, thanks.
  14. Hi, I found this very good tutorial at IBM's site: http://www.ibm.com/developerworks/xml/library/x-validxphp/ BUT my question is, what if any arbitrary XML file is passed passed to this xml validator function as parameter (that I will soon write), so meaning there may not be an xml schema created, so how would I validate it then b/c the link above assumes there a schema is made to use to validate. Any help much appreicated!
  15. thanks a bunch!
  16. Hi, for my purposes, I can only use core PHP function (no PEAR for eg) to convert SQL to XML, should I convert SQL to csv first, and then use php's filesystem to read each line to extract and store as xml nodes OR does someone know easier/better method? Any help much appreciated, thanks.
  17. Hi, how do I store as a string (in a variable) a mysql query b/c what I'm doing below outputs Resource id in client browser: <?php //database connection set up etc $show=mysql_query("SELECT file_Name FROM xdocument WHERE doc_id=95"); print $show; ?> Any help much appreciated, thanks.
  18. Hi, I was wondering if it is possible to have the foreign keys (FK) to automatically assign its value to the corresponding PK (primary key) it references? Let's say I have four tables (with their PK,FK and other fields) TABLE document: TABLE pathway: TABLE leaf TABLE value: PK: docID PK:pathID PK:leafID PK:valueID filePath pathway FK:pathID FK:leafID fileName FK:docID value target source So when I upload a document, it is added to TABLE document, where PK docID set, and at same time I would add the filepath to TABLE pathway, and now I want TABLE leaf's FK to AUTOMATICALLY add the pathID, docID and ALSO at same time TABLE value's FK of leafID will also be added for that ONE entry that was initally added to TABLE document, pathway. Please I hope someone understand what I want to do, I know FK is for ensuring integrity of data. Please any help is appreciated. Please use my example to help me, thanks. PS: I know the formatting is off which I noticed when I went to preview the post, sorry.
  19. I got it working, I just had the arrangements of the query mixed up
  20. Hi, I just want to know how to check if a row/record already exists for a given table, but this code gives me message in browser: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in myTest.php This is the the snippet I am running: <?php $connxn=mysql_connect("localhost","root"); $db=mysql_select_db("siliconvalley"); $toyNodePath="#document/siliconValleyHELLO"; $queryA=mysql_query("SElECT FROM pathexpress (path_express) WHERE path_express='$toyNodePath'");//make sure AT MOST ONE ROW EXISTS!! if(mysql_num_rows($queryA)==1) print "ALREADY IN table pathexpress!"; else { mysql_query("INSERT INTO pathexpress (path_express) VALUES ('$toyNodePath')"); print "ADDED $toyNodePath to table pathexpress!"; } ?> Please, any help is greatly appreciated!
  21. No, I'm saying each time I reload the script through the browser, it inserts another duplicate record. And also, I WANT to store the last inserted primary key for a given database table b/c I want to pass it as parameter to a function. Any help appreciated, thanks.
  22. I was checking online and came across this useful tidbit: SHOW KEYS FROM table WHERE Key_name = 'PRIMARY' My question is how can I take advantage of this query to only output the LAST entered primary key, b/c I want to store that as a foreign key for another table in the same database. Please help a fellow out!
  23. It is working, BUT each time I reload/refresh the browser, the script increments this value. You see, for my assignment, I need other tables to reference this PK as a FK (primary key, foreign key). Is there a simpler/better way to reference a primary key as a foreign key for other tables in same database? //get current Id of some table function mysql_next_id($table) { $result = mysql_query('SHOW TABLE STATUS LIKE "'.$table.'"'); $rows = mysql_fetch_assoc($result); return $rows['Auto_increment']; } $someId=mysql_next_id("document")-1;
  24. Thanks
  25. Yes I figured that out, BUT now I have a new problem. Please take a look at this link, thanks. http://www.phpfreaks.com/forums/index.php?topic=346585.0
×
×
  • 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.