Jump to content

Recommended Posts

<?php
$user = "user";
$pass = "test";
mysql_connect('localhost','root','michael1');
mysql_select_db('LogPass');
$sql="INSERT INTO Table1 VALUES ('$ulog', '$plog')";
$rs=mysql_query($sql);
header("Location: http://localhost/proj/");
?>

I've been having some problems getting this code to add a user and pass into my db... It worked perfectly in odbc, so I know it works. There is no error message, but the values do not get inserted...

Link to comment
https://forums.phpfreaks.com/topic/84336-mysql-value-adding-problem/
Share on other sites

$sql="INSERT INTO `Table1` VALUES ('$ulog', '$plog')";

 

Where are the columns set for Table 1?

 

 

 

 

Try this

 

<?php
$user = "user";
$pass = "test";
mysql_connect('localhost','root','michael1') or die(mysql_error());
mysql_select_db('LogPass')or die(mysql_error());
$sql="INSERT INTO `Table1` (username,password) VALUES ('$ulog', '$plog')";
$rs=mysql_query($sql)or die(mysql_error());
header("Location: http://localhost/proj/");
?>

 

edit: Oops. someone already posted, sorry.

You must list the columns if you are not inserting a value into each column. If you only have two columns in the table and you are inserting a value into each column, you don't need to list the columns.

 

Because you get a database selected error message from the query statement, it means that your mysql_select_db() statement is incorrect. Fix that problem first.

try that but even it work's sort your insert out mate....

<?php
$user = "user";
$pass = "test";
$db=mysql_connect('localhost','root','michael1');
mysql_select_db('LogPass',$db);
$sql="INSERT INTO Table1 VALUES ('$ulog', '$plog')";
$rs=mysql_query($sql)or die(mysql_query());
header("Location: http://localhost/proj/");
?>

Where are your values for the INSERT?

 

Plus

 

$sql="INSERT INTO Table1 VALUES ('$ulog', '$plog')";

 

That is wrong.

 

Read this

 

http://www.w3schools.com/php/php_mysql_insert.asp

 

it not wrong he not using the first varable defention

 

you dont need to tell the varables what thay are if u dont want to....#

 

it bad but it still works

try this mate should insert your name password and goto google

 

it will work if in your databae you got ulog and plog in a table as one table,,,,,

 

 

<?php

$user="user";
$pass="test";

$db=mysql_connect("localhost","root","michael1");
$result=mysql_select_db("LogPass",$db);

$user=addslashes($_POST['user']);
$pass=addslashes($_POST['pass']);

if(isset($user)||($pass))){

$sql="INSERT INTO Table1 (ulog,plog) VALUES ('$user', '$pass')";
$rs=mysql_query($sql)or die(mysql_query());

header("Location: http://www.google.com");
}
?>

Considering that the original problem was that there was no error checking on any of the mysql function calls to get php/mysql to tell exactly which one and why it was failing and that once some error checking was added to the mysql_query(), which resulted in the only addition information that there was no database selected, this thread has gotten off topic of helping with the problem of connecting to the database server, selecting a database, and executing a query.

 

Correct the actual query once it is executing, but the code is not even reaching that point yet. The OP stated the $ulog/$plog/$user/$pass was a typo. Without knowing what the column names are, posting code with guesses about what the names are and if a form is involved, is just adding confusion.

Sorry, been away for a while... DB Layout:

 

Name: LogPass

Table: Table1

Headers: Username, Password

 

I was only posting the script but the form was just your basic html page and I prefer to get the script working before integrating it into the form...

 

The code I was using was this one:

 

<?php

$user = "user";

$pass = "test";

mysql_connect('localhost','root','michael1') or die(mysql_error());

mysql_select_db('LogPass')or die(mysql_error());

$sql="INSERT INTO `Table1` (username,password) VALUES ('$user', '$pass')";

$rs=mysql_query($sql)or die(mysql_error());

header("Location: http://localhost/proj/");

?>

 

Thanks to PhpSensei

 

I was still having the No Database Selected error though. Is it a problem having MySql and xampp installed if Mysql has a diff. port and service name?

ya it should be

 

<?php
$user = "user";
$pass = "test";
mysql_connect('localhost','root','michael1') or die(mysql_error());
mysql_select_db('LogPass';
$sql="INSERT INTO `Table1` (username,password) VALUES ('$user', '$pass')";
$rs=mysql_query($sql)or die(mysql_error());
header("Location: http://localhost/proj/");
?>

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.