Welcome! Log In Create A New Profile

Advanced

Step 7 - "Model is not available in ANY Colour" - Why??

Posted by 37081888 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar Step 7 - "Model is not available in ANY Colour" - Why??
October 29, 2013 12:03PM
I've been having this issue for a while now and I'm trying to figure out why...

Whenever I click the submit button to check if the selected model is available in the chosen colour, the result is always "not available in the selected colour" even though I specifically set the DB to ensure the model's availability in a certain colour.

Has anyone had this issue and if so, could you please help me sort it out?

(Is there something wrong with my availability table perhaps? I created it exactly as Mac instructed in the tut letter. Now I feel like it's in need of more columns - 1 for model name and the other for colour name...)
avatar
Mac
Re: Step 7 - "Model is not available in ANY Colour" - Why??
October 29, 2013 12:51PM
This question is as wide as the horizon.... impossible to say what the error is, other than that the query is clearly not correct..
avatar Re: Step 7 - "Model is not available in ANY Colour" - Why??
October 29, 2013 01:35PM
Apologies for not zoning it in earlier with the code I think may be problematic... here is my "fill in the blanks" code for the selection based on yours in the tut letter:

<form action="" method="POST">
<?php
$result = $connection->Fetch('model','model_id'); ?>
Model: <select name="model">
<option value="select">Select</option>
<?php
for ($x = 0; $x < count($result); $x++) {
echo "<option value=". $result[$x]['model_id'] .">". $result[$x]['model']."</option>";
}
?>
</select>

<?php
$result = $connection->Fetch('colour' , 'colour_id'); ?>
Colour: <select name="colour">
<option value="select">Select</option>
<?php
for ($x = 0; $x < count($result); $x++) {
echo "<option value=". $result[$x]['colour_id'] .">". $result[$x]['colour']."</option>";
}
?>
</select>
<input type="submit" value="Submit" name="Availability"/>
</form>
<?php
$Submit=$_POST['Availability']; //this line gives me an "undefined variable" error...
if(isset($Submit))
{
$model_id=$_POST['model'];
$colour_id=$_POST['colour'];
echo "<br /></br>";
echo "The model ";
$result = $connection->Fetch_model('model'); // could this section be the troublesome one?
$result = $connection->Avail('model_id' , 'colour_id'); // this line?
echo " in the colour ";
$result = $connection->Fetch_colour('colour'); // or this one?
}
echo "<br /></br>";
$connection->select_db();
?>
avatar
Mac
Re: Step 7 - "Model is not available in ANY Colour" - Why??
October 29, 2013 01:57PM
Use the formatted code button to post code...

I cannot post the solution here sad smiley but Fetch requires two parameters

Figure it out from here, because understanding that shows you understand how OOP can be used.
avatar Re: Step 7 - "Model is not available in ANY Colour" - Why??
October 29, 2013 02:15PM
Language: PHP
$Submit=$_POST['Availability']; //this line gives me an "undefined variable" error...
You should not try and extract anything from $_POST without checking if it isset.

Language: PHP
$Submit=$_POST['Availability']; //this line gives me an "undefined variable" error... if(isset($Submit)) // <<< Unnecessary duplication, combine the 2 lines.

Language: PHP
$model_id=$_POST['model']; $result = $connection->Fetch_model('model'); // could this section be the troublesome one? <<< Your variable name is $model_id

Language: PHP
$model_id=$_POST['model']; $colour_id=$_POST['colour']; $result = $connection->Avail('model_id' , 'colour_id'); // this line? <<< Your variable names are $model_id and $colour_id

Language: PHP
$result = $connection->Fetch_colour('colour'); // or this one? <<< Your variable name is $colour_id

You assign 3 different values to $result without using any of them.


This code should be above the form. When you click submit, the page is reloaded, and processing starts from the top again.
Processing does not continue after the form, when you submit the form.
Language: PHP
<?php $Submit=$_POST['Availability']; //this line gives me an "undefined variable" error... if(isset($Submit)) { $model_id=$_POST['model']; $colour_id=$_POST['colour']; echo "<br /></br>"; echo "The model "; $result = $connection->Fetch_model('model'); // could this section be the troublesome one? $result = $connection->Avail('model_id' , 'colour_id'); // this line? echo " in the colour "; $result = $connection->Fetch_colour('colour'); // or this one? } echo "<br /></br>"; $connection->select_db(); ?>
avatar Re: Step 7 - "Model is not available in ANY Colour" - Why??
October 29, 2013 06:01PM
@bigron: Whoo-hoo! Yet again, your advice and pointers WORKED - dude, why are you so awesome?? (I mean that in a good way) smiling smiley
So, I completely neglected to use the variables I assigned in the opening section of the form's processing code ($model_id and $colour_id) in the $result= lines which is why the page wasn't able to match the selections of model and colour with the availability table... sighhh, that's what OOP requires, lol... I'm glad it's sorted now - thanks very much for helping me understand this. BTW, even though I didn't combine if isset and $_POST in the same line, the submit button does work nevertheless - I get what you're saying though.

@Mac: as a lecturer I know you can't post solutions (just a few pointers in the right direction would suffice) but, thanks for organising this forum for your students to help each other learn smiling smiley

bigron11 Wrote:
-------------------------------------------------------
>
Language: PHP
> $Submit=$_POST['Availability']; //this line gives > me an "undefined variable" error... >
> You should not try and extract anything from
> $_POST without checking if it isset.
>
>
Language: PHP
> $Submit=$_POST['Availability']; //this line gives > me an "undefined variable" error... > if(isset($Submit)) > // <<< Unnecessary duplication, > combine the 2 lines. >
>
>
Language: PHP
> $model_id=$_POST['model']; > $result = $connection->Fetch_model('model'); // > could this section be the troublesome one? <<< > Your variable name is $model_id >
>
>
Language: PHP
> $model_id=$_POST['model']; > $colour_id=$_POST['colour']; > $result = $connection->Avail('model_id' , > 'colour_id'); // this line? <<< Your variable > names are $model_id and $colour_id >
>
>
Language: PHP
> $result = $connection->Fetch_colour('colour'); // > or this one? <<< Your variable name is > $colour_id >
>
> You assign 3 different values to $result without
> using any of them.
>
>
> This code should be above the form. When you click
> submit, the page is reloaded, and processing
> starts from the top again.
> Processing does not continue after the form, when
> you submit the form.
>
Language: PHP
> <?php > $Submit=$_POST['Availability']; //this line gives > me an "undefined variable" error... > if(isset($Submit)) > { > $model_id=$_POST['model']; > $colour_id=$_POST['colour']; > echo "<br /></br>"; > echo "The model "; > $result = $connection->Fetch_model('model'); // > could this section be the troublesome one? > $result = $connection->Avail('model_id' , > 'colour_id'); // this line? > echo " in the colour "; > $result = $connection->Fetch_colour('colour'); // > or this one? > } > echo "<br /></br>"; > $connection->select_db(); > ?> >
Sorry, only registered users may post in this forum.

Click here to login