techiefreak05 Posted January 9, 2007 Share Posted January 9, 2007 I tried a query that updated a lot of stuff .. but it wouldnt work, so i tried putting it into a function, but i still get a syntax error, and i dont know why...*also note, the original query worked on my computer, but after i got a host, some random bits of all my sql queries stopped workingTHE FUNCTION:[code]<?phpfunction doUpdate($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o){$update = "UPDATE zpageinfo SET film = '$a', literature = '$b', music = '$c, aboutme = '$d', friends = '$e', gender = '$f', school = '$g', here_for = '$h', city = '$i', state = '$j', work = '$k', age = '$l', css_code = '$m', smoke = '$n', drink = '$o' WHERE id = '$_SESSION[id]'";mysql_query($update) or die(mysql_error());}?>[/code]HOW I USE IT:[code]<?phpdoUpdate($_POST[film],$_POST[literature],$_POST[music],$_POST[aboutme],$_POST[friends],$_POST[gender],$_POST[select_edu],$_POST[here_for],$_POST[city],$_POST[state_select],$_POST[work],$_POST[age],$_POST[css_code],$_POST[smoke],$_POST[drink]);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/ Share on other sites More sharing options...
matto Posted January 9, 2007 Share Posted January 9, 2007 change this partid = '$_SESSION[id]'";toid = '" . $_SESSION['id'] . "'"; Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156360 Share on other sites More sharing options...
matto Posted January 9, 2007 Share Posted January 9, 2007 also your post vars s/be like$_POST['film']not like$_POST[film] Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156361 Share on other sites More sharing options...
techiefreak05 Posted January 9, 2007 Author Share Posted January 9, 2007 Tahnks for the replies, but i tried to no avail .. Here is how i use the functon as of right now:[code]<?phpdoUpdate($_POST['film'],$_POST['literature'],$_POST['music'],$_POST['aboutme'],$_POST['friends'],$_POST['gender'],$_POST['select_edu'],$_POST['here_for'],$_POST['city'],$_POST['state_select'],$_POST['work'],$_POST['age'],$_POST['css_code'],$_POST['smoke'],$_POST['drink']);?>[/code]and here is the function itself:[code]<?phpfunction doUpdate($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o){$update = "UPDATE zpageinfo SET film = '$a', literature = '$b', music = '$c, aboutme = '$d', friends = '$e', gender = '$f', school = '$g', here_for = '$h', city = '$i', state = '$j', work = '$k', age = '$l', css_code = '$m', smoke = '$n', drink = '$o' WHERE id = '" . $_SESSION['id'] . "'"; mysql_query($update) or die(mysql_error());}?>[/code]but with those, it producs the same syntax error:[quote]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '1'' at line 1[/quote]where it says "1".. thats my session id... there is some error around ( WHERE id = '" . $_SESSION['id'] . "' ) Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156362 Share on other sites More sharing options...
Philip Posted January 9, 2007 Share Posted January 9, 2007 music = '$cneeds an extra 'music = '$c' Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156363 Share on other sites More sharing options...
techiefreak05 Posted January 9, 2007 Author Share Posted January 9, 2007 HAHA. thanks alot! got rid of the error, but now it still doesnt work .. the $_POST variables are all still empty .. when they're not ... I'm now back to my original problem ...when I echo $update from the function... it shows the query like i have it, except all the $_POST variables are empty ...but they are not. Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156373 Share on other sites More sharing options...
Philip Posted January 9, 2007 Share Posted January 9, 2007 If you echo them, does it show all of the data? Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156375 Share on other sites More sharing options...
matto Posted January 9, 2007 Share Posted January 9, 2007 yes, add this after your $update = "echo "<tt>$update</tt>";exit; Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156378 Share on other sites More sharing options...
techiefreak05 Posted January 9, 2007 Author Share Posted January 9, 2007 when i echo the variable that holds the query, it shows this::[quote]UPDATE zpageinfo SET film = '', literature = '', music = '', aboutme = '', friends = '', gender = '', school = '', here_for = '', city = '', state = '', work = '', age = '', css_code = '', smoke = '', drink = '' WHERE id = '1' [/quote]its not getting the $_POST data.. even tho i filled out all of the fields..., yes they are all the correct names, this query has worked on my system, but not on my host Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156380 Share on other sites More sharing options...
Philip Posted January 9, 2007 Share Posted January 9, 2007 Do you have a link to the site (you can PM if you want), or can you show the form code? Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156382 Share on other sites More sharing options...
matto Posted January 9, 2007 Share Posted January 9, 2007 can you post your form tag<form method=....> Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156385 Share on other sites More sharing options...
btherl Posted January 9, 2007 Share Posted January 9, 2007 When post data isn't appearing when I expect it, I would add this at the very start of the script:[code=php:0]var_dump($_POST);exit(0);[/code]That will display the entire contents of $_POST. If it's empty, then the problem is with how you call the script. I would guess that you need to add "method=post". Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156407 Share on other sites More sharing options...
techiefreak05 Posted January 9, 2007 Author Share Posted January 9, 2007 my form tag is as follows: <form action="" method="post">...form stuff here...</form> Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156455 Share on other sites More sharing options...
techiefreak05 Posted January 9, 2007 Author Share Posted January 9, 2007 ok ive had some advising from people.. and we cant figure out why the POST variables are empty when they shouldnt be. we believe its the form .. somewhere.. a ilttle piece.. but we cant quite spot it.. can you??ITS A BG FORM...[code]<form action="" method="post"><table cellpadding="2" cellspacing="2" class="menuGreen"><tr><td><input type="submit" name="zpageUPDATE" value="-Update All-"></td></tr></table><br><br><?phpif($_POST['clrComments']){$clrCommentsQ="DELETE FROM profile_comments WHERE userID = '$_SESSION[id]'";mysql_query($clrCommentsQ);}?><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Delete All Your Profile Comments</div><br><form action="" method="post"><input type="submit" name="clrComments" value="-Clear Your Profile Comments-"></form></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Why Are You Here?</div><br><input type="text" name="here_for" size="60" value="<?php echo $row[here_for];?>"></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Age</div><br><input type="text" name="age" size="10" value="<?php echo $row[age];?>" maxlength="3"></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Occupation</div><br><input type="text" name="work" size="60" value="<?php echo $row[work];?>"></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Location</div></td></tr><tr><td>City: <input type="text" name="city" value="<?php echo $row[city];?>" size="25"></td><td>State: <select name="state_select"> <option name="state" value="NoState">--Select A State--</option> <option name="state" value="Alabama">Alabama</option> <option name="state" value="Alaska">Alaska</option> <option name="state" value="Arizona">Arizona</option> <option name="state" value="Arkansas">Arkansas</option> <option name="state" value="California">California</option> <option name="state" value="Colorado">Colorado</option> <option name="state" value="Connecticut">Connecticut</option> <option name="state" value="Delaware">Delaware</option> <option name="state" value="Florida">Florida</option> <option name="state" value="Georgia">Georgia</option> <option name="state" value="Hawaii">Hawaii</option> <option name="state" value="Idaho">Idaho</option> <option name="state" value="Illinois">Illinois</option> <option name="state" value="Indiana">Indiana</option> <option name="state" value="Iowa">Iowa</option> <option name="state" value="Kansas">Kansas</option> <option name="state" value="Kentucky">Kentucky</option> <option name="state" value="Louisiana">Louisiana</option> <option name="state" value="Maine">Maine</option> <option name="state" value="Maryland">Maryland</option> <option name="state" value="Massachusets">Massachusets</option> <option name="state" value="Michigan">Michigan</option> <option name="state" value="Minnesota">Minnesota</option> <option name="state" value="Mississippi">Mississippi</option> <option name="state" value="Missouri">Missouri</option> <option name="state" value="Montana">Montana</option> <option name="state" value="Nebraska">Nebraska</option> <option name="state" value="Nevada">Nevada</option> <option name="state" value="New Hampshire">New Hampshire</option> <option name="state" value="New Jersey">New Jersey</option> <option name="state" value="New Mexico">New Mexico</option> <option name="state" value="New York">New York</option> <option name="state" value="North Carolina">North Carolina</option> <option name="state" value="North Dakota">North Dakota</option> <option name="state" value="Ohio">Ohio</option> <option name="state" value="Oklahoma">Oklahoma</option> <option name="state" value="Oregon">Oregon</option> <option name="state" value="Pennsilvania">Pennsilvania</option> <option name="state" value="Rhode Island">Rhode Island</option> <option name="state" value="South Carolina">South Carolina</option> <option name="state" value="South Dakota">South Dakota</option> <option name="state" value="Tennesse">Tennesse</option> <option name="state" value="Texas">Texas</option> <option name="state" value="Utah">Utah</option> <option name="state" value="Vermont">Vermont</option> <option name="state" value="Verginia">Verginia</option> <option name="state" value="Washington">Washington</option> <option name="state" value="West Virginia">West Virginia</option> <option name="state" value="Wisconsin">Wisconsin</option> <option name="state" value="Wyoming">Wyoming</option></select></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Education</div></td></tr><tr><td><select name="select_edu"><option name="edu" value="None" <?php if($row['school'] == "None"){echo "selected"; } ?>>--Select Education--</option><option name="edu" value="High School Grad" <?php if($row['school'] == "High School Grad"){echo "selected"; } ?>>High School Grad</option><option name="edu" value="Some High School" <?php if($row['school'] == "Some High School"){echo "selected"; } ?>>Some High School</option><option name="edu" value="In High School" <?php if($row['school'] == "In High School"){echo "selected"; } ?>>In High School</option><option name="edu" value="College Grad" <?php if($row['school'] == "College Grad"){echo "selected"; } ?>>College Grad</option><option name="edu" value="Some College" <?php if($row['school'] == "Some College"){echo "selected"; } ?>>Some College</option><option name="edu" value="In College" <?php if($row['school'] == "In College"){echo "selected"; } ?>>In College</option></select></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue" width="335"><tr><td><div class="headingBlue">Gender</div></td></tr><tr><td>Male<input type="radio" name="gender" value="Male" <?php if($row['gender'] == "Male"){echo "checked"; } ?>><br>Female<input type="radio" name="gender" value="Female" <?php if($row['gender'] == "Female"){echo "checked"; } ?>></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue" width="335"><tr><td><div class="headingBlue">Do You Drink?</div></td></tr><tr><td>Yes<input type="radio" name="drink" value="Yes" <?php if($row['drink'] == "Yes"){echo "checked"; } ?>><br>No<input type="radio" name="drink" value="No" <?php if($row['drink'] == "No"){echo "checked"; } ?>></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue" width="335"><tr><td><div class="headingBlue">Do You Smoke?</div></td></tr><tr><td>Yes<input type="radio" name="smoke" value="Yes" <?php if($row['smoke'] == "Yes"){echo "checked"; } ?>><br>No<input type="radio" name="smoke" value="No" <?php if($row['smoke'] == "No"){echo "checked"; } ?>></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuGreen"><tr><td><div class="headingGreen">Profile Layout Code:</div><br><textarea name="css_code" rows="14" cols="75"><?php echo $row[css_code];?></textarea></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Television / Film:</div><br><textarea name="film" rows="14" cols="75"><?php echo $row[film];?></textarea></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Literature:</div><br><textarea name="literature" rows="14" cols="75"><?php echo $row[literature];?></textarea></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Music:</div><br><textarea name="music" rows="14" cols="75"><?php echo $row[music];?></textarea></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">About Me:</div><br><textarea name="aboutme" rows="14" cols="75"><?php echo $row[aboutme];?></textarea></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuBlue"><tr><td><div class="headingBlue">Friends:</div><br><textarea name="friends" rows="14" cols="75"><?php echo $row[friends];?></textarea></td></tr></table><br><br><table cellpadding="2" cellspacing="2" class="menuGreen"><tr><td><input type="submit" name="zpageUPDATE" value="-Update All-"></td></tr></table></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156479 Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 [code]<form action="" method="post">[/code]Why's ur action blank? Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156536 Share on other sites More sharing options...
techiefreak05 Posted January 9, 2007 Author Share Posted January 9, 2007 because, the script is in the page, what else do i need? Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156632 Share on other sites More sharing options...
Philip Posted January 9, 2007 Share Posted January 9, 2007 [code]<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST">[/code]Try that instead. Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156817 Share on other sites More sharing options...
techiefreak05 Posted January 9, 2007 Author Share Posted January 9, 2007 nope.. still the same... Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156862 Share on other sites More sharing options...
bljepp69 Posted January 9, 2007 Share Posted January 9, 2007 You can't nest forms. You have a form within your form so the closing tag for the nested form is really closing the first one. Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156868 Share on other sites More sharing options...
kenrbnsn Posted January 9, 2007 Share Posted January 9, 2007 Check that you are not nesting form tags. Looking at the source I see:<form><form></form></form>That is illegal HTML markup. Fix that and your forms should start to work.Ken Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156870 Share on other sites More sharing options...
trq Posted January 9, 2007 Share Posted January 9, 2007 [quote]Why's ur action blank?[/quote]A blank action will post to itself.Throughout your form you use the variable $row as though you have defined it... where [i]do[/i] you define it?How does this form fit in with your other script / function? Your form is posting to itself so.....?A word of advice. If a function seriously needs that many arguments, you need to refine your logic. At least make the function accepts an array and pass the arguments that way. That function is never going to be easy to reuse without having to go back and see what argument goes where. Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156884 Share on other sites More sharing options...
techiefreak05 Posted January 9, 2007 Author Share Posted January 9, 2007 kenrbnsn: THANKS!!! you were right about the form tags!! it works now!thorpe: The function wont need to be used again. Quote Link to comment https://forums.phpfreaks.com/topic/33418-problem-with-function/#findComment-156898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.