G
GaryAC

  • Mar 30, 2004
  • Joined Dec 15, 2003
  • Cheers for your replies. It all works now!!!

    • I already have a DTD created. This is the XML code I would like to write to an XML file:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE catalogue SYSTEM "M:\Final_Year\Web Applications Technologies\order.dtd">
      <catalogue>
      <order id="1">
      <dvdid>3</dvdid>
      <qty>20</qty>
      </order>
      <order id="2">
      <dvdid>1</dvdid>
      <qty>20</qty>
      </order>
      </catalogue>

      However instead of hard coding id 1, dvdid 3, qty 20 for example, these will be values derived from PHP variables.

      Can you write PHP variable values to text files ok??

      Thanks for your help its much appreciated

      • Thanks for your replies.

        Basically what I need to do is simulate a basic stock control system that generates orders in XML format for a DVD shop.

        What I have at current is a page with a button, that when pressed checks a MySQL db to see if orders need to be generated i.e. stock is low.

        If it is I need to generate a vary basic order form in XML that stores the ID and the number required for each DVD.

        Once created this file does not need to be updated or changed. Just overwritten if new orders are to be generated.

        Would it be a case of using fwrite?

        • Hi,

          I need to create an XML file from PHP, but I haven't got a clue how to do it. Not sure if printf statements are suffice??

          So I was hoping someone could explain to me how to wite XML into a file from PHP.

          My scenario is I have a DVD shop, and I wish to make re-orders. I gather all the DVDs that have gone below the Stock level and then create an XML file containing each DVD_ID and the QTY.

          Thanks for any help, it would be much appreciated

          Regards

          GaryAC

          • May well be the case.

            Cheers for your help.

            • Hi,

              I am trying to make all my pages XHMTL 1.0 Transitional. However I am getting a weird error with the <legend> tag align attribute.

              I am aligning some text in the center by using:

              <legend align="center"><span class="chen"><strong>New Member:</strong></span></legend>

              Which works, however when I validate it using the W3C mark up validation service it comes up eith the error:

              Line 22, column 25: value of attribute "align" cannot be "center"; must be one of "top", "bottom", "left", "right" (explain...).

              So its saying align must be "top", "bottom", "left", "right".

              But everywhere I have researched it states that you can align using center, which you obviously can beccause it works when I use it.
              However I want my pages to be XHTML Transitional!!!

              Is this an error in W3C's validation service???

              Any help would be much apprecited.

              • No worries, I am now using

                $HTTP_SERVER_VARS['HTTP_REFERER']

                This enables me to cross reference variable values from other pages.

                Cheers for the tip

                • Hi,

                  What I am trying to do here is create a login page. The user can either login as a past user , or become a new member. So far all I have cattered for is becoming a new member each time someone accesses my page, so this works fine.

                  However it would be better if someone could enter their password etc. and have that run a check on the db to see if it is correct.

                  At the moment I have 2 pages that deal with new members.

                  1. Details:
                    User manually enters contact details etc.

                  2. Verifies and adds user to db.

                  I want to create a third page that only aks for the name and password, but then retreives all of this users other info from the db.Which I know can be done using queries!!!
                  Then Skipping out the first page and going straight to the 2nd page above.

                  However I am not sure how to pass PHP variables from one PHP page to another??

                  I hope that all made sense.
                  Thanks for any help!!

                  • Well my goals and reasons are that, I am creating a web page that displays a list of dvd's from a db. With the text I wanted to put a front cover picture of the DVD, a bit like Amazon for example...

                    So in theory I could have hundreds of DVD titles, all which have a picture image that goes with it. I thought about storing these images in a db, and just querying them from the table like I do with the DVD titles. However it seems that it would be easier just to save the images on the server, and reference them by their file name.

                    Still can't see why the images are not being displayed. Must have something to do withhow the binary data was saved maybe??

                    • Hi,

                      The problem I am having is that I cannot retreive pictures I have put into my MySQL db.

                      I can upload pictures to my db, but I cannot retrive them to view them on a page.

                      At the moment I have 4 pages.

                      1. up.html:

                      <?xml version="1.0" encoding="UTF-8"?>
                      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
                      <html xmlns="http://www.w3.org/1999/xhtml" lang="en-UK">
                      <head>
                      <title>WAT PHP Lecture Notes - Image Upload to MySQL</title>
                      <meta http-equiv="Expires" content="Tue, 10 Sep 2002 00:00:00 GMT"/>
                      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                      <meta name="Author" content=""/>
                      </head>
                      <body>
                      <form action="upload.php" method="post" enctype="multipart/form-data">
                      <p>
                      Your name: <input type="text" name="username" /><br />
                      Small image to upload: <input type="file" size="40" name="userfile" /><br />
                      <input type="submit" value="Upload file" />
                      </p></form>

                      </body></html>

                      1. upload.php

                      <body>
                      <h1>Uploading Images to MySQL</h1><p>
                      You submitted this file:<br /><br />
                      Temporary name: <?php echo $FILES[userfile][tmp_name] ?><br />
                      Original name: <?php echo $
                      FILES[userfile][name] ?><br />
                      Size: <?php echo $FILES[userfile][size] ?> bytes<br />
                      Type: <?php echo $
                      FILES[userfile][type] ?></p>

                      <?php
                      //require file that states the values for the db connection, i.e. Password etc. Makes them secure
                      require '/home/involve/my.private';
                      function prntErr($errMesg) {
                      printf("<p><strong> %s </strong></p>\n", $errMesg);
                      }
                      if ( !ereg( "gif|png|x-png|jpeg", $FILES[userfile][type]) ) {
                      prntErr("Sorry only browser compatible images allowed");
                      } else if ( strlen($username) < 3 ) {
                      prntErr("Sorry username too short<br />min 3 characters");
                      } else if ( $
                      FILES[userfile][size] > 5096 ) {
                      prntErr("Sorry file too large");
                      } else if ( !($link=mysql_connect($host, $user, $passwd)) ) {
                      prntErr("Error connecting to database");
                      } else if ( !(mysql_select_db($dbName)) ) {
                      prntErr("Error selecting database");
                      } else if ( !($handle = fopen ($FILES[userfile][tmp_name], "r")) ) {
                      prntErr("Error opening temp file");
                      } else if ( !($image = fread ($handle, filesize($
                      FILES[userfile][tmp_name]))) ) {
                      prntErr("Error reading temp file");
                      } else {
                      $ext = explode('.', $userfile_name);
                      $filename = $username . '.' . $ext[count($ext)-1];
                      fclose ($handle);
                      $image = mysql_escape_string($image);
                      //Insert image selected into db
                      $query = "INSERT INTO hero (file,img) VALUES ('$filename','$image')";
                      if ( !(mysql_query($query,$link)) ) {
                      prntErr("Error writing image to database");
                      prntErr(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
                      } else {
                      prntErr("Image successfully copied to database") ;
                      }
                      }
                      ?>
                      </body>

                      These two pages work as when I look in my db table it has entered in the new file id and name, and alot of gobbledigook, which is obviously the image being stored.

                      However my next 2 pages are supposed to retreive all my images and print them out to the screen. However all I get is a blank image with the red cross, and the gobbledigook from the table.

                      3.ImageShow.php

                      <title>WAT PHP Lecture Notes - Image Download from MySQL</title>
                      <meta http-equiv="Expires" content="Tue, 10 Sep 2002 00:00:00 GMT"/>
                      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                      <meta name="Author" content=""/>
                      </head>
                      <body>
                      <h1>Images Stored in MySQL</h1>
                      <snip>
                      <?php
                      //require file that states the values for the db connection, i.e. Password etc. Makes them secure
                      require '/home/involve/my.private';
                      function prntErr($errMesg) {
                      printf("<p><strong> %s </strong></p>\n", $errMesg);
                      }
                      if ( !($link=mysql_connect($host, $user, $passwd)) ) {
                      prntErr("Error connecting to database");
                      } else if ( !(mysql_select_db($dbName)) ) {
                      prntErr("Error selecting database");
                      } else {
                      $query = "SELECT img FROM hero ORDER BY file";
                      if ( !($result = mysql_query($query,$link)) ) {
                      prntErr("Error reading database");
                      prntErr(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
                      } else {
                      for ( $i = 0 ; $i < mysql_num_rows($result) ; $i++ ) {
                      $row = mysql_fetch_row($result);
                      echo "<img src=\"getImage.php?file=$row[0]\" alt=\"$row[0]\"/> \n";
                      }
                      }
                      }
                      ?>
                      </snip>

                      </body></html>

                      1. getImage.php

                      <?php
                      //require file that states the values for the db connection, i.e. Password etc. Makes them secure
                      require '/home/involve/my.private';
                      $link = mysql_connect($host, $user, $passwd);
                      mysql_select_db($dbName);
                      $query = "SELECT img FROM hero WHERE file='$GET[file]'";
                      $result = mysql_query($query,$link);
                      $row = mysql_fetch_row($result);
                      $ext = explode('.', $
                      GET[file]);
                      $type = $ext[count($ext)-1];
                      if ( $type == 'gif' )
                      header("Content-Type: image/gif");
                      else if ( $type == 'jpg' )
                      header("Content-Type: image/jpeg");
                      else if ( $type == 'jpeg' )
                      header("Content-Type: image/jpeg");
                      else if ( $type == 'png' )
                      header("Content-Type: image/png");
                      echo $row[0];
                      ?>

                      I can't see why it won't display the images!!!

                      Sorry there's alot of code, but thought it would be better to post it all, so you can see what I have already done!!

                      Thanks for any help!!

                      • Nice one, didn't realise it was as easy as that.

                        All works fine,

                        Reg

                        Gary

                        • I have a PHP page that updates a db with the customers name, address email address etc.

                          Then their order is processed. Once this is done I want to send them an automaited email, to the email address provided by them.

                          Can anyone tell me how this is done please??

                          Thanks

                          Reg

                          Gary

                          • Sorry people, a school boy error. Must be getting tired, must fill up on coffee.

                            I missed out:

                            mysql_fetch_array()

                            Silly me!!!

                            • I have done plenty of query's through out my php code but for some reason I can't obtain a certain value from a table.

                              I am creating orders for dvd's, therefore I am inserting data into the order tables etc. However once my orders have been made I need to update my dvd table with new stock levels.

                              So I wanted to run a query simply to store the stock level of a certain dvd into a variable. However for some reason, it will not retreive the stock level.

                              Here is the code I am using:

                              //Obtain id from previous query
                              $custid = mysql_insert_id();

                              echo "Customer id is " . $custid;

                                $query2 = "INSERT INTO custord (custid, ortime, numdvd, carriage, orvalue)" .
                              "VALUES ('$custid', now() , '$NoDVD', '$Tx', '$Total')";
                              
                                if ( !mysql_query($query2,$db) ) {
                                   printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
                                } else {
                                   echo ("Thank you for completing the registration form $Name <br /><br />\n");
                                }
                              
                                //Obtain orderid of last entry(the one above)
                                $orderid = mysql_insert_id();  
                                echo "Order id is " . $orderid; 
                              
                                for($i=0; $i<$NoDVD; $i++){
                              
                              $query[$i] = "INSERT INTO orderline (orderid, dvdid, qty)" .
                              	"VALUES ('$orderid', '$DVDID[$i]', '1' )";
                              
                              	if ( !mysql_query($query[$i],$db) ) {
                              		printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
                              	} else {
                              		echo ("Entered DVD $DVDID[$i] <br /><br />\n");
                              	}
                              
                                //Here I am trying to retreive the dvd stock level!!!

                              //$DVDID is set else where, has correct info tho.
                              //Update DVD Stock Level

                              	$check = "select stock from dvd where dvdid = '$DVDID[$i]'";
                              
                              	$result = mysql_query($check,$db);
                              
                              	$st = $result["stock"];
                              
                              	echo "Current stock level is " . $st;
                              
                              	echo "<br />";
                              
                              	$st = $st - 1;
                              	echo "New Stock level is " . $st;
                              
                              	echo "<br />";
                              
                              	$update = "update dvd Set stock ='$st' where dvdid='$DVDID[$i]'";
                              
                              	if ( !mysql_query($update,$db) ) {
                              		printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
                              	} else {
                              		echo ("Updated DVD $DVDID[$i] stock level <br /><br />\n");
                              	}
                                }
                              
                              
                                mysql_close($db);

                              }
                              exit('</head><body></body></html>');

                              Seems as though it should work to me.

                              Thanks for any help

                              Reg

                              Gary

                              • Hi,

                                I have a problem with searching for strings within strings. What I have is a session variable called $basketContents.

                                Now every time a new item is selected it is in this format:

                                ID,Title,QTY,Price:

                                e.g.

                                1,Matrix,1,20.99:

                                Then when another item is selected it is added to the end of this string.

                                e.g.

                                1,Matrix,1,20.99:4,Meet The Parents,1,16.99:

                                So I know that the sysmbol ":", differenciates each item.

                                Only problem is if an item is selected for a second time, then instead of re-entering it into the session string it would be better to change the QTY to 2.

                                So I have been trying to use:

                                $qty = substr_count($ckBasketContents, $basketContents);

                                Where $ckBasketContents is the item selected and $basketContents is the session variable containing all my items.

                                However this does not seem to be working as if I use this code:

                                $qty = substr_count($ckBasketContents, $basketContents);
                                if ($qty>1){
                                echo "Found more than once";
                                }else{
                                echo "Only occurs once";
                                }

                                And add two instances of the same title, it does not bring back a value greater than 1. So it is obviously not recognising that the string $basketContents contains two instances of a particular string (in this case a title name, e.g. Matrix).

                                Can anyone tell me how I can check to see if there is more than one instance within my session string.

                                Thanks for any help

                                Regards

                                Gary

                                • Figured it out. I am using now() in my insert statement. Which displays todays date and time. Perfect.

                                  Thanks for the help.

                                  • Ok, but for some reason I can't find out how to obtain the current date and time using any of the time functions in PHP.

                                    Have you any examples I could look at??

                                    Thanks for your help

                                    Reg

                                    Gary

                                    • You are a diamond!!!!!

                                      Thanks alot, it works now, and mysql_insert_id() function is pretty handy hey!!!

                                      Cheers I aprreciate your help

                                      regards

                                      Gary

                                      • I may be making a silly mistake, but I've been looking at it for ages and i cannot figure out what it is. So i was wondering if anyone can help!!! Please...

                                        I have some data stored in PHP variables that are used to insert data to a mySQL db.

                                        I have a customer table which automatically generates a custid number. So when I enter a new customer it is automatically given an id.

                                        Now I need this custid, to be able to insert it into the next table. However for some reason when I query the customer table to obtain this custid, it returns nothing.

                                        Here is my code:

                                        if ( $referer[0] == URLLIST && $yesButton == 'Yes' ) {
                                        if ( !($db = mysql_connect($host, $user, $passwd)) ) {
                                        printError(sprintf("Error connecting to database from %s, by user %s", $host, $user));
                                        } else {
                                        mysql_select_db($dbName, $db);

                                          $query1 = "INSERT INTO customer (Name, addr1, addr2, addr3, postcode, email, passwd, cardnum, expiry)" .

                                        "VALUES('$Name', '$Add_1', '$Add_2', '$Add_3', '$P_code', '$Email', '$pword', '$Card', '$expiry')";

                                          if ( !mysql_query($query1,$db) ) {
                                             printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
                                          } else {
                                             echo ("Thank you for completing the registration form $Name <br /><br />\n");
                                          }

                                        //Now I want to find the custid that has been generated to put in the next table

                                        //Query to find custid
                                          $find = "select custid from customer where Name = $Name";
                                          $answer = mysql_query($find,$db);

                                        //Put custid into PHP variable $custid
                                        $custid = $answer["custid"];
                                        echo "Customer id is " . $custid;

                                          $query2 = "INSERT INTO custord (custid, ortime, numdvd, carriage, orvalue)" .
                                        			"VALUES ('$custid', '', '$NoDVD', '$Tx', '$Total')";
                                        
                                          if ( !mysql_query($query2,$db) ) {
                                             printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
                                          } else {
                                             echo ("Thank you for making an order $Name <br /><br />\n");
                                          }
                                          mysql_close($db);

                                        }
                                        exit('</head><body></body></html>');
                                        }

                                        I can't figure out why $custid is empty!!!!!
                                        Any solutions??

                                        Thanks for your help

                                        Reg

                                        Gary