veedeoo 474 Junior Poster Featured Poster

else: on line 172, and elseif; on line 191 above. Is that how you itend it to be? or something like this else{ } and eleseif(){}?

veedeoo 474 Junior Poster Featured Poster

Change this

  else {
// Confirm the successful log-in
echo $login_name || $user_id; || "<a href=\"logout.php\">Logout</a>";
}

to this

 else {
// Confirm the successful log-in
echo $login_name."|| ".$user_id." || <a href=\"logout.php\">Logout</a>";
}
veedeoo 474 Junior Poster Featured Poster

ok, I hovered on them many times...aiming my cursor back and forth right on the spot where crashes always occur, I think it is ok now...I've reloaded the page many times and ff won't crash..It must been fixed ( fingers crossed).

Let's give it another day or two.. If it crashes again, I will definitely post an update.

Thanks,

veedeoo 474 Junior Poster Featured Poster

On my laptop, I only have the flash plugin running on Windows 7. This is the unit that crashes the most. While the others have java and other stuffs in it.

I have been observing this for almost a week now, and most of the crashes occurs when my cursor moves over somewhere near the right column ad, the login/logout text link and the header ad.

veedeoo 474 Junior Poster Featured Poster

That's true, people will always have their own preferred browser.

veedeoo 474 Junior Poster Featured Poster

Yes, the report is true.. daniweb is crashing in firefox 13.0 beta. Users should be advice not to use firefox 13.0 beta, if they are part of the Beta channel users from April 26, 2012 and on. Users must use firefox stable release, regardless of OS they currently have on their computers. I tested it on windows 7, ubuntu, and zorin os. All of these OS's are running firefox 13.0 beta.

I suspect, the crashes occur during the mouseover on the right column banner ad and on the header ad. The crashes does not occur all the time, but it will crash 3 out of 10 visits to daniweb.

The text editor is also acting up at times in firefox, but not all the time. The problem with the text editor is that the cursor is not inline with the text being type. Just like what I am doing right now. My cursur is on top line, while the typed text is apearing below.

veedeoo 474 Junior Poster Featured Poster

Hi,

The first thing you need to do is create a simple html page ( stand alone). This html page should have all the items you want on your modification. For example, if you are planning to have a form, place the form in this html page including the css. The next one, will be the form processor file, and finally test your script. For now, don't worry about the view.php. Modifying this will be easy later on, once you build a working prototype on what you want to make. The most important is to have a working stand alone script.

Once you are happy with the result, it is time we extend or modify the controller.php, view.php,add.php, edit.php and db.xml files. It should not be that hard, because it is written in OOP.

The main core of the comment block is the Controller.php. In the admin area, the settings are controlled by add.php and edit.php. The default setting options for the admin is delivered by the db.xml. Lastly, the view is where the form elements are located.

veedeoo 474 Junior Poster Featured Poster

the query can be something like this.

SET product_InInventory = CountBeforeThePurchase - 'ItemPurchasedByYourClient'

Then you send another query to get the updated count.. Say, you only have 10 items remaining, and your client type in 11.. On your controller file, you should alert the client that they cannot select more than 10.

Another option is to pre-populate your select menu for quantity.. for example

 $available = 11; 
 ## the integer 11 should be from your database.
 $option = array();
 for($qA = 1; $qA <= $available; $qA++){
 $option[] = $qA;

 $smartyOption[] = $option;

 }

 $smarty->assign('smartyOption',$smartyOption);


 ## on your template side it should be something like this

 <select name="quantity">
 {foreach $smartyOption option}
 <option>{$option}</option>
 {/foreach}
 </select>

sorry I can't use your codes as example.. I can't just decipher the logic flows of your script.

veedeoo 474 Junior Poster Featured Poster

Cool, try it and give it a chance. The upside of using NetBeans IDE is the multi-programming language support, and the ease of loading multiple projects. On top of these, it will be a lot easier to trace any variables, functions, and class instantiation across your project. So, disassembling or just learning how the programming flows of an applications inherited from other developers is a brisk.

NetBeans has an extensive search capabilities. For example, you can search $foo , foo(), or class foo. The options can be either current document or current project.

The downside of netbeans IDE is that it uses more memory compared to Eclipse, but I will take netbeans over eclipse, because netbeans has features that I need.. e.g. zend framework, smarty plugins, and many other stuffs that are not found in other IDE free or for FEE..

veedeoo 474 Junior Poster Featured Poster

@veledrom,

Let me try this one more time... I just tested this just right now, and it is working on my side.

My setup

  1. Localhost server ->xampp portable (thumb drive)
  2. Localhost OS ->windows 7 on Dell laptop

