lesser-equity

Magazine
Go Back   Computer Juice > Computer Software > Web Design, Hosting & SEO


Register


Reply
 
Thread Tools
  #11  
Old 2nd Apr 2008, 13:41
Donor Group
 
alright. And you have a valid mysql database that I can't see too.

The attachment is what I'm trying to get at. I did that with partly php and partly html and the result of the two is the same when the browser sees it because the php has executed and written the html out.

Here's the View Source which shows that there's no php left by the time your browser sees the code...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit Item</title>
<form id="form1" name="form1" method="post" action="EditItem.php">
<select name="itemid">
<option value=Milk>2 litre semi-skimmed Johnson Farms</option>
<option value=Eggs>2 litre eggs Johnson Farms</option><option value=Chickenbones>2 litre salmon Johnson Farms</option><option value=Milk>2 litre chickenbones Johnson Farms</option><option value=Eggs>2 litre semi-skimmed Johnson Farms</option><option value=Chickenbones>2 litre semi-skimmed Johnson Farms</option></select>
<p align='center'><input type="submit" value="Edit item"></p><p>
</form>
<form id=form2 name=form2 method=post action=EditItem.php>
<label>Item Description
<input type=text name=itemdescription value=Milk>
</label>
<p>
<label>Quantity In Stock
<input type=text name=quantityinstock value=214>
</label>
</p>
<p>
<label>Round Up Total
<input type=text name=rounduptotal value=300>
</label>
</p>
<p>
<label>Batch Price
<input type=text name=batchprice value=0.83>
</label>
</p>
<p>
<label>Supplier Name
<input type=text name=suppliername value='Johnson Farms'>
</label>
</p>
</form>
</body>
</html>



I added the missing </head> and <body>, I changed all the <? to <?php and I sort of bodged the other code because I don't have the database to work from.

Mostly you've got the right stuff there but it's not going to be easy to tell if you can't view the source you're writing, that's just flying blind in a snowstorm.

Which browser are you looking at localhost with?
Attached Thumbnails
PHP mysql, creating a drop down list that takes fields from table in mysql-php1.jpg  
__________________

My System: Tim

Processor(s):
Athlon 64 3500+
Motherboard:
Asus A8N-VM CSM
RAM Memory:
Corsair PC3200 CL2 DDR-400 2GB
Graphics Card(s):
nVidia Geforce 6600 512MB
Sound Card:
Cherry RS 6000 M keyboard
Hard Drive(s):
Barracuda.7+ 2x200GB 58MB/s sustain
Optical Drive(s):
Samsung DVD-ROM TS-H352
Case / PSU:
Thermaltake Soprano
Cooling:
Stock
Network / Internet:
Telewest 2x20Mb/sec
Monitor(s):
SXGA flat panel
Operating System(s):
Slackware (2.6.27.7) (Fluxbox)
  #12  
Old 3rd Apr 2008, 05:06
Member Group
 
IE
  #13  
Old 3rd Apr 2008, 05:23
Donor Group
 
If you read http://www.mredkj.com/tutorials/tips_ie.html can you get view source to work? If you can't see the html output by the php then I'm not sure how you're expected to be able to get the code correct.

I'm not sure whether you've grasped the point that the webserver reads the php but it doesn't send it on to the client browser. The client browser doesn't understand php at all. If you see any php code in your browser it means it's not been consumed by the webserver because it's not valid php, so the pre-processor ignores it and the browser ends up thinking it's just text I expect.

Tell me if there's anything I can help you with, I've lost touch with what it is you'd like to achieve in this thread. I've re-read it and I understand why I've said what I wrote but if it's not made any sense to you then I'm the wrong person to ask.
  #14  
Old 3rd Apr 2008, 05:56
Member Group
 
Ok, thanks for attempting but i still have no idea what i'm doing.
Failing.
  #15  
Old 3rd Apr 2008, 07:33
Donor Group
 
I'l try to unravel the levels, I hope it helps a bit.

