Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 9th, 2012, 01:18 PM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2011
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default a few questions

I have reached to chapter 8 in the book with a few small questions I have.

1) the $_POST array- does it delete itself after the script on the page is executed? (I have been thinking that if i have 2 different forms in my site both share some fields in common and in one point I filled in one of the forms and after a of bit of browsing fill in the second form. will the second form processing script will use the first form input?)

2) I noticed as the book progresses the explanations are becoming less detailed (which is understandable on certain parts of the script that uses familiar code)
and some of the code is left unexplained (or not explained enough). this includes the code
Code:
header (‘content-type: image/jpeg)
(what does it do? can I use the same concept for other file types?) and the imagecreatetruecolor() and imagecopyresample() functions (the last two where explained about what they do but not how to use them or their arguments ) in chapter 7. also the join() function that is (used in chapter 8 page 224) is not explained. this function I actually searched and found in the php documentation and in this place: http://www.w3schools.com/php/func_string_join.asp
and it seems you mixed between the two arguments of the function.

3) I saw many times in the book that when you make an insert query you place the query into a $result variable. I wanted to know if I have to that or I can just make the query

example:
Code:
 $query = ‘INSERT INTO images (image_caption, image_username, image_data) VALUES (“yadi”, “yadi”, “yada”)’;

// insted of $result = ..
$result = mysql_query($query, $db) or die(mysql_error($db);

// just simply .
mysql_query($query, $db) or die(mysql_error($db);
4) I don't know if you will cover this later in the book (I am right now in chapter 8) but how do I deal with empty fields in the data base or a query that returns nothing?
Reply With Quote
  #2 (permalink)  
Old February 10th, 2012, 04:58 PM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default I dont know php! because of air conditions!!! 1st question's answer

Hi my friend!
the $_POST array refers to values that are submited to current page. so it would be destroyed after page execution.

Code:
<form name='myForm' action='destination.php' method='post'>
   firstname: <input type='text' name='firstname' /><br/>
   lastname: <input type='text' name='lastname' /><br/>
   <input type='hidden' name='someHidden' value='someValue' />
   
   <input type='submit' name='submit' value='submit the form' />
</form>
destination.php
Code:
if(isset($_POST["submit"])){
     $firstname = $_POST["firstname"];
     // ...
}
=================
you can also use combination of GET and POST methods:
Code:
<form name='myForm' action='destination.php?p=add' method='post'>
   firstname: <input type='text' name='firstname' /><br/>
   lastname: <input type='text' name='lastname' /><br/>
   <input type='hidden' name='someHidden' value='someValue' />
   
   <input type='submit' name='submit' value='submit the form' />
</form>
destination.php
Code:
$p = $_REQUEST["p"];
switch($p){
  case "add":
     $firstname = $_POST["firstname"];
     // ...
     // write insert statements here ...
     break;
   
  case "edit":
     $id = $_POST["id"]; // id may be a hidden field
     $firstname = $_POST["firstname"];
     // write update statements here ...
     break;
}
Reply With Quote
  #3 (permalink)  
Old February 10th, 2012, 05:25 PM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default 2nd question's answer

Hi again.
this question should be detailed:
Code:
vardump($question); //!!!!!!
about 'content-type':
when a page is rendered, it should be returned to the user (browser). there are two types of data sent to browser: 1: headers, 2: content
header can contain some fields, such as 'content-type', cookie data, etc. header's data is processed by the browser. by default php sends 'content-type: text/html' header to the browser. if you use:
Code:
header ('content-type: text/plain');
the content of your page would not be processed as html, but plain text.
some times you need to send a special type of file to the browser (for download or other purposes); then you can use 'content-type: <mime-type>' header.
common used mime-types are :
* text/html
* text/plain
* image/jpeg
* application/octet-stream // can be widely used
* application/pdf

you can find a list of available mime-types in http://www.webmaster-toolkit.com/mime-types.shtml

I don't know php so I can't help about imagecreatetruecolor() and imagecopyresample() functions.

Last edited by irProject; February 10th, 2012 at 05:29 PM.
Reply With Quote
  #4 (permalink)  
Old February 10th, 2012, 05:43 PM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default 3rd question's answer

There are simply four Data-Manipulation commands in Database Systems: SELECT, INSERT, UPDATE, DELETE

SELECT command returns a result set.
INSERT, UPDATE and DELETE commands return number of affected rows.

in many cases, the result of INSERT command may be ignored. so you can ignore the result by writing:
Code:
mysql_query($query, $db) or die(mysql_error($db);
or use result (maybe for 'multiple rows insertion') by writing:
Code:
$result = mysql_query($query, $db) or die(mysql_error($db);
in php (and common languages) you can avoid storing returned result of a function

$result = someFunction($a, $b);
or
someFunction($a, $b);
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET Interview Questions, C# Interview Questions, dotnetuncle .NET Framework 2.0 2 April 30th, 2013 06:57 AM
questions ks1102 Excel VBA 1 April 9th, 2009 11:13 AM
C++ questions jam93 C++ Programming 1 August 19th, 2007 10:39 PM
two questions reverand Excel VBA 2 December 5th, 2005 05:33 AM
questions anshul Javascript How-To 1 April 12th, 2004 07:29 AM



All times are GMT -4. The time now is 09:42 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.