How to set up the hosts file in windows 7.
a. Click on start ==> find notepad =>right click on notepad => select run as administrator. Notepad should open up.
b. On notepad, click ==>open ==> direct file browser to ==>windows/System32/drivers/etc/ ==>if you don't see any file ==>select all files ==> select hosts file.

  1. In your host file add

    127.0.0.1 localhost
    127.0.0.1 project.local
    127.0.0.1 www.project.local

  2. Save your Changes.

  3. Open your command prompt. this should be located in acessories. On the black box, type ping project.local. You should see something like this on the black box.

    C:\Users\SomeUser>ping project.local

        Pinging project.local [127.0.0.1] with 32 bytes of data:
        Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
        Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
        Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
        Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    
        Ping statistics for 127.0.0.1:
            Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
        Approximate round trip times in milli-seconds:
            Minimum = 0ms, Maximum = 0ms, Average = 0ms
    
  4. Do the same for the www.project.local. The result will pretty much the as above .

Now, Open your browser and type project.local..It should take you to your local server. Do the same with the other one, type www.project.local

We are done with the host computer.

veedeoo 474 Junior Poster Featured Poster

ok.. sorry about the wait. I need to do some errands for my Dad...

Here is the complete script I used to test the same environment as yours. The only difference is that I did not make any user edit.

Save this as mysqlitest.php, type in your database credentials, the table name, and the column name. In this case it is name..run this script in your localhost. It should delete selected member on submit of the form.

