Jump to content

Updateing Mysql in PHP


leequalls

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.