SQL and PHP in wordpress site to gather data for the current user logged in
-
This is my php so far and I get the error message: Could not update data: Query was empty. Any suggestions? And also could someone show me how to display what the grade is in the html form. Thanks
<?php
if(isset($_POST[‘update’]))
{
$dbhost = ‘localhost’;
$dbuser = ‘qwoif’;
$dbpass = ‘lhovys’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die(‘Could not connect: ‘ . mysql_error());
}$user_id = get_current_user_id();
$grade = $_POST[‘grade’];
$sql = mysql_query(“UPDATE wp_gsga_users SET grade = $grade WHERE ID = $user_id”);
mysql_select_db(‘my_db’);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die(‘Could not update data: ‘ . mysql_error());
}
echo “Updated data successfully\n”;
mysql_close($conn);
}
else
{
?>
<form method=”post” action=”<?php $_PHP_SELF ?>”>
<table width=”400″ border=”0″ cellspacing=”1″ cellpadding=”2″>
<tr>
<td width=”100″>Grade</td>
<td><input name=”grade” type=”text” id=”grade”></td>
</tr>
<input name=”update” type=”submit” id=”update” value=”Update”>
</td>
</tr>
</table>
</form>
<?php
}
?>
- The topic ‘SQL and PHP in wordpress site to gather data for the current user logged in’ is closed to new replies.