I tested this script 10 times until all of my test members were completely deleted.. I also take advantage of the OOP the mysqli has to offer.

        <?php
            ## file name mysqlitest.php
        ## fill in the database credentials below
        $host = 'localhost';
        $dbuser = 'root';
        $dbpass = '';
        $dbname = '';

        ## define the following
       # database table
       $table = "users";
       $colName = "name";

        ## try to connect to the database
        ## instantiate the mysqli class.
        $mysqli = new mysqli($host, $dbuser, $dbpass, $dbname);


    ## get members from the database
      if ($resMembers = $mysqli->query("SELECT $colName FROM $table "))
                        { 
                                if ($resMembers->num_rows > 0)
                                {

                                        $option_block = '';

                                        while ($row = $resMembers->fetch_object())
                                        {
                                                $option_block .= '<OPTION  value="'.$row->name.'">'.$row->name.'</OPTION>'; 
                                        }

                                }
                        }


      ## end of members query.

      ## process delete on submit
            if (isset($_POST['submit'])&&(!empty($_POST['user_name'])))
            {
                    ## clean up a little
                    $user = mysqli_real_escape_string($mysqli,$_POST['user_name']);

                    ## prepare to delete
                    if ($deletethis = $mysqli->prepare("DELETE FROM $table WHERE $colName = '".$user."' "))
                    {

                            $deletethis->execute();
                            $deletethis->close();
                    }
                    else
                    {
                            echo "ERROR: could not prepare SQL statement.";
                    }
                    $mysqli->close();

                    ## do whatever …
veedeoo 474 Junior Poster Featured Poster

ok, I see why the codes is not working. let me test if my hunch is correct... maybe not..

veedeoo 474 Junior Poster Featured Poster

ok,,

Let say we have a table named users, and this table have the following columns.

id -------- name ------- lastName -------- occupation ------- addresss ----- hobby .

and this table have one member named poorBoy, the entry would be something like this

01 ---- poor --------- Boy ---------------- Neo's Side Kick ------ Zion --------- drinking coffee

Then if we want to delete myself from our members table, then the query will be like this

 $names = "poor";

 $sql = "DELETE FROM users WHERE name = '$names' ";
veedeoo 474 Junior Poster Featured Poster

Yeah... The thing with that is Michelle is under name in the db, not user_name...

but your codes above

else {
$sql = "DELETE FROM users WHERE user_name = '$names' ";
$res = mysqli_query($mysqli, $sql);

is using the user_name as the users column name, and not name as you have stated. So, if the column name is name, then both of Adav's and my suggestions should work without any problem..

In fact, I just run a test on my localhost.. including the codes I posted above, and it is working perfectly on my side.

Just change the query to

 $sql = "DELETE FROM users WHERE name = '$names' ";
veedeoo 474 Junior Poster Featured Poster

The benefits is that you can build a core where all of the classes needed by your applications are included. In this core, you would have : database CRUD class, content management class, javascript class, templating class, form generator class, and many other classes that are known to be reusable by targeted applications big and small e.g. blog, cms, forum, and many others.

Having those classes in the core, we can easily build an application based on what those classes does.

Fore example, if we have a class to make all kinds of fruit juices, and we want to make an orange juices from a fresh orange, then our controller file can be something like this

 class MakeOrangeJuice extends juices_controller{
   ## since we want fresh orange and not the type of juices in our fruit juices class, we can add it here.
   private $freshOrangeOnly;

      public function __construct(){

      ## since making fruit juices are all alike.. there are always similarities on how to squeeze them, putting them in a glass, and chilling them.
      ## parent construct will be the basic methods on how to create fruit juices as defined in the juices_controller
      parent::__construct();
      $this->freshOrangeOnly = "valencia orange";
      ## we send this thing to our model page
      $this->load->model('orangejuice_model');

      }

Our model page will be the processes or procedures of making the actual orange juice

   ## this is the model

   class OrangeJuice_model extends juices_Model {
    private $quantity;
    private $quality;
    public function __construct()
    {
        $this->load->squeezer();
        $this->quantity = $quantity;
        $this->quality = null; …
veedeoo 474 Junior Poster Featured Poster

Have you tried using a using NetBeans IDE? It literally comes with everything you need I think..

veedeoo 474 Junior Poster Featured Poster

@HiWorld,

Deleting entries in mysqli is sometimes problematic. This is the first one I used before I learned how to use PDO.. you will have to go by its proper syntax. prepare->execute->close(), and then finally closing the database connection.

So, if I will be using a mysqli class on my project, instead of PDO, and wanted to delete item from my database, my codes can be something very similar to this. Not the best one I could come up with.. it is Friday which is a lazy day for me as always. No school and no worry :), just chillin' with my coffee mug..

<?php
  ## include your database info.
  require('config.php');

    ## try to connect to your database
    ## instantiate the mysqli class
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAMETWO);

if (isset($_POST['submit'])&&(!empty($_POST['user_name'])))
    {
            ## clean up a little
            $user = mysqli_real_escape_string($mysqli,$_POST['user_name']);

            ## prepare statement to delete
            if ($deleteThis = $mysqli->prepare("DELETE FROM users WHERE user_name = '".$user."' "))
            {

                    $deleteThis->execute();
                    $deleteThis->close();
            }
            else
            {
               ## you can assign this error to some variable if you want.
               echo "ERROR: could not prepare MYSQLI statement.";
            }
            $mysqli->close();

            ## do whatever you want here after sucessful deletion
            echo "Member: ".$user." has been deleted from Users table.";
    }

    else{

            ## form is submitted empty
            ## can't delete an empty item
            ## send back to previous page.
        }

      ?>

There is catch in my codes above though. For instance, if we want to delete user based on its "id" which is an integer, then the …

veedeoo 474 Junior Poster Featured Poster

The closest thing I could find is http://groceryguide.com/ . To build a site such as this, you need to learn how to parse webpages, rss feed, and maybe xml file.

For example, you can send your parsing spider to Albertson's to get the weekly sale, you can then save the collected data in your database. Your spider should be run by cron on the day that the weekly specials are published by the stores in your area.

Some stores don't have a website, if this the case the items should be inputted manually.. For the location, you can integrate the google maps API to show the loation and direction to the store from your visitor's IP location.

Again, it is a theory at this point, but it can be done in PHP. Expect to spend about 45 days for this project...

veedeoo 474 Junior Poster Featured Poster

Hi,

You don't escaped double quotes inside a single quotes..

      echo '
</select>
<input type="submit" value="Search" class="button" />
</form>
</div>
<div id="menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</div>
';

The best way to do it is to close the php tag and then show your html as pure html. This way you don't have to worry making mistakes on escaping..BUT NOT in your case though, because it is wrapped within function..

veedeoo 474 Junior Poster Featured Poster

Hi,

On top of mschroeder's question, does your wamp server have this file in it? => c:\wamp\apache\conf\extra\httpd-vhosts.conf ? I just hate donwloading a copy, because they want me to provide my email address. I already have enough junk mails to deal with on a daily basis.

veedeoo 474 Junior Poster Featured Poster

You are very much welcome. Just let us know if you need help in setting up the xampp package with ioncube loader.

veedeoo 474 Junior Poster Featured Poster

ok, I think I got it...

Change this

$class = $result[0];

to

$class = $result['class_name'];

and

$instructor = $result[1];

to

 $instructor = $result['instructor'];
veedeoo 474 Junior Poster Featured Poster

Hi,

Before jumping into possible solution, may I have more info. about your database? class and the instructor tables.

The reason I am asking is because of this

$class = $result[0];

and this

 $instructor = $result[1];

Both will return ONE..

veedeoo 474 Junior Poster Featured Poster

There is no guarantee that your data will remain encrypted. The reason is that if you distribute these encrypted data, the decryption must be supported by the browser and without internet connection. That leaves you to only one type of encryption method, the javascript encryption. This type encryption can be easily broken by anyone who can search the internet.

The second option is to distribute your application with lightweight xampp thumb drive edition, pre-stored your data with base64_encode.. this should give you an encryption very identical to the BLOB data. Actually, blob data seems to appear to me as just another derivative of base64 hashing. The downside of this if the user try to take a peek on the database, they can of course decode everything using a simple base64_decode function.

The third option is to utilize option two above, with the only exemption of not having a built in database in the distribution. The client only needs the ability to run pHP script on their desktop. However, this will require an Internet connection to retrieve data from your server.

The idea is simple, you just need to provide a unique ID.. the php script included in the xampp will then access the Internet and validate the unique ID with the remote server (your server). If the unique ID is valid, then the cURL in the local xampp gets executed to retrieved the decrypted data coming from your site.

The advantage of this is you have more control over the …

veedeoo 474 Junior Poster Featured Poster

Hi,

I believe Windows is blocking the script from writing on C drive. Possible reason is that the location where the script is trying to write the file is outside of its working space, and the script do not have permission to do so.

Try changing the target location for logs_php.txt , it should be anywhere between htdocs and aaa directories. PHP script will not be able to write outside the htdocs directory. Outside this directory are write protected, and should be done by the root, but in windows there is no such definition unless you are physically writing the file . I mean DOS command can write in any space and any part of the physical drive, but not in php. PHP is more confined in the htdocs directory.

There a few exemption to this rule.. for example, if the php script is designed to execute a video encoder such as ffmpeg, mencoder, and metadata injectors such as flvtool2. Even though these applications are located in the root of the C drive, php exec function will still be able to execute these program without restriction. However, if we closely analyze what is really going on during the process, the output file is still saved and must be saved below the htdocs. All errors encountered by the ffmpeg during the process still have to be routed somewhere below the htdocs and not anywhere in the C drive.

veedeoo 474 Junior Poster Featured Poster

Hi,

Please read this one Here. You need table join. In your case, code below

  'conditions' => array(
 'Channel.id = Item.channel_id',
 )

can be modified to

 'conditions' => array(
 'word.user_id = user.id',
 )

I can't write any sample for this question, because the response is pretty lengthy... please update us with your progress.

veedeoo 474 Junior Poster Featured Poster

we can also do it by finding the ip of the host machine..open command prompt on windows and type

ipconfig

The local machine ip should be something like IPv4 or something in this pattern 192.xxx.xx.x . This ip can be access by other machines via browser using this http://192.xxx.xx.x/project/ as url.

During the first run, a firewall might block it. Allow the accesss as necessary..

veedeoo 474 Junior Poster Featured Poster

it is called concatenating assignment operator, or "dot equals", which is pretty similar to += plus equals in java language.

for more info. read more about it Here.

But in the event where we are dealing with the items inside a loop like for, foreach, and while loops. You can do the array like this

  $thisArray = ();
 while(something is true){
 ## iterated items
 $thisArray['itemOne'] = $itemOne;
 $thisArray['itemTwo'] = $itemTwo;
 ## we can easily print the items within the array in this section, but we don't like that.
 ## so instead, we can assign it to something like my example below

 $asignedArray[] = $thisArray;

 }
  ## outside the while loop or anywhere. It can also be another page as long as you can pass it down or extend. You can do this

  foreach($asignedArray as $item){

  echo $item[0];
  echo $item[1];

  }

  ## you can also use $item['itemOne'],.. and so forth.

By following this simple system, we can easily convert anything to templating system in the likes of smarty, twigs and many others. Say, if we want to send the $thisArray to templating system. We just delete the foreach loop below and make the assignment to the template.

veedeoo 474 Junior Poster Featured Poster

CORRECTIONS!

Do it like this

 ## lets add proxy type
 CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
 ## lets add the proxy ip
 CURLOPT_PROXY => 'http://64.202.165.130:3128',

Use comma intead, because it is an array..... I completely missed it BIG time... :). I think I am just running out of coffee..

veedeoo 474 Junior Poster Featured Poster

oh YESSSSSS,,, thanks diafol... You are so cool.. :)

veedeoo 474 Junior Poster Featured Poster

Hi,

for the accents, we need to make a separate validation function for it.. e.g.

function isItLatin($username) {
$itIs = false;

if (preg_match("/^[\w\d\s.,-]*$/", $username)) {
    $itIs = true;
}

return $itIs;
}

Based on the accented character validation result, we can use different filters e.g. English, or Latin filters. So for instance, we have an accented input in the form, if the function above recognizes it as part of the acceptable characters within bound, then this

$username = preg_replace('/[^a-zA-Z0-9 ]/s', ' ', $_POST['username']);

Will no longer apply or used, but instead we make the script by using the simple validation as included in the class itself

 ## this will allow usage of the accented characters
 $username = trim($_POST['username']);

For the javascript validation for accented characters, you can read more Here, it is pretty much self-explanatory..

rogerg commented: thx +0
veedeoo 474 Junior Poster Featured Poster

Hi,

Is this the PHP/SDK you are currently using?

if so, then additional cURL configuration can be added like this

 public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
## lets add proxy type 
CURLOPT_PROXYTYPE => CURLPROXY_HTTP;
## lets add the proxy ip
CURLOPT_PROXY => 'http://64.202.165.130:3128';
CURLOPT_USERAGENT => 'facebook-php-3.1',

If NOT, look for function curl_setopt_array in your base_facebook.php. You should be able to see how the options were defined. Better yet, just post the code here, and we will try to help you out.

  function curl_setopt_array ($ch, $opts){

  }
veedeoo 474 Junior Poster Featured Poster

@hwoarang69;

Here is a sample just to help you out..

## first you need to take the form out of the echo zone..
else
    {
    ## it is ok to close PHP below 
    ?>
    <!-- codes below can be pure html.. Don't let your php parser to parse something that can be directly given to the browser -->

   <!-- not loged in(not member) -->

    <h2> YOU ARE NOT LOG IN!</h2>
    <form method="post" action="login.php">
    <strong>Member Login </strong><br/>
    <p id = "login_error"> </p>
    <label>Username:</label>
    <input name="username" type="text" id="username"><br/>
    <label>Password: <label>
    <input name="password" type="password" id="password"><br/>
    <input type="submit" value="Login" name="submit">
    <a href="register.php"> Register! </a>
    </form>
   <! -- we can open or define php document tags again below to close the else curly bracket -->
   <?php
   ## this is what I am talking about.
    }
    ?>

If you take a closer look on your form codes, you will probably notice that I took it our of the echo function. Can't talk much about why?, but the idea is to not deal with too many html embedded inside the php. With this method, you can remove the entire form out of this page, and then put it in different page, save it as from.php and then just include it here, but that is out of the scope of this question.

Now, we move on to your simple form validation codes... I hope you will be working on this a little later. Otherwise this type of validation will not thrive in production server. Below is your …

veedeoo 474 Junior Poster Featured Poster

Later on, I will convert the entire script to either Twig or Smarty templating system. Depending on my mood. Twig is easy, so it is more likely to be the candidate. This will provide an additional security, because of the compilation use by smarty.

veedeoo 474 Junior Poster Featured Poster

If you downloaded the file before this post, you must donwload it again. I just made an update..

Update 2 Detail:

  1. Remove the restriction on password, so that the password generator can be use.

Safety issues on password?
1. Since the password is being converted to md5 hash, there will be few chracters or entities can pose harm to the database, the same hashing is used when validating the users password. The original santizing method is still in effect as intended by the original author.

ADDED file:

Here is the access control that will verify if the logded in member is an admin or regular member.

To be recognize by the script as admin, you need to change your privs as 7. The modification defined members privs as 7- admin, 3 - moderator, 1 - regular member. Script validates them as 700, 300, or 100.

veedeoo 474 Junior Poster Featured Poster

Hi,

If you want to use base_64, then you can try

  $item_no = base64_encode (4);
  ## the above gives a this value NA==

Thus, making your url as shown below

 http://www.dev.xxxxxxxxxxxxxxxxxxxxxxxx.com/findanagent_details.php?recordID=<?php echo $item_no;?>

and visible to the browser as

   http://www.dev.xxxxxxxxxxxxxxxxxxxxxxxx.com/findanagent_details.php?recordID=NA== 

we cannot encode this recordID to base 64, unless you want to use pregmatch on the url extracting this part, and then use base64_decode.. for the above code, you extract the encoded integer ...like this

$record_id = base64_decode ($_GET['recordID']);

Record ID should be now back to its original value which is 4.

veedeoo 474 Junior Poster Featured Poster

Hi,

Ok, just to get you going and to eliminate the problem of html tags being posted in the database. I fixed the class.. WARNING! this is a temporary fix.. I will attempt to fix some other vulnerabilities if I find ONE.

Disclaimer! I do not own NOR I wrote this log in system. I am still waiting for the original author to contact me if he has any updates for the script. Otherwise, I will have to make few more fixes, and this script should be consider as safe.

On my fixed file, I added a distinction between regular members and the admin. I also extended it to have a moderator role if needed be.

Later I will talk about this extended method from the original class.

Instructions:

  1. Download the upgraded fg_membersite file Here
  2. Replace the .txt extension with php extension. e.g. fg_membersite.php
  3. Open the include directory and rename the file called fg_membersite.php to something else. This is your backup file.
  4. Upload the downloaded and enamed file from step 1 and 2 to your include directory.
  5. Go to your phpMyAdmin, and then click on the database for your login system.
  6. On the top right corner, look for the sql tab, click on the sql tab.
  7. Place your cursor in the textarea, right click and then choose "select all", hit delete.
  8. Paste the codes below inside the textarea , and click save or go.

    ALTER TABLE member ADD privs INT( 11 ) NOT NULL AFTER name

  9. Now go …

veedeoo 474 Junior Poster Featured Poster

Hi,

I think there is a problem in the validation class of the script. I felt so guilty recommending this script. The earlier version I tested it, but their latest one, I have not do any testing at all. I should have test it first, before extending any recommendation. I need to contact the author of the script and tell him about this bug. He should be active at sourceforge..

I tested the script today and you are right, the html tags are able to scape and get posted in the database under the radar of the validator class.

If you can wait for a few days, I might be able to write you one, or maybe try to fixed the validation class..

I have a login function in my open source application, but it is too huge for me to disassemble for your purpose. Just hold on... I will get back to this thread.

veedeoo 474 Junior Poster Featured Poster

Hi,

Try this,,, this is my test codes from the other threads, and I have to modify it similar to your xml . You can use the code as an example of what you are trying to achieved. There should not be any problem mocking it to your own.

Here we go... simple DOM object with write and then read..

copy and save as books.xml

<?xml version="1.0" standalone="yes"?>
<books>
  <book>
  <author>Jack Herrington</author>
  <title>PHP Hacks</title>
  <publisher>O'Reilly</publisher>
  </book>
  <book>
  <author>Jack Herrington</author>
  <title>Podcasting Hacks</title>
  <publisher>O'Reilly</publisher>
  </book>
  </books>

Copy and save as books.php

<?php
## filename books.php
$xml = "books.xml";
   $doc = new DomDocument;
   $doc->Load($xml);

    $books = $doc->getElementsByTagName('books')->item(0);
    ## we iterate  book block
    $new_BookEntry = $doc ->createElement('book');
    ## items going inside the book block
    $new_AuthorEntry = $doc->createElement('author');
    $new_TitleEntry = $doc ->createElement('title');
    $new_PubEntry = $doc->createElement('publisher');

    ## prepare items to be added in xml file

    $authorNode = $doc ->createTextNode ('New Book');
    $titleNode = $doc ->createTextNode ('New Title');
    $pubNode = $doc->createTextNode ('new publisher');
    ## add new entries 
    $new_AuthorEntry-> appendChild($authorNode);
    $new_TitleEntry-> appendChild($titleNode);
    $new_PubEntry->appendChild($pubNode);

    $new_BookEntry-> appendChild($new_AuthorEntry);
    $new_BookEntry-> appendChild($new_TitleEntry);
    $new_BookEntry->appendChild($new_PubEntry);
    $books -> appendChild($new_BookEntry);

if($doc->save($xml)) echo "Sucess";

## read updated xml file
  ## uncomment codes below if use in different page.
 //$doc = new DOMDocument();
  //$doc->load( $xml );

  $records = $doc->getElementsByTagName( "book" );
  foreach( $records as $record )
  {
  $author = $record->getElementsByTagName( "author" );
  $author = $author->item(0)->nodeValue;

  $publishers = $record->getElementsByTagName( "publisher" );
  $publisher = $publishers->item(0)->nodeValue;

  $titles = $record->getElementsByTagName( "title" );
  $title = $titles->item(0)->nodeValue;

  echo "<p>Title: ".$title."<br/>Author: ".$author."<br/>Publisher: ".$publisher."<br/></p>";
  }

?>

That's should update the books.xml with the new info. …

veedeoo 474 Junior Poster Featured Poster

Hi,

You should go by Ardav's suggestion.. (I mean diafol :) ). That should get the job done, but if want to do some simple xml parsing, then you can try codes below. Not the best one, but can also get the job done ( I hope :))..

Here we go... simple DOM object..

## don't forget to provide the location of the actual xml file.
$xml = "someXml.xml";
$doc = new DOMDocument();
  $doc->load( $xml);
  ## lets read the code block
  $records = $doc->getElementsByTagName( "code" );
  foreach( $records as $record )
  {
  ## parse the zip code
  $zip = $record->getElementsByTagName( "postalcode" );
  $zip = $zip->item(0)->nodeValue;

  ## parse the city
  $city = $record->getElementsByTagName( "name" );
  $city = $city->item(0)->nodeValue;

  ## parse the latitude
  $lat = $record->getElementsByTagName( "lat" );
  $lat = $lat->item(0)->nodeValue;

  ## parse longtitude.
  $longtitude = $record->getElementsByTagname( "lng" );
  $longtitude = $longtitude->item(0)->nodeValue;

  echo "<p>Zip Code: ".$zip."<br/>City: ".$city."<br/>Latitude: ".$lat."<br/>Lontitude:".$longtitude."</p>";
  }

that's pretty much about it...

diafol commented: good example +14
veedeoo 474 Junior Poster Featured Poster

Hi,

Run this script on your local server..

<?php
function showMe($thisY){
        $out = "";
        $out .=header('Content-type: image/png');
        $out .= base64_decode($thisY);

        return $out;
    }
if (isset($_GET['submit'])){
 $thisX = $_GET['imagenv'];
    echo showMe($thisX);


}
else{
 $someX = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAACA0lEQVR4nO3cwUsUYRzG8UdhKa0oEREpCjoUSOlJgiAWIbp26FZQt+iS2CH0ImwGXj2IWiePhnSo6L5/2nQoqFmVRvd93+edfb+f8/B7vzDsLDvzzkoAAAAAAAAAAAAAAAAAAPxrU11tquvOwG8P1VOlnipJHyR9dAeV6rDBMfvRKyBJmjzj8QdRKjC0BXfAqOkEmLERYAYkvQ0466KksYDzinMn0tzxSHMxhNvugLbZSbBGrE8ghjDnDmiDp+4AAANm3QG5emNc+7NxbZzinjsgJ4vuANS9cAf88dwdgONuuQPcrrkDBhR/E3LFHXCCLXcAICnvy4Pzd5FNjperos27A/7jujsAdQ/cASjYd3dAQ8vugFTuugMaeuUOQIFCbIBL4+/G7pH2zh3QWCEn5LE74Ix23QGo++QOQN2qOyCml+6Ac3jtDoijvV+Q6+6AONp7Qr64A2KacgecQ8h3VbJzwR0AAKNrzx2Aupw3YhSn+F2MubnpDkhhwh3Q0CV3QCpt2VpzxR2QypI7oIFtd0BKI30ru41+uANQl/O1Obd3VYp2wx2AnvrqqS/pqjvF7Zs7QFKbH5gFl8P/Vh25A3LzyLRuRzwky8aaOyBrlVRVSnIN/5pgjfaLfEI6kp5Eml2EZwFmTIs7AcG9lzTT8NjLkn5Kuh8vBwAAAAAAAACAJn4Bse83Wq3XeMoAAAAASUVORK5CYII=";
?>
<form id="imagen" method="get" name="imagen" action="#">
    Con Corte - Añadir carro
    <input id="imagenv" name="imagenv" type="hidden" value="<?=$someX?>"/>
    <input type="submit" name="submit" value="submit"/>
    </form>

    <?php
    }

?>

That should show you an image...as output. I removed this part of your code from the hidden input

  data:image/png;base64,

please ignore the expected result I posted on my first PoST, that was from other script I am currently testing.

veedeoo 474 Junior Poster Featured Poster

Hi,

I know it is kind of silly to ask, you probably know it. What do you see if you do this??

        $out = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAACA0lEQVR4nO3cwUsUYRzG8UdhKa0oEREpCjoUSOlJgiAWIbp26FZQt+iS2CH0ImwGXj2IWiePhnSo6L5/2nQoqFmVRvd93+edfb+f8/B7vzDsLDvzzkoAAAAAAAAAAAAAAAAAAPxrU11tquvOwG8P1VOlnipJHyR9dAeV6rDBMfvRKyBJmjzj8QdRKjC0BXfAqOkEmLERYAYkvQ0466KksYDzinMn0tzxSHMxhNvugLbZSbBGrE8ghjDnDmiDp+4AAANm3QG5emNc+7NxbZzinjsgJ4vuANS9cAf88dwdgONuuQPcrrkDBhR/E3LFHXCCLXcAICnvy4Pzd5FNjperos27A/7jujsAdQ/cASjYd3dAQ8vugFTuugMaeuUOQIFCbIBL4+/G7pH2zh3QWCEn5LE74Ix23QGo++QOQN2qOyCml+6Ac3jtDoijvV+Q6+6AONp7Qr64A2KacgecQ8h3VbJzwR0AAKNrzx2Aupw3YhSn+F2MubnpDkhhwh3Q0CV3QCpt2VpzxR2QypI7oIFtd0BKI30ru41+uANQl/O1Obd3VYp2wx2AnvrqqS/pqjvF7Zs7QFKbH5gFl8P/Vh25A3LzyLRuRzwky8aaOyBrlVRVSnIN/5pgjfaLfEI6kp5Eml2EZwFmTIs7AcG9lzTT8NjLkn5Kuh8vBwAAAAAAAACAJn4Bse83Wq3XeMoAAAAASUVORK5CYII');

        echo $out;

That should give you something on the screen... I think :)

