Page 1 of 2

Newbie lost and out of my depth

Posted: Wed Apr 20, 2011 11:38 pm
by dbarron87
Hello all and thanks for looking, thanks for your help in advance i am complete newbie trying to learn from a script i have received.

The problem is i am selecting a shipping type (being royal mail, dhl ect) however it is not showing up on the following page

auction site > select shipping type > auction view
I can use the drop down on the shipping type option (being shippingdetail.php) however i am not seeing the result on the advert page (detail.php)

I have attached some code below to see if any one can see what is wrong.

I have done alot of reading however it has not made much sense ( due to serious health problems and lack of sleep)

All help would be appreciated,
i would like the current code to work purely because it will save me all the coding to try and get it to work after if i was to change the type of form

This Is From the shipping page (shippingdetail.php)

Code: Select all

?>
<? if(!empty($err_serivce))
{
?>
<tr><td></td>
<td><a href="ship_detail.php#txtservice">Services</a> - <?= $err_service; ?></td></tr>
<?
}
...
<font size=2>Choose Postage Service</font></b>
<?
}
?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="chkservice">
<option value="">Select</option>
<?
$ser_sql="select * from postage_service";
$ser_res=mysql_query($ser_sql);
while($service_row=mysql_fetch_array($ser_res))
{
if($service_row['service_name']==$service)
{
?>
<option value="<?= $service_row['service_name'] ?>" selected><?= ucwords($service_row['service_name']) ?></option>
<?
}
else
{
?>
<option value="<?= $service_row['service_name'] ?>"><?= ucwords($service_row['service_name'])?></option>
<?
}
}
?>
</select></td></tr>
<tr>
This Is From the Detail Page (detail.php)

Code: Select all

<? if($row['post_service']=='royal-mail-1st-class') { ?><td><img src="images/royal-mail-1st-class.jpg" /></td>
         <? } if($row['post_service']=='royal-mail-2nd-class') { ?><td><img src="images/royal-mail-2nd-class.jpg" /></td>
         <? } if($row['post_service']=='DPD') { ?><td><img src="images/DPD.jpg" /></td>
         <? } if($row['post_service']=='DHL') { ?><td><img src="images/DHL.jpg" /></td>
         <? } if($row['post_service']=='Fedex') { ?><td><img src="images/fedex.jpg" /></td>
         <? } if($row['post_service']=='parcel-force-24') { ?><td><img src="images/parcel-force-24.jpg" /></td>
         <? } if($row['post_service']=='parcel-force-48') { ?><td><img src="images/case-collection.jpg" /></td>
         <? } if($row['post_service']=='case-collection') { ?><td><img src="images/parcel-force-48.jpg" /></td>
         <? } if($row['post_service']=='other-postages') { ?><td><img src="images/other-postages.jpg" /></td>
         <? } if($row['post_service']=='pickup-only') { ?><td><img src="images/pickup-only.jpg" /></td><? }?>
        <td>&nbsp;<? echo $row['post_service']; ?></td></tr>
i know it will display pictures when working, however it currently isn't, when i remove one of the "=" from the code above, it will show that image, even though i know it hasn't been selected, but this is the only way that i have been able to see the table and image works.

But why is it not saving the checked boxes selected on previous page, i beleived the database is correct but what is wrong?

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 2:50 am
by eivind
Doesn't seem like your code saves your choice anywhere, though. Does it? How is your choice given to $row in detail.php?

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 1:03 pm
by dbarron87
i am using a script i brought, so i am lost.
there maybe another code that shows it saves however i have not found this.
what sort of code would be needed to save it?
the database is all setup, to me it does seem like it isn't saving the choice in the database, i could be completely wrong though.
if there was some code somewhere that does save the choice do you believe this coding above would work?
Thanks for your help.

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 1:11 pm
by fugix
change the <?= to <?php

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 1:14 pm
by dbarron87
fugix wrote:change the <?= to <?php

at what part of the code sorry
as i see a few <?
thanks for your help

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 5:08 pm
by fugix
all of them...the <? are short tags and should be avoided...always use <?php

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 5:28 pm
by dbarron87
fugix wrote:all of them...the <? are short tags and should be avoided...always use <?php

thanks fugix i will try that now.

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 5:55 pm
by dbarron87
this did not seem to make a difference, i am not sure why.

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 8:29 pm
by califdon
Fugix is right about using "long" opening PHP tags, but that will not affect your problem, it's just good practice (the "short" tags could be misinterpreted as tags for other languages, if they are present on the server).

You need to learn some fundamentals about PHP and web protocols, so you can at least show us the parts of the scripts that might be involved with your problem. You can't learn that in a forum, but let me try to point you in the right direction. The way that data in an HTML form is passed to another PHP script is (usually) as elements of a special global array called the $_POST array. When the form Submit button is clicked, the browser sends this array to the server along with its call to the second script. So the second script must contain code lines that check the values in the $_POST array. These lines might look something like this:

Code: Select all

...
if(isset($_POST['chkservice'])) {
   $chkservice = $_POST['checkservice'];
} else {
   $chkservice = "";
}
What that says is: if there IS a value in the $_POST array with the name 'chkservice" (that's the name of your Select dropdown box on the form), use that value for the variable $chkservice in this script, if not, use a zero-length string. The reason to do it this way is to avoid a programming error in case that value is NOT in the array, for some reason.