You installed Apache, php and mysql. You wrote some code in Dreamweaver and saved it as X.php and then you used Internet Explorer to browse to localhost/X.php - I think we both agree so far.

I want to show you something. Run your notepad and copy this into it:
Code:
<html><head><title>example header</title></head>
<?php
echo '<body><h1>This is your browser details</h1></body></html>';
echo '<p>You are reading this with '.$_SERVER['HTTP_USER_AGENT'].'</p>';
?> 
</body></html>
Now save that as c:\xampp\htdocs\cj.php

Browse to localhost/cj.php and see what it did. Apache has read cj.php. The .php file type tells Apache to pass the content to your php package. Your php package has run the code between the <?php and the ?> tags and so long as the code was valid it's all been taken out. The code had echo (which is nearly the same as print) which wrote some valid html into the place the code ws removed from. Then the php package has handed the output back to Apache which has sent it to your browser.

You've used php to create html code. That's all it's done. The html code that it's written has to be valid and it's no different to what you'd have written without php if you'd had no php in there. In the browser, View Source and look at the html the browser was given, it says (on my computer)
Code:
<html><head><title>example header</title></head>
<body><h1>This is your browser details</h1></body></html><p>You are reading this with Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12</p> 
</body></html>
That's not what you saved to disk from notepad. That's what the php system created for you.

Now, for your database accesses you've written some php code which might or might not work. The same thing's going to happen. Apache will read your .php file and pass it to the php system. What it gets back (if you had clean syntax!) is just html and nothing else. It will have unit price as "£0.43" and description as "pepsin 125ml sachet" instead of the field names you originally coded. That's what will go to your browser. The browser will see no php code at all, with any luck.

To build this system, it's far easier to take a step at a time, to first write a html file which is valid html and looks the way this final version is going to look. You have to check that it's good html, you test it somehow. That becomes the good example of the html file you want your php code to generate for you. That's very like the code I showed you in post#11.

Then you take out all the "£0.43" and "pepsin 125ml sachet" place holders and replace them with your database field names with enough php code to get the values out of the database. That's quite close to the code you showed in post#5. You have to write the post#11 code first and test that before you can try to write the post#5 code because it's too much to handle in one leap, writing the entire page clean in one stage. When you finish changing the example code into the proper production code with all the php database open and reads in it you're just testing your php code and you have a target to aim for - making the browser see the same as you started with when you wrote your example and tested it. That's why being able to View Source matters so much, so you can compare the output html code with your target html code. I don't know another way of seeing it to know what it says.

Yes there are people in the world that can write the entire thing in one single step and manage to test it so it's clean and works. That's what the experts do. I prefer to remember the "keep it simple" lesson and take it in stages.

Read that and tell me what's not making sense.
  #16  
Old 4th Apr 2008, 06:49
Member Group
 
Right, sort of got somewhere today.
I have a simple update ..form thing but was wondering how do i do a delete query(? i think..), where the user can choose an item from a drop down and delete it. I thought i could just use the update query and change the update parts to delete but there is no delete type buttons.

Asked one of the guys in my class what his was like and he only had a few lines. Have googled but don't understand.
I want to be able to delete specific items from the items table.
  #17  
Old 4th Apr 2008, 07:57
Donor Group
 
You currently have "edit item". Make a copy of what you're doing there and label it "delete item". You had the item you wanted editing, now it's the item you want deleting.

You have code which currently does the edit. Make a copy of that and label it delete.

mysql_query("DELETE FROM tab-x WHERE item=".$item) or die(mysql_error());