UPDATED LATER:

The above should give you something like this

<div id="page" class="shell">
<!-- Logo + Search + Navigation -->
<div id="top">
<div class="cl">&nbsp;</div>
<h1 id="logo"><a href="SITE_URL/lib/skins/lolim/images/logo.gif">MONDAYS</a></h1>
<div class="field-holder">
<br />
veedeoo 474 Junior Poster Featured Poster

Hi,

Can you rewrite your js function so that the only thing left is to call that function. If so, you can do it like my example below. Not a big one, but that's how you make the php call for the output of the js function. unless, you want to wrap the entire js as php variable, then the possiblility is a little bit brighter. However, passing it in the script like your script above will not do it, because PHP is parse on the server side, while js is interacting on the client side.

<?php
echo "hello! I am echoed by php <br/>";
?>

<html>
<head>
<script type="text/javascript">
function displayDate()
{
document.getElementById("out").innerHTML=Date();
}
</script>
</head>
<body>

<p>Javascript ouput delivered by php </p>
<p id="out">Echoed JS function shows here.</p>

<button type="button" onclick="<?php echo 'displayDate()';?>">Clikc Me</button>

</body>
</html> 
veedeoo 474 Junior Poster Featured Poster

Hi,

Here are the samples of ones and zeros take your pick...

   <?php
    $x = false;
    $y = true;
    $z = NULL;
    $a = 0;
    $b = 1;

    ## as dumps
    var_dump($x);
    echo "<br/>";
    var_dump($y);
    echo "<br/>";
    var_dump($z);
    echo "<br/>";

    ## as boolean to integer to reflect 0 as false and NULL,  and 1 as true. NULL and NOT NULL can also be set on your database table.
    echo "x = ".(int)$x."<br/>";
    echo "y = ".(int)$y."<br/>";
    echo "z = ".(int)$z."<br/>";

    ## these two are integers.
    echo "a = ".$a."<br/>";
    echo "b = ".$b."<br/>";

    ## as boolean without the integer intervention. here x and z does not have  VISIBLE output values.
    echo "x = ".$x."<br/>";
    echo "y = ".$y."<br/>";
    echo "z = ".$z."<br/>";

    ## however, condition below confirms that x , z, and $a are  zeros. Please consider this. This is the situation when generous parenthesis matters, or else evaluation will not return plausible response.?????????
    if(($z && $x && $a ) == 0){
       echo "They are false, NULL, and ".$a;
     }
