...

View Full Version : One variable not posting while the rest are?



greens85
02-22-2010, 11:28 AM
Hi,

I have a number of variables posting correctly but my ID one doesn't seem to want to work for me, despite it being setup in the same manner as the rest...


<?php
$id = $_GET['candidateid'];
$query = "SELECT * FROM my_table WHERE id = $id";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_array($result);
?>


<input type="text" name"candidateid" id="candidateid" class="bodyinput" value="<?php echo $id;?>"/> // This correctly puts the candidate id in the box

but when I submit the form to the next page, and try to drag it out like so:


$candidateid = mysql_real_escape_string($_POST['candidateid']);

<tr>
<td style='background-color:#CCCCCC;'>Candidate ID:</td>
<td style='background-color:#CCCCCC;'>$candidateid</td>
</tr>

I just get a blank space where it should display the candidate id, anyone got any ideas?

Just so you can compare it with one of my working variables:


<input type="text" name="candidatename" id="candidatename" class="bodyinput" value="<?php echo $row['fname'];?>"/>

$candidatename = mysql_real_escape_string($_POST['candidatename']);

<tr>
<td>Candidate Name:</td>
<td>$candidatename</td>
</tr>

This displays the candidate name exactly as I would expect.

JAY6390
02-22-2010, 12:19 PM
You use $_GET and $_POST in your examples, which of the two is it meant to be? My guess is that is what's causing the problem. A simple way to check is to put this at the top of your script for the form processing script and see which has the candidateid in it

echo '<h2>POST</h2>';
echo '<pre>'.print_r($_POST, true).'</pre>';
echo '<h2>GET</h2>';
echo '<pre>'.print_r($_GET, true).'</pre>';

koko5
02-22-2010, 12:30 PM
Hi, maybe td style='background-color:#CCCCCC; is the same as your text color inside td -> use mouse select or view source.

You can use
<input type="text" name"candidateid" id="candidateid" class="bodyinput" value="<?php echo htmlentities($_GET['candidateid']);?>"/>for the first page instead of sql result.

p.p.: Try also:

var_dump($_REQUEST);
Regards

greens85
02-22-2010, 12:58 PM
You use $_GET and $_POST in your examples, which of the two is it meant to be? My guess is that is what's causing the problem. A simple way to check is to put this at the top of your script for the form processing script and see which has the candidateid in it

echo '<h2>POST</h2>';
echo '<pre>'.print_r($_POST, true).'</pre>';
echo '<h2>GET</h2>';
echo '<pre>'.print_r($_GET, true).'</pre>';

Hey Jay,

thanks for the reply... to be honest I've actually tried both $_GET & $_POST and neither of them work...

As for your test, neither of them actually print the candidate ID... obviously this show the problem, I'm just not sure why it's picking up the rest though, when im using the same method!

To try and make things a bit clearer the structure is:

schoolarea.php

This page contains a 'candidate ticker', once the user clicks to enquire about a certain candidate then next page loads up with a url of:

http://www.my-site.co.uk/candidateenquire.php?candidateid=10

Then I have a form, where the candidate id is successfully posted to the form, along with a number of other variables...

however when I post the form (so that it will email me the details, I recieve all the details I'd expect except for the candidate id... but I cant see any difference in the way I'm calling the candidate id or any of the other variables!

greens85
02-22-2010, 01:17 PM
Might be worth noting, it I add the same code to the previous page...

candidateenquire.php

It returns candidateid as a $_GET rather than a $_POST?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum