Forum Moderators: coopster

Message Too Old, No Replies

if (isset. causing php script to drop

         

indiguy

11:54 am on Sep 14, 2009 (gmt 0)

10+ Year Member



if(isset($_POST['menu1']))
{
// Select every record from the table or display error
$menu1 = mysql_query("select cp_teas.* from cp_teas") or die(mysql_error());
while ( $row = mysql_fetch_array($menu1) ) //return results line by line
{
// For the javascript function above: onkeyup='checkField(this);', see below.
// [webmasterworld.com...]
echo "<tr>";
echo "<input type='hidden' name='id' value='".$row['tea_id']."'>";
echo "<td><input type='text' size = 10 name='choice' onkeyup='checkField(this);' value='".$row['tea_choice']."'></td>";
echo "<td>"."&nbsp;&nbsp"."<input type='text' size = 45 name='description' onkeyup='checkField(this);' value='".$row['tea_desc']."'>"."..."."</td>";
echo "<td>"."&nbsp;&nbsp\$"."<input type='text' size = 3 id='price' name='price' value='".$row['tea_price']."'></td>";
echo "<td><input type='submit' value='Update' name='button1' ></td>";
echo "<td><input type='submit' value='Delete' name='button2'action='javascript:confirm(<? echo '".$row['tea_id']."','".$row['tea_choice']."','".$row['tea_desc']."','".$row['tea_price']."'; ?>)' ></td>";
echo "</tr>";
// update button function
if(isset($_POST['button1']))
{.....

its dropping with this isset -> if(isset($_POST['button1']{..
Ive tested via echo "bla bla" to see if it was a query issue, but its not. Im using Joomla and when i click on "update" it drops out and opens a joomla article. Ive tried it outside the while loop, and tried using html instead of echo if(isset.. but no difference..
Im new to php, and on a steep learning curve.. but im lost with this now.

leadegroot

1:01 pm on Sep 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what do you mean by the script 'dropping'?
Do you see the table row in the source before this 'drop' output?

rocknbil

1:33 am on Sep 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You mean the script is outputting everything before your isset but dying at that point? If it's related to your other thread [webmasterworld.com] it's probably a mysql error . . . . can you check your error logs?

indiguy

3:57 am on Sep 15, 2009 (gmt 0)

10+ Year Member



yeah, its related, but i posted this one as was a different issue.
By 'dropping' i mean, when i click 'update' submit button, the script stops, it returns to a different joomla article thats not called!

I know its not the sql in the if(isset($_POST['button1'])) which handles the update button. I tested with a echo, but that didnt even show. so its breaking out when button is clicked.

Oh, thanks for your advice before too :)

indiguy

9:03 am on Sep 16, 2009 (gmt 0)

10+ Year Member



i checked my error logs, but nothing. i know the update works, is i updated earlier outside the while loop. but its since the if(isset.. is implemented the script stops.

rocknbil

2:54 pm on Sep 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it wouldn't be it if (isset()) itself, it would be what's inside it.

Or what happens if button1 is not set. That is, we can't see what's after the if (isset()) condition, so in the condition below,

if (isset('button1')) {
// do something
}
// No condition if button1 is not set.
// So the script just ends if there's not an
// else or else if here.
?>

... if button1 is present, it executes what's in the if, if not, there's nothing to do following it.

My point is programming can sometimes throw you a curve, making you look in all the wrong places for sometimes days on end. I'd 1) make sure button1 is set by doing something like this,

if (isset('button1')) {
// do something
echo "button 1 was set";
}

and 2) find out what's in the if condition that's causing it to end (or outside it, if button1 is not set.)

indiguy

12:14 pm on Sep 17, 2009 (gmt 0)

10+ Year Member



thanks for all your help people. I got a frd to look. its not good to call name two things the same.. hence why the script was dropping out. I had two 'id's. a pk was name=\"id\"..
and the form was name=\"id\".
thats the trouble. but solved now, and now i know how to use:
//print_r($_GET);
//print_r($_POST);

all good, got to remove some submits, only one per form, so plan to just have one and update all rows at the same time. my works cut out for me.. should be sort of fun learning