?>

next the form implementation which is pretty easy... I think..

veedeoo 474 Junior Poster Featured Poster

ok.. here is the php.net manual for multiple file uploads Click Here..Read on leehowarth1 post.. or by anyone should and can help you out.

We cannot use $_FILES['this'], because the upload is coming as an array. So, your codes above can be something like this

 $fileNameOne = $_FILES['ufile']['name'][0];
 $fileNameTwo = $_FILES['ufile']['name'][1];

Or better yet, just use one of the recommended approach in php.net as linked above..

I could have written this script.. this is not pretty hard to do, but I am preparing for my flight to California. I need to be in CalTech by Monday. So, I aplogize if I can't do it this time. Normally, I would write a simple demo script, but not this time.

veedeoo 474 Junior Poster Featured Poster

Change this

 $resultlink = "\n\t<li><a href=\"posts.php?ID={$arr['id']}+{$arr['type']}+{$arr['name']}\">{$arr['name']} {$arr['location']}</a></li>";

to this...

 $resultlink = "\n\t<li><a href=\"posts.php?id={$arr['id']}&type={$arr['type']}&name={$arr['name']}&loc={$arr['location']}\">{$arr['name']} {$arr['location']}</a></li>";

and then on your post.php, you can do like this

   $id = $_GET['id'];
   $location = $_GET['location'];

   ## do the same for others then echo them the way you want it to be showing on the browser.