(those mysql_error bits you took out need to be there really, else you'll have a database error and the code will just carry on regardless. You need to catch it when you're testing so you can make it work robustly and then the mysql_error won't ever happen in real life).

I expect I've misunderstood what you were asking. What have I assumed that's not true?

I know what I don't understand though - "but there is no delete type buttons" - you must be using a bit of software to generate your mysql syntax and I don't know what software it is. It might be a part of Dreamweaver. All I have here is a text editor with no delete type buttons so I can see why we have trouble getting ideas across.
  #18  
Old 4th Apr 2008, 08:09
Donor Group
 
This sounds exactly like the coursework that I failed this time last year! Not in the same course as me are you?! I found www.w3schools.com to be a great help. You seem to have lucked out with getting the help from Spot, Im sure you will have a working site up and running before hand in date! Good luck
__________________
Last night I lay in bed looking up at the stars in the sky and I thought to myself, where the heck is the ceiling.
What if everything is an illusion and nothing exists? In that case, I definitely overpaid for my carpet.
  #19  
Old 5th Apr 2008, 03:13
Member Group
 
Still confused about delete, what do i need to take out of edit?


I meant the Insert>Form>Button in Dreamweaver, how there is submit and hidden etc.
  #20  
Old 5th Apr 2008, 07:25
Donor Group
 
The thing is, I've never used Dreamweaver.

What I think is that using what's effectively a program generator like Dreamweaver gives you another entire level to learn, except that some people (I'm talking generally, I'm not putting you Samantha into the picture), some people can use the generator without learning to read or write what it generates.

It's quite possible that Dreamweaver is good enough at generating systems that the Dreamweaver user doesn't need to know how to read or write mysql statements, or php syntax, or html tags. If that's so then a "learn to use Dreamweaver" course will let someone generate a site from scratch without knowing any mysql statements, or php syntax, or html tags and it could well be a quick way to become competent at writing a website.

If Dreamweaver doesn't actually do all the work, and a person does need to also know how to write and read mysql statements and php syntax and html tags, then learning Dreamweaver on top of learning mysql statements and php syntax and html tags seems a bit of an overhead to me.

Anyway, that's why if I were teaching someone to program I'd not hand them Dreamweaver at all. If, on the other hand, I were teaching a Dreamweaver course then I would. If I were teaching a "create your own website" then I might or I might not. For teaching programming it looks to me like it gets in the way.

Where I said 'You currently have "edit item"' I was talking about the command button on your html which is labelled "edit item", not any instruction in Dreamweaver. I was suggesting that a copy of the html code which makes that command button could be relabelled "delete item" and the mysql statement in my post would do the job if it were in the POST page that the command button called.

That's how I program most of the time, taking bits I've already written and tested and copying them and changing the copy to do something similar but not identical. Actually sitting down and writing totally fresh code is exciting but time-consuming. Re-using stuff known to work speeds up the process. I don't much like copying code from someone else into my own source because I have a lot of tinkering to put it into my own style where I'll feel comfortable, and it would take a while to get all the variable naming convention to match the rest of my program, but I'd still sometimes do that rather than write from nothing. The code that other people have written that I do, always, rely on is the stuff I call as routines through an API. I'm an application programmer calling up huge existing functions through whatever Application Programming Interfaces are available to me. I write 1% of what's going to actually run, my code's like a skim of jam on a thick slice of buttered toast. The 99% complexity of what the computer actually performs is already fully tested and working, my 1% is the new stuff I'm trying to get right which carries the actual design of the new system I'm implementing. That mysql_query line is an API call to someone else's code which is far more complex internally than anything I'm writing and millions of other programmers are also, like me, relying on mysql_query working faultlessly. We're all writing different screen applications though.

So - is there anyone on site who's good at using Dreamweaver who can cut in and say what to do?

I can see why you said earlier that the bits I've written about html and php are "nothing like what we've been 'taught' to do" if you've been taught how to make a website using Dreamweaver and nobody's covered html or php.

I hope I've not held you back or slowed you down in completing this bit of your course.
Reply

Register
Thread Tools




Arabic Bulgarian Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Finnish French German Greek Hebrew Hungarian Italian Japanese Korean Latvian Lithuanian Norwegian Polish Portuguese Romanian Russian Serbian Slovak Spanish Swedish Thai Turkish Ukrainian

Copyright ©2006 - 2009 Computer Juice.

Powered by vBulletin® Copyright ©2000 - 2009 Jelsoft Enterprises Ltd. SEO by vBSEO ©2009, Crawlability, Inc.