Now that you have a variable, you can do something with it.

With that understanding, perhaps you can look at your second script and determine whether it is even looking for this value. Usually all the $_POST variables will be checked in one place near the beginning of the script. If you don't find this kind of a line, that's probably your problem.

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 8:57 pm
by dbarron87
califdon wrote:Fugix is right about using "long" opening PHP tags, but that will not affect your problem, it's just good practice (the "short" tags could be misinterpreted as tags for other languages, if they are present on the server).

You need to learn some fundamentals about PHP and web protocols, so you can at least show us the parts of the scripts that might be involved with your problem. You can't learn that in a forum, but let me try to point you in the right direction. The way that data in an HTML form is passed to another PHP script is (usually) as elements of a special global array called the $_POST array. When the form Submit button is clicked, the browser sends this array to the server along with its call to the second script. So the second script must contain code lines that check the values in the $_POST array. These lines might look something like this:

Code: Select all

...
if(isset($_POST['chkservice'])) {
   $chkservice = $_POST['checkservice'];
} else {
   $chkservice = "";
}
What that says is: if there IS a value in the $_POST array with the name 'chkservice" (that's the name of your Select dropdown box on the form), use that value for the variable $chkservice in this script, if not, use a zero-length string. The reason to do it this way is to avoid a programming error in case that value is NOT in the array, for some reason.

Now that you have a variable, you can do something with it.

With that understanding, perhaps you can look at your second script and determine whether it is even looking for this value. Usually all the $_POST variables will be checked in one place near the beginning of the script. If you don't find this kind of a line, that's probably your problem.


i think i kind of understand that, after looking at what you put i did not find a line like that any where near the top of the page
i found this instead

Code: Select all

 <select name="chkservice">
 <option value="">Select</option>
<?php
this was within the code about the postage service, however the code is missing half of what you put. is this my problem?
it does almost seem to me that the problem is either writing the chosen drop down menu to the database or receiving the chosen drop down menu.
would i be right to say that?

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 9:07 pm
by califdon
You're looking in the wrong script. What you posted is in the first script, to create the dropdown box, which called a Select form element. That's where it is assigned the name "chkservice". When the form is Submitted, the second script must look at the $_POST array to find the values. Whether you write the values to a database is an entirely different matter, but you certainly can't do that if you don't have the values! I think if you read my previous post again, you should be able to examine the second script and find where it is looking for ALL the values from the form. It should be the only place in the script where you see references to the $_POST array.

More fundamentally, this is why a forum isn't an appropriate place to learn basic fundamentals of programming. You just have to learn first things first.

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 10:09 pm
by dbarron87
Well this must be my problem, i am seeing no where anything along the lines of $_post array
i will carry on looking in to it now, im getting awfuly tired, so not sure if it maybe a slow reply.

Re: Newbie lost and out of my depth

Posted: Thu Apr 21, 2011 11:35 pm
by califdon
There are only 2 ways to get data from a form and do anything with the data: $_GET, which passes the data as part of the URL (that's what you see sometimes when a URL ends with a question mark followed by one or more pairs of names and values, like "xyz.com?id=287671&pg=2", but that is rarely used for data from forms, or $_POST, which I described earlier. If the second script doesn't have anything relating to $_POST, it cannot possibly receive any data from the first script. It's also possible that a script calls itself, instead of a different script. Then the $_POST stuff would have to be in the same script. You can tell which is the case by finding (in the first script) the FORM tag (<form name=xxxxx method=post action=zzzzz>). The method will be either "post" or "get" (rare). The action will either be the name of the second script, or possibly blank, meaning that it calls itself.

Re: Newbie lost and out of my depth

Posted: Sat Apr 23, 2011 8:26 pm
by dbarron87
califdon wrote:There are only 2 ways to get data from a form and do anything with the data: $_GET, which passes the data as part of the URL (that's what you see sometimes when a URL ends with a question mark followed by one or more pairs of names and values, like "xyz.com?id=287671&pg=2", but that is rarely used for data from forms, or $_POST, which I described earlier. If the second script doesn't have anything relating to $_POST, it cannot possibly receive any data from the first script. It's also possible that a script calls itself, instead of a different script. Then the $_POST stuff would have to be in the same script. You can tell which is the case by finding (in the first script) the FORM tag (<form name=xxxxx method=post action=zzzzz>). The method will be either "post" or "get" (rare). The action will either be the name of the second script, or possibly blank, meaning that it calls itself.


sorry for slow responce, had some time away.
after reading this i have noticed that it does end with a question mark
ship_detail.php?item_id=
so it being like this would mean i need a $_get function is this correct.
to receive the chosen option from the drop down? as agin i am not seeing this either.

im very sorry, i normally pick things up well but i must admit i am struggling with this.

Re: Newbie lost and out of my depth

Posted: Sat Apr 23, 2011 9:08 pm
by califdon
Tell me exactly what the <form> tag has in it. It will be above the part of shippingdetail.php that has your <select> tag and the other form elements. It will look something like <form method=post action= detail.php>. Show me exactly what it says.