Jump to content

Insert into database


merlin371

Recommended Posts

Hey guys sorry if this is a really noobie question but i tried everything and i cant see why it wont work, I have a form that would send the information to another page that in theory puts the data into the database however it does nothing, it wont even give me an error, this is what i have on the page.

 

include("config.php");
$db_link = mysql_connect($db_server, $db_uname, $db_pass);

mysql_select_db($db_name, $db_link);

if (isset($_POST['user']))
{
	$user = $_POST['user'];
	$date = $_POST['date'];
	$time = $_POST['time'];
	$device = $_POST['device'];
	$info = $_POST['info'];
	mysql_query ("INSERT INTO `alanz`.`logs` (`id`, `user`, `date`, `time`, `device`, `info`) VALUES (NULL, '".$user."', '".$date."', '".$time."', '".$device."', '".$info."');", $db_link);
}

 

any idea why it wont do anything?

 

thanks

Link to comment
Share on other sites

You have nothing in that script that would give you any errors if something was not right. I suspect either the POST value is not set or there is a database error. Try this:

 

<?php
   
include("config.php");
$db_link = mysql_connect($db_server, $db_uname, $db_pass)
   or die ("unable to connect to database server");
   
mysql_select_db($db_name, $db_link)
   or die ("unable to select to database");
   
if (!isset($_POST['user']))
{
   echo "The post value for 'user' is not set.";
}
else
{
   $user   = mysql_real_escape_string(trim($_POST['user']));
   $date   = mysql_real_escape_string(trim($_POST['date']));
   $time   = mysql_real_escape_string(trim($_POST['time']));
   $device = mysql_real_escape_string(trim($_POST['device']));
   $info   = mysql_real_escape_string(trim($_POST['info']));

   $query = "INSERT INTO `alanz`.`logs` (`user`, `date`, `time`, `device`, `info`)
             VALUES ('{$user}', '{$date}', '{$time}', '{$device}', '{$info}')"
   mysql_query ($query, $db_link)
      or die ("Query:<br />{$query}<br />Error:<br />" . mysql_error());
}
   
?>

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.