veedeoo 474 Junior Poster Featured Poster

Hi,

the name on these form inputs...

     <input name="image1" type="file" id="ufile[]" size="50" />

should also be in an array like this

     <input name="ufile[]" type="file" id="ufile[]" size="50" />

UPDATE! I have to remove some codes, because it was deprecated...just use $_FILES..

veedeoo 474 Junior Poster Featured Poster

Hi,

This is just a humble suggestion.. I didn't really read your codes in its entirety, but I could see lots of improvements in the nested while loops area. You can try improving it by using mysql join. By using join, you might be able to get rid some of the while loops.

In my previous expermental application, I used singleton database connector class as shown ,,, Here. This can help a lot on the database function of your script, and this can serve as the CRUD on your application.

There is nothing wrong with nested while loops if there is no other way of avoiding it. So, don't force it, if it cannot be done with effeciency.

veedeoo 474 Junior Poster Featured Poster

Hi,

Try putting your <table> tags, before the foreach loop as in.. ( Reminder: I am just following your coding style, which I always do most of the time, when posting response, but in my own projects I must use smarty or twig, because I really hate mixing php and html codes in one page..)

        <table>
        <!-- you can use header cells instead -->
        <tr><th>Col Title 1</th><th>Col Title 2 </th> <th><!-- put the rest here --></th></tr>
        <?php
        foreach($those as $this){

        ## begin distributing your data in their own row and td
        ?>
        <tr>
        <td><?php echo $this['item1'];?></td><td><?php echo $this['item2'];?></td><td><!-- add more as needed by your requirements --></td>
        </tr>
        <!-- watch out! below is the end of the loop -->

        <?php

        }
        ## end of foreach loop
        ?>

        </table>

I thought this project was based on symfony.. Didn't symfony already have its own twig templating system in it?

veedeoo 474 Junior Poster Featured Poster

Hi,

Try changing this

 $query = "SELECT type, name, location, landmark FROM table1";

to this

$query = "SELECT id, type, name, location, landmark FROM table1";

reason? because you have id in here..

 $resultlink = "\n\t<li><a href=\"posts.php?ID={$arr['id']}+{$arr['type']}+{$arr['name']}\">{$arr['name']} {$arr['location']}</a></li>";
  $end_result .= '<li>' . $resultlink . '</li>';

and then add this on top of the while loop.. do not include inside the while loop..

 $end_result = "";

one last thing, remove your error suppressor in

 @mysql_query($query);

remove the suppressor @ for now, or until you are sure your script working properly.. some books talks about how to suppress errors, but this is not the environment to suppress them..we want errors to appear as much as possible while in developement. use this instead..

  mysql_query($query);