Erindesign 08-22-2007, 12:04 AM Hey all,
I have profile_form.php which is basically a form/updater. The form submits info to the same file via a button called update.
Now, at the top of the form, I have a simple update script for mysql but it won't excecute. it gives me a few errors like:
Notice: Use of undefined constant update - assumed 'update' in /home/profile_form.php on line 17
The Form:
<form method="post">
<input blah blah .... />
<input blah blah .... />
<input blah blah .... />
<input type="submit" name="update" value="Update"/>
</form>
Then the action:
if (isset($_POST[update]) && $_POST[update]!=""){
DO STUFF
}
NancyJ 08-22-2007, 12:19 AM The message is telling you exactly what the problem is - you don't have a constant defined called update but you have tried to use it. It then assumes you meant the string 'update' and uses that instead.
//this is a constant, it differs from a variable because it is not prefixed with a $
my_var
//this is a string, it differs from a constant because it is enclosed in quotation marks
'my_var'
Array keys are strings, which may be contained in constants, variables or given directly as string.
To get rid of the warning change your code to:
if(isset($_POST['update']) && $_POST['update']!="")
kbluhm 08-22-2007, 12:20 AM Array keys are integers or strings, and nothing else:
if (isset($_POST['update']) && $_POST['update']!=""){
CFMaBiSmAd 08-22-2007, 12:23 AM The notice errors are because the syntax - $_POST[update] means that PHP must first look for a defined constant named update, then when it does not find one, it generates and logs the error, then looks for an array index named update. The proper syntax is - $_POST['update']
However, php makes a correct assumption that you meant $_POST['update'] and continues execution. If your code is not working, it is not directly related to the missing quotes, and is likely due to some other logic problem.
You would need to post your code to get any specific help with why it is not working.
Erindesign 08-22-2007, 12:51 AM I still get error, so here, blow my brains out:
<?php
$check=$_POST['update'];
if (isset($check) && $check!='' && $check=='update'){
$userid=$_POST['memid'];
$name=$_POST['firstname'];
$gender=$_POST['gjinia'];
$age=$_POST['mosha'];
$location=$_POST['banimi'];
$msn=$_POST['msn'];
$aim=$_POST['aim'];
$website=$_POST['website'];
$interest=$_POST['interesat'];
$update = mysql_query("Update gallarific_users set firstname='$name', gjinia='$gender', mosha='$age', banimi='$location', msn='$msn', aim='$aim', website='$website', interesat='$interest' userid = '$userid'");
}
?>
<form method="post" action="self">
<input type="hidden" name="memid" id="memid" value="<?php echo $user[userid]; ?>" size="30"/>
<table width="90%" border="0">
<tr>
<td width="150" align="right" class="padlr"><strong>Pseudonimi:</strong></td>
<td><?php echo $user["username"]; ?></td>
</tr>
<tr>
<td width="150" align="right" class="padlr"><strong>Fjalekalimi:</strong></td>
<td><?php echo $user["password"]; ?></td>
</tr>
<tr>
<td width="150" align="right" class="padlr"><strong>Adresa E-Mail:</strong></td>
<td><?php echo $user["email"]; ?></td>
</tr>
<tr>
<td width="150" align="right" class="padlr"><strong>Emri Juaj: </strong></td>
<td><input type="text" name="firstname" id="firstname" size="30" value="<?php echo $user["firstname"]; ?>" /></td>
</tr>
<tr>
<td width="150" align="right" class="padlr">Gjinia: </td>
<td>
<select name="gjinia" id="gjinia">
<option value="$user[gjinia]"><?php echo $user["gjinia"]; ?></option>
<option value="Mashkull">Mashkull</option>
<option value="Femer">Femer</option>
<option value="N/A">Sta Them</option>
</select>
</td>
</tr>
<tr>
<td width="150" align="right" class="padlr">Mosha: </td>
<td>
<select name="mosha" id="mosha">
<option value="$user[mosha]"><?php echo $user["mosha"]; ?></option>
<option value="10-15">10-15</option>
<option value="16-20">16-20</option>
<option value="21-25">21-25</option>
<option value="26-30">26-30</option>
<option value="31-35">31-35</option>
<option value="35-40">35-40</option>
<option value="40+">40+</option>
</select>
</td>
</tr>
<tr>
<td width="150" align="right" class="padlr">Vendbanimi: </td>
<td><input type="text" name="banimi" id="banimi" size="30" value="<?php echo $user["banimi"]; ?>" /></td>
</tr>
<tr>
<td width="150" align="right" class="padlr">MSN Messenger: </td>
<td><input type="text" name="msn" id="msn" size="30" value="<?php echo $user["msn"]; ?>" /></td>
</tr>
<tr>
<td width="150" align="right" class="padlr">AIM Messenger: </td>
<td><input type="text" name="aim" id="aim" size="30" value="<?php echo $user["aim"]; ?>" /></td>
</tr>
<tr>
<td width="150" align="right" class="padlr">Hi5 / MySpace: </td>
<td><input type="text" name="website" id="website" size="30" value="<?php echo $user["website"]; ?>" /></td>
</tr>
<tr>
<td width="150" align="right" class="padlr">Ineteresat: </td>
<td><textarea name="interesat" id="interesat" rows="3" cols="30"/><?php echo $user["ineteresat"]; ?></textarea></td>
</tr>
<tr>
<td width="150" align="right" class="padlr"> </td>
<td><input type="submit" id="update" name="update" value="update"/></td>
</tr>
</table>
</form>
Fumigator 08-22-2007, 12:57 AM You missed this one
<input type="hidden" name="memid" id="memid" value="<?php echo $user[userid]; ?>" size="30"/>
Inigoesdr 08-22-2007, 12:57 AM Change
<form method="post" action="self">
<input type="hidden" name="memid" id="memid" value="<?php echo $user[userid]; ?>" size="30"/>
To
<form method="post" action="self">
<input type="hidden" name="memid" id="memid" value="<?php echo $user['userid']; ?>" size="30"/>
Erindesign 08-22-2007, 01:18 AM still nothing.... :(
I changed the action="self" to action="profile.php" which is basically self.
I also changed what you guys said, but it didn't work.
Inigoesdr 08-22-2007, 01:27 AM Post the error?
Erindesign 08-22-2007, 01:30 AM Notice: Undefined index: update in /home/.nigan/steganos/fotokoment.com/themes/black/profile_form.php on line 17
Line 17 is right under the first if statement.
CFMaBiSmAd 08-22-2007, 01:31 AM action="self" has no meaning. This either must be an empty value - action='' or action="" or it must be a relative or absolute URL.
Erindesign 08-22-2007, 01:45 AM which is why I changed it. Now I get this error, and it doesnt update the info in mysql.
Notice: Undefined index: update in /home/.nigan/steganos/fotokoment.com/themes/black/profile_form.php on line 17
Nightfire 08-22-2007, 01:56 AM interesat='$interest', userid = '$userid'"
Missing a comma here. Doubt it's what's causing your problem though
Erindesign 08-22-2007, 02:15 AM It wasn't the problem. I put a little check in the update, and it doesnt update:
if($update){echo updated;}
else{echo error;}
and everytime I submit the form, it gives me the error...
fl00d 08-22-2007, 02:19 AM Could this be it?
$check=$_POST['update'];
if (isset($check) && $check!='' && $check=='update')
With that statement you're checking if $check is equal to 'update'. And since you said $check is $_POST['update'], its checking if $_POST['update'] contains the text "update". And since the button does NOT contain "update", the SQL query doesn't run.
I just ran a test using the following code and nothing happened:
<?php
$check=$_POST['update'];
if(isset($check) && $check!="" && $check=="update"){
echo "Everything is returning true";
}else{
echo "<form action='check.php' method='post'>
<input type='submit' name='update' value='update'>
</form>";
}
?>
I changed it to:
<?php
$check=$_POST['update'];
if(isset($check) && $check!=""){
echo "Everything is returning true";
}else{
echo "<form action='check.php' method='post'>
<input type='submit' name='update' value='Update'>
</form>";
}
?>
and it worked fine. Try that I think it will work.
Hope this helped
-fl00d
Nightfire 08-22-2007, 02:20 AM Don't you want to have a where clause in the query too? You're not saying what you want updating and I'm sure it'll either not do a thing, or update every single record to what's entered.
$update = mysql_query("UPDATE gallarific_users SET firstname='".$name."', gjinia='".$gender."', mosha='".$age."', banimi='".$location."', msn='".$msn."', aim='".$aim."', website='".$website."', interesat='".$interest."', userid = '".$userid."' WHERE userid='".$_POST['userid']."'");
Erindesign 08-22-2007, 02:28 AM ok here is what i got so far out of this.
1. i suck at forms :P lets get serious at #2 :D.
2. When the form isnt submited, so I only go to profile.php, I get that error that update is undefined bla bla.
3. When form is submitted, I don't get a php error, but my UPDATE isn't happening in the database. It just echoes out the error part of my check :(
ALso, the comma that you found missing was supposed to be a where. I just want the stuff put in where the userid=userid :D not put in a new userid. Changed that.
still same crap... the $check and update stuff is good, but when I check if($update) it isn't true. meaning, theres a problem in the mysql query and here is mine:
$update = mysql_query("UPDATE gallarific_users SET firstname='".$name."', gjinia='".$gender."', mosha='".$age."', banimi='".$location."', msn='".$msn."', aim='".$aim."', website='".$website."', interesat='".$interest."' WHERE userid='".$userid."'");
Fumigator 08-22-2007, 04:19 AM echo mysql_error(), also you should echo your query string (after it has been built with all the variables) but to do that you need to assign the query string to a variable and echo the variable.
$query = "UPDATE gallarific_users SET firstname='".$name."', gjinia='".$gender."', mosha='".$age."', banimi='".$location."', msn='".$msn."', aim='".$aim."', website='".$website."', interesat='".$interest."' WHERE userid='".$userid."'"
$update = mysql_query($query);
if (!$update) {
die("Query error. query string is $query and error is ".mysql_error());
}
Erindesign 08-22-2007, 01:53 PM Fumigator you're god... It turned out I had misspelled "interesat" in the database.
Now the actions work, but I still get this error:
Notice: Undefined index: update in /home/.nigan/steganos/fotokoment.com/themes/black/profile_form.php on line 17
Any way of getting rid of it? Maybe not even use the $_POST[update] but something else?
aedrin 08-22-2007, 05:07 PM Look at line 17 and look for any opening bracket ([) not followed by a ' or ".
Or copy that line in here so that we can check it out.
Perhaps you should use an IDE with some syntax coloring/error checking. They will generally tell you where the problem is, as these are easy to fix.
http://www.eclipse.org/pdt/
Erindesign 08-22-2007, 08:11 PM heres my stupid line 17 :(
$check=$_POST['update'];
I tried action="profile.php?update=true" and $check=$_GET['update']. It still gave me the same error.
Erindesign 08-22-2007, 08:18 PM Never mind guys, thanx all. I fixed it.
instead of declaring $check=$_POST['update'] I just used $_POST['update'] in the if statement. It doesn't seem to give the error any longer.
|
|