leequalls Posted May 29, 2009 Share Posted May 29, 2009 I am trying to update the mysql data when someone logs in the code below will not update the database anyone have any suggestions. I do not get any error codes. mysql_query("UPDATE DJ SET lastaccess='$datetime' WHERE username=$username"); mysql_query("UPDATE DJ SET ip_address='$ip' WHERE username=$username"); Link to comment https://forums.phpfreaks.com/topic/160097-updateing-mysql-in-php/ Share on other sites More sharing options...
Michdd Posted May 29, 2009 Share Posted May 29, 2009 mysql_query("UPDATE `DJ` SET lastaccess='$datetime', ip_address='$ip' WHERE username='$username'"); Needed to put '' around $username, also only one query needed. Link to comment https://forums.phpfreaks.com/topic/160097-updateing-mysql-in-php/#findComment-844664 Share on other sites More sharing options...
justAnoob Posted May 29, 2009 Share Posted May 29, 2009 Here is a update script that I use for some stuff. <?php //error_reporting(E_ALL); //ini_set('display_errors',1); session_start(); require 'connection.php'; if(isset($_POST['submit'])) { $item_name = mysql_real_escape_string($_POST['item_name']); $description = mysql_real_escape_string($_POST['description']); $in_return = mysql_real_escape_string($_POST['in_return']); $idnumber = mysql_real_escape_string($_POST['id']); $sql = "UPDATE table_name_here SET item_name = '$item_name', description = '$description', in_return = '$in_return' WHERE id = '$idnumber'"; if(mysql_query($sql)) { $_SESSION['updatecomplete'] = "Update Complete!"; header("location: http://www.--------.com/-------.php"); exit(); } else { $_SESSION['updateerror'] = "Error. Please try again later."; header("location: http://www.------.com/------.php"); exit(); } } ?> Link to comment https://forums.phpfreaks.com/topic/160097-updateing-mysql-in-php/#findComment-844666 Share on other sites More sharing options...
leequalls Posted May 29, 2009 Author Share Posted May 29, 2009 mysql_query("UPDATE `DJ` SET lastaccess='$datetime', ip_address='$ip' WHERE username='$username'"); Needed to put '' around $username, also only one query needed. Thanks This fixed the problem just needed the "$username" Link to comment https://forums.phpfreaks.com/topic/160097-updateing-mysql-in-php/#findComment-844671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.