...

View Full Version : Resolved Value not sending



greens85
07-02-2010, 01:42 PM
Hi all,

I've added a radio button, that will basically check if the user has already set email alerts and will let them turn them off if they so wish:


<?php
$joinquery = "SELECT * FROM resumes LEFT JOIN jobseekers ON jobseekers.jobseekerid = resumes.jobseekerid WHERE resumes.jobseekerid=\"$a1[jobseekerid]\"";
$alertr = mysql_query($joinquery) or die (mysql_query());
while ($alertrow = mysql_fetch_array($alertr)) {
$alertstatus = $alertrow['alertstatus'];
}

if($alertstatus == '') {
echo "<input type='radio' name='alertstatus' value='Yes' checked>Yes
<input type='radio' name='alertstatus' value='No'>No";
} elseif($alertstatus == 'Yes') {
echo "<input type='radio' name='alertstatus' value='Yes' checked>Yes
<input type='radio' name='alertstatus' value='No'>No";
} else {
echo "<input type='radio' name='alertstatus' value='Yes'>Yes
<input type='radio' name='alertstatus' value='No' checked>No";
}
?>

While this succeeds in checked if they have previously allowed email alerts or not, when I then press to change to 'No' or even 'Yes' then value isn't being posted to the database, on the processing side of things I have added this:


$alertstatus = mysql_real_escape_string($_POST['alertstatus']);
echo $alertstatus;

$query = "UPDATE resumes SET
title = \"$title\",
hour = \"$hour\",
category = \"$category\",
subcounty = \"$subcounty\",
alertstatus = \"$alertstatus\"
where jobseekerid = \"$a1[jobseekerid]\"";

Added the echo to see if the value was being passed but I can now see that it isn't... the problem is I don't know why it isn't being passed?

Can anyone offer any advice on this?

many thanks,

Greens85

mlseim
07-02-2010, 02:14 PM
I don't see any kind of <form> tag with the action and method.

_Aerospace_Eng_
07-02-2010, 02:14 PM
So where do you actually run your query? I see no call to mysql_query in your code.

greens85
07-02-2010, 02:19 PM
I don't see any kind of <form> tag with the action and method.

Hey mlseim,

The form tag is present but as its a long form I just didnt bother to show it... it is set like so:


<form action="setalerts.php" method="post">

At least I assume that is what you mean?

greens85
07-02-2010, 02:20 PM
So where do you actually run your query? I see no call to mysql_query in your code.

Hi aerospace,

Not sure I fully get what you mean, are you talking about this part?


<?php
$joinquery = "SELECT * FROM resumes LEFT JOIN jobseekers ON jobseekers.jobseekerid = resumes.jobseekerid WHERE resumes.jobseekerid=\"$a1[jobseekerid]\"";
$alertr = mysql_query($joinquery) or die (mysql_query());
while ($alertrow = mysql_fetch_array($alertr)) {
$alertstatus = $alertrow['alertstatus'];
}
?>

If so, is the call not this part?


$alertr = mysql_query($joinquery) or die (mysql_query());

tomws
07-02-2010, 02:32 PM
Are you saying that you're not getting the POST value or your are getting it but it's not inserting? What's the order of your code? Can you take the whole thing, trim it down to the relevant portion and post it here?

I don't know if it matters for your app, but the inputs aren't valid XHTML. The input tags should be closed and the checked attribute should be in standard attribute="value" format. Like this, for example:

<input type='radio' name='alertstatus' value='Yes' checked="checked" />

_Aerospace_Eng_
07-02-2010, 02:49 PM
Well in the part you said you added you have some SQL in there for an UPDATE but you never show a call to mysql_query.

greens85
07-02-2010, 03:02 PM
Are you saying that you're not getting the POST value or your are getting it but it's not inserting? What's the order of your code? Can you take the whole thing, trim it down to the relevant portion and post it here?

I don't know if it matters for your app, but the inputs aren't valid XHTML. The input tags should be closed and the checked attribute should be in standard attribute="value" format. Like this, for example:

<input type='radio' name='alertstatus' value='Yes' checked="checked" />

Hey Tomws,

In answer to your question, I suppose the answer is both! I'm not getting the POST value for that one particular record, and as a result it isn't inserting. It might be worth noting that all other values are being passed just fine!

I'm not sure exactly what parts you would need to troubleshoot, so I will just provide the whole page for both the entry part and the processing script.. hope this is fine with you.

As for the validation stuff, unfortunately the vast bulk of the code is pre bought software which quite honestly is wrote horrendously, however I inherited without choice... i would love to clean it up but quite simply it would take too much time, that I am currently using to develop and enhance the features of the site! :(

_Aerospace_Eng_
07-02-2010, 03:08 PM
Can you post the table structure for your resumes table? An sql dump for the table would be best as it shows the types for each field. If you use this for your update query after you echo alertstatus

$query = "UPDATE resumes SET
title = '$title',
hour = '$hour',
category = '$category',
subcounty = '$subcounty',
alertstatus = '$alertstatus'
where jobseekerid = {$a1['jobseekerid']}";
echo $query;
$result = mysql_query($query) or die(mysql_error());
and paste the query that is echoed into something like phpmyadmin do you get any results?

tomws
07-02-2010, 03:16 PM
To start with, this is on the form page:

<td><input type="hidden" name="alertstatus" id="alertstatus" value"Yes"></td>

Same name as the radio buttons, but after them. I'm unsure how the browser would pass values and what the handler would receive. It would be worth the time to change that or comment it out for testing.
EDIT: Oh, look! The value attribute isn't used correctly there. It's missing the "=". I'll be that's why you're not even getting a "Yes".

greens85
07-02-2010, 03:52 PM
Can you post the table structure for your resumes table? An sql dump for the table would be best as it shows the types for each field. If you use this for your update query after you echo alertstatus

$query = "UPDATE resumes SET
title = '$title',
hour = '$hour',
category = '$category',
subcounty = '$subcounty',
alertstatus = '$alertstatus'
where jobseekerid = {$a1['jobseekerid']}";
echo $query;
$result = mysql_query($query) or die(mysql_error());
and paste the query that is echoed into something like phpmyadmin do you get any results?

I'm using PHPmyadmin but not sure how to get a dump of the table, would you be kind enough to talk me through it?

greens85
07-02-2010, 03:54 PM
To start with, this is on the form page:

<td><input type="hidden" name="alertstatus" id="alertstatus" value"Yes"></td>

Same name as the radio buttons, but after them. I'm unsure how the browser would pass values and what the handler would receive. It would be worth the time to change that or comment it out for testing.
EDIT: Oh, look! The value attribute isn't used correctly there. It's missing the "=". I'll be that's why you're not even getting a "Yes".

You are right in that:


<input type=hidden" name="alertstatus" id="alertstatus" value="Yes"> is part of the old setup, I will remove it now!

Not sure where to go from here though?

tomws
07-02-2010, 03:59 PM
Not sure where to go from here though?

Um... try it and see if it works? If I'm correct, that's where your empty value was coming from, so now it should be passing the correct value from the radios.

greens85
07-02-2010, 04:01 PM
Just an update, after removing that line the variable is now echoing out :)

However it is still not inserting into the database :confused:

greens85
07-02-2010, 04:10 PM
Not to worry it is now updating the record :)

I think it may have been because I edited the field directly in the database at some point, this has proved a problem with updates before but either way all works fine now...

Many thanks to everyone who helped me out here, it is greatly appreciated!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum