Jump to content

[SOLVED] Any suggestions?


ArcAiN6

Recommended Posts

I am currently in the midst of writing some code for a site I'm building, and perhaps it's because it's so late, or perhaps I've gotten in over my head. But i simply can't figure this out.

 

The code is supposed to select a user from the database by name in a drop down menu (that works fine)

display their current total of dkp (this function is also working correctly)

and then offer the admin an opportunity to update / add to the current total of DKP for the user (this is NOT working at all)

 

following is the code. any help in this matter would be most appreciated.

 

Thank you for your time :)

 

ArcAiN6

 

 

<?
// Connect database
mysql_connect("localhost","myDBuser","myDBpass");
mysql_select_db("myDBname");

// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($_GET['select'])&& $_GET['select'] !=""){
$select=$_GET['select'];
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> ">
<h4>Select Toon's Name :</h4>
<select name="select">
<option value="">--- Select ---</option>
<?
// Get records from database (table "e107_user_extended").
$list=mysql_query("select * from e107_user_extended order by user_extended_id asc");

// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['user_extended_id']; ?>"
<? if($row_list['user_extended_id']==$select){ echo "selected"; } ?>>
<? echo $row_list['user_toonm']; ?></option>
<?
// End while loop.
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>
<hr>
<p>
<?
// If you have selected from list box.
if(isset($select)&&$select!=""){

// Get records from database (table "e107_user_extended").
$result=mysql_query("select * from e107_user_extended where user_extended_id='$select'");
while ($row = mysql_fetch_assoc($result)) {
echo ' User - Current DKP<strong>' . '<p>' . $row['user_toonm'] . " - " . $row['user_DKP'] . '</p>';
}
}
echo '<br><br><h3>Update this Toon\'s DKP\?<h3><br>';

if(isset($_POST['dkp'])&& $_POST['dkp'] !=""){
$dkp=$_POST['dkp'];
}
?>
<form id='form2' name='form2' action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label><h3>Type total DKP earned here:</h3><br />
(for example joe has 10dkp, and he earned 3 dkp tonight, input 3 into the field)<br>
<input name="dkp" type="text" value="0" size="8" maxlength="8">
</label><br />
<input type="submit" value="SUBMIT" />
</form>
<?
//check that the input is actually a number

// Execute update
$sql = 'UPDATE user_extended SET user_DKP = user_DKP + $dkp WHERE user_extended_id =  $select';
// Close database connection.
mysql_close();
?>
</p>
</body>
</html>


Link to comment
Share on other sites

ok... so i was having a tard moment... the database name wasn't correct, and also there was nothing to actually empliment the changes...

 

now that i've solved those two problems, i'm getting an error message... following is an altered post (evidently 15mins is too long to wait to modify my post above :( )

 

I am currently in the midst of writing some code for a site I'm building, and perhaps it's because it's so late, or perhaps I've gotten in over my head. But i simply can't figure this out.

 

The code is supposed to select a user from the database by name in a drop down menu (that works fine)

display their current total of dkp (this function is also working correctly)

and then offer the admin an opportunity to update / add to the current total of DKP for the user (this is NOT working at all)

 

it also returns an error " Error adding submitted DKP: Unknown column '$select' in 'where clause' "

 

following is the code. any help in this matter would be most appreciated.

 

Thank you for your time :)

 

ArcAiN6

 

 

<?
// Connect database
mysql_connect("localhost","myDBusername","myDBpass");
mysql_select_db("myDBname");

// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($_GET['select'])&& $_GET['select'] !=""){
$select=$_GET['select'];
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> ">
<h4>Select Toon's Name :</h4>
<select name="select">
<option value="">--- Select ---</option>
<?
// Get records from database (table "e107_user_extended").
$list=mysql_query("select * from e107_user_extended order by user_extended_id asc");

// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['user_extended_id']; ?>"
<? if($row_list['user_extended_id']==$select){ echo "selected"; } ?>>
<? echo $row_list['user_toonm']; ?></option>
<?
// End while loop.
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>
<hr>
<p>
<?
// If you have selected from list box.
if(isset($select)&&$select!=""){

// Get records from database (table "e107_user_extended").
$result=mysql_query("select * from e107_user_extended where user_extended_id='$select'");
while ($row = mysql_fetch_assoc($result)) {
echo ' User - Current DKP<strong>' . '<p>' . $row['user_toonm'] . " - " . $row['user_DKP'] . '</p>';
}
}
echo '<br><br><h3>Update this Toon\'s DKP?<h3><br>';

if(isset($_POST['dkp'])&& $_POST['dkp'] !=""){
$dkp=$_POST['dkp'];
}
?>
<form id='form2' name='form2' action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label><h3>Type total DKP earned here:</h3><br />
(for example joe has 10dkp, and he earned 3 dkp tonight, input 3 into the field)<br>
<input name="dkp" type="text" value="0" size="8" maxlength="8">
</label><br />
<input type="submit" value="SUBMIT" />
</form>
<?
//check that the input is actually a number

// Execute update
$sql = 'UPDATE e107_user_extended SET user_DKP = user_DKP + $dkp WHERE user_extended_id =  $select';
if (@mysql_query($sql)) {
     echo '<p>DKP has been added.</p>';
   } else {
     echo '<p>Error adding submitted DKP: ' .
         mysql_error() . '</p>';
   }

// Close database connection.
mysql_close();
?>
</p>
</body>
</html>

Link to comment
Share on other sites

In here:

$sql = 'UPDATE user_extended SET user_DKP = user_DKP + $dkp WHERE user_extended_id =  $select';

 

Use double quotes when evaluating variables inside a string, like this:

 

$sql = "UPDATE user_extended SET user_DKP = user_DKP + $dkp WHERE user_extended_id =  $select";

 

or else escape the string like in the rest of your code:

 

$sql = 'UPDATE user_extended SET user_DKP = user_DKP + '.$dkp.' WHERE user_extended_id =  '.$select;

 

 

And you are not "executing" that sql statement anywhere, as in your missing this:

mysql_query($sql);

Link to comment
Share on other sites

hrm.... that did seem to change the error message a bit ;)

 

now i'm recieving:

 

rror adding submitted DKP: 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 'WHERE user_extended_id =' at line 1

 

and if i try to continue and select a user i recieve this error:

 

Error adding submitted DKP: 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 'WHERE user_extended_id = 1' at line 1

 

i think after i fix the syntax issue, i'll need to do something to hide / not parse the rest of the code untill a user is selected, and an input posted by the user. as it sits now, it appears to be trying to do the whole script on every loading of the page..

Link to comment
Share on other sites

crap...

 

not fixed...

//is NOT correct... this actually selects the first id in the table... 
$sql = "UPDATE e107_user_extended SET user_DKP = user_DKP + '$dkp' WHERE user_extended_id = 1";

//DOES NOT WORK
$sql = "UPDATE e107_user_extended SET user_DKP = user_DKP + '$dkp' WHERE user_extended_id = '$select' "; 

//also does not work
$sql = "UPDATE e107_user_extended SET user_DKP = user_DKP + '$dkp' WHERE user_extended_id = '.$select.' "; 

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.