Jump to content

Problem with Function


techiefreak05

Recommended Posts

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 working

THE FUNCTION:
[code]
<?php
function 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]
<?php
doUpdate($_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]

Link to comment
Share on other sites

Tahnks for the replies, but i tried to no avail .. Here is how i use the functon as of right now:

[code]
<?php
doUpdate($_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]
<?php
function 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'] . "' )
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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".
Link to comment
Share on other sites

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>

<?php
if($_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]
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.