Forum Moderators: coopster

Message Too Old, No Replies

Getting MySQL to query using PHP varibles

>_<

         

maexus

5:07 pm on Aug 18, 2005 (gmt 0)

10+ Year Member



All it does is when I edit a field and click ok, it says it updated successfully. I doesn't though. This page has been killing me and I don't know why it doesn't work.

<?php

if (!isset($_POST['editID']) &&!isset($_POST['submit']))
{
echo
'
<p>Please enter the User ID that you would like to edit.</p>
<form action="edituser.php" method="post">
<input type="text" name="editID">
<input type="submit" value="Edit User">
</form>
';
} else {
$editID = $_POST['editID'];

$server = "";
$userid = "";
$passwd = "";
$database = "";

$connect = mysql_connect("$server", "$userid", "$passwd") or die ("MySQL Error. Contact an Admin");
mysql_select_db("$database") or die ("Database Error. Contact an Admin");
if (!isset($_POST['submit'])) {$result = mysql_query("SELECT * FROM users WHERE id = '".$editID."'") or die ("No such user");
$info = mysql_fetch_array($result);}

if (isset($_POST['submit'])) {
$update = mysql_query("UPDATE users SET
userName = '".$_POST['userName']."',
userLevel = '".$_POST['userLevel']."',
credits = '".$_POST['credits']."',
schoolEmailFront = '".$_POST['schoolEmailFront']."',
schoolEmailEnd = '".$_POST['schoolEmailEnd']."',
contactEmail = '".$_POST['contactEmail']."',
age = '".$_POST['age']."',
city = '".$_POST['city']."',
zipCode = '".$_POST['zipCode']."',
contactScreenNameAIM = '".$_POST['contactScreenNameAIM']."',
contactScreenNameYahoo = '".$_POST['contactScreenNameYahoo']."',
contactScreenNameMSN = '".$_POST['contactScreenNameMSN']."',
websiteURL = '".$_POST['websiteURL']."',
heightFeet = '".$_POST['heightFeet']."',
heightInch = '".$_POST['heightInch']."',
weight = '".$_POST['weight']."',
hairColor = '".$_POST['hairColor']."',
eyeColor = '".$_POST['eyeColor']."',
gender = '".$_POST['gender']."',
tattoos = '".$_POST['tattoos']."',
piercings = '".$_POST['piercings']."',
skinTone = '".$_POST['skinTone']."',
bio = '".$_POST['bio']."',
interests = '".$_POST['interests']."',
smoker = '".$_POST['smoker']."',
drinker = '".$_POST['drinker']."',
sexuality = '".$_POST['sexuality']."',
starSign = '".$_POST['starSign']."',
maritalStatus = '".$_POST['maritalStatus']."',
seekingFriends = '".$_POST['seekingFriends']."',
seekingDating = '".$_POST['seekingDating']."',
seekingRoommates = '".$_POST['seekingRoommates']."',
seekingStudyGroups = '".$_POST['seekingStudyGroups']."'
WHERE id = '".$editID."'") or die (mysql_error());
echo 'Update Sucessful';
}

#mysql_close($connect) or die ("Could not close MySQL connection. Contact an Admin");
?>
<form action="edituser.php" method="post">
<lots of html for the form was removed - jatar_k>
<input type="submit" name="submit" value="Edit User">
</form>
<?php
}
?>
</body>
</html>

[edited by: jatar_k at 3:40 pm (utc) on Aug. 19, 2005]

jatar_k

3:47 pm on Aug 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld maexus,

the way I understand the logic

the first time someone comes to this form they get the form to select the user id

<p>Please enter the User ID that you would like to edit.</p>
<form action="edituser.php" method="post">
<input type="text" name="editID">
<input type="submit" value="Edit User">
</form>

then that submits to itself (I assume edituser.php is this script).

It then shows the edit form. The one thing I notice is at no time does it write that editID into the second form. I don't think it knows what that id is. You should probably write that var into the big form as a hidden var.

you could also echo your full sql statement to the browser to see if that is actually the case.

maexus

7:58 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



Actually. Now that I look at it that does make sense. Let me try that out.

maexus

12:12 am on Aug 20, 2005 (gmt 0)

10+ Year Member



Thanks. That was it. Works not. Thanks!