Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page Inserting tabular data into mysql database
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
blackdogruns's Avatar
Member
blackdogruns is an unknown quantity at this point
 
Posts: 75
Join Date: Dec 2011
Location: Salem, Oregon
Exclamation Inserting tabular data into mysql database - 01-04-2012, 06:36 PM

I'm looking to insert data into one of my mysql databases for logging in purposes. However, it's not working out. Any ideas?
PHP Code:
<?php

//////////////////////  Flood Control /////////////////

$stamp time();
$logFile 'contact_flood.dat';
    
$old= @file_get_contents($logFile);
        
$temp $old+60;
        
         if (
$stamp $temp) {
        
header('server-busy-wait-a-minute.php');// dump out location
        
die();
            }
        else{

$fh fopen($logFile'w');
fwrite($fh$stamp);
fclose($fh);}

//////////////////////  End Flood Control /////////////////


$host="mysql17.000webhost.com"// Host name 
$username="a6072331_index"// Mysql username 
$password="PASSWORD modified by Moderator"// Mysql password 
$db_name="a6072331_index"// Database name 
$tbl_name="logindata"// Table name 

// Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

INSERT INTO $tbl_name (usernamepasswordemailnameage);
VALUES ($_REQUEST['username'], $_REQUEST['password'], $_REQUEST['email'], $_REQUEST['name'], $_REQUEST['age']);

?>
This is the code i have so far.

Last edited by d3iti; 01-04-2012 at 07:10 PM. Reason: It is not allow write password
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,537
Join Date: Jul 2009
Location: Spain
Default 01-04-2012, 07:17 PM

In your code you need to run the query.
Also had a few problems with the connection (the connection variables should not be quoted).

Try the code below and tell us, though I'm not sure the $ _REQUEST array work.

Tell us if you get any error messages.

PHP Code:
<?php
//////////////////////  Flood Control /////////////////
$stamp time();
$logFile 'contact_flood.dat';
    
$old= @file_get_contents($logFile);
        
$temp $old+60;
        
         if (
$stamp $temp) {
        
header('server-busy-wait-a-minute.php');// dump out location
        
die();
            }
        else{

$fh fopen($logFile'w');
fwrite($fh$stamp);
fclose($fh);}

//////////////////////  End Flood Control /////////////////

$host="mysql17.000webhost.com"// Host name 
$username="a6072331_index"// Mysql username 
$password="PASSWORD modified by Moderator"// Mysql password 
$db_name="a6072331_index"// Database name 
$tbl_name="logindata"// Table name 

// Connect to server and select databse.
mysql_connect($host$username$password)or die("cannot connect"); 
mysql_select_db($db_name)or die("cannot select DB");

$sql="INSERT INTO $tbl_name (username, password, email, name, age);
VALUES ($_REQUEST['username'], $_REQUEST['password'], $_REQUEST['email'], $_REQUEST['name'], $_REQUEST['age'])"
;

mysql_query($sql) or die ('Error SQL ! '.$sql.'<br/>'.mysql_error());
mysql_close();

?>
P. S. I modified your previous post to hide the password database. You should change when you go up the php code above.


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma
Reply With Quote
(#3 (permalink))
Old
blackdogruns's Avatar
Member
blackdogruns is an unknown quantity at this point
 
Posts: 75
Join Date: Dec 2011
Location: Salem, Oregon
Default 01-05-2012, 12:26 AM

I just tried that script and got this error message,
"Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a6072331/public_html/otherpages/adduser.php on line 31"

btw: best moderators ever
Reply With Quote
(#4 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,537
Join Date: Jul 2009
Location: Spain
Default 01-05-2012, 07:18 AM

In line 31 there is a semicolon that should not appear:
PHP Code:
$sql="INSERT INTO $tbl_name (username, password, email, name, age); 
Remove this semicolon and try again.
PHP Code:
$sql="INSERT INTO $tbl_name (username, password, email, name, age) 
Line 31 and line 32 should be a single line


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma
Reply With Quote
(#5 (permalink))
Old
blackdogruns's Avatar
Member
blackdogruns is an unknown quantity at this point
 
Posts: 75
Join Date: Dec 2011
Location: Salem, Oregon
Default 01-05-2012, 03:47 PM

I tried that and still got the same error message. I changed my input data to variables and stated them before the "INSERT INTO". Now I'm getting this message,
"Parse error: syntax error, unexpected T_STRING in /home/a6072331/public_html/otherpages/adduser.php on line 40"

Here is my code so far,

<?php
////////////////////// Flood Control /////////////////
$stamp = time();
$logFile = 'contact_flood.dat';
$old= @file_get_contents($logFile);
$temp = $old+60;

if ($stamp < $temp) {
header('server-busy-wait-a-minute.php');// dump out location
die();
}
else{

$fh = fopen($logFile, 'w');
fwrite($fh, $stamp);
fclose($fh);}

////////////////////// End Flood Control /////////////////


$host="mysql17.000webhost.com"; // Host name
$username="a6072331_index"; // Mysql username
$password="thanks for reminding me"; // Mysql password
$db_name="a6072331_index"; // Database name
$tbl_name="logindata"; // Table name

$username = $_REQUEST['username']; // Username
$password = $_REQUEST['password']; // Password
$email = $_REQUEST['email']; // Email
$name = $_REQUEST['name']; // Name
$age = $_REQUEST['age']; // Age

// Connect to server and select databse.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");

$sql="INSERT INTO $tbl_name (username, password, email, name, age)
VALUES ($username, $password, $email, $name, $age)"

mysql_query($sql) or die ('Error SQL ! '.$sql.'<br/>'.mysql_error())
mysql_close()

?>

Last edited by blackdogruns; 01-05-2012 at 03:49 PM.
Reply With Quote
(#6 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,537
Join Date: Jul 2009
Location: Spain
Default 01-05-2012, 05:56 PM

Line 37 and line 38 should be a single line:
PHP Code:
<?php
////////////////////// Flood Control /////////////////
$stamp time();
$logFile 'contact_flood.dat';
$old= @file_get_contents($logFile);
$temp $old+60;

if (
$stamp $temp) {
header('server-busy-wait-a-minute.php');// dump out location
die();
}
else{

$fh fopen($logFile'w');
fwrite($fh$stamp);
fclose($fh);}

////////////////////// End Flood Control /////////////////


$host="mysql17.000webhost.com"// Host name 
$username="a6072331_index"// Mysql username 
$password="thanks for reminding me"// Mysql password 
$db_name="a6072331_index"// Database name 
$tbl_name="logindata"// Table name 

$username $_REQUEST['username']; // Username
$password $_REQUEST['password']; // Password
$email $_REQUEST['email']; // Email
$name $_REQUEST['name']; // Name
$age $_REQUEST['age']; // Age

// Connect to server and select databse.
mysql_connect($host$username$password)or die("cannot connect"); 
mysql_select_db($db_name)or die("cannot select DB");
// ****************    Next lines 37 and 38 are single line finished by ; 
$sql="INSERT INTO $tbl_name (username, password, email, name, age) VALUES ($username, $password, $email, $name, $age)";

mysql_query($sql) or die ('Error SQL ! '.$sql.'<br/>'.mysql_error());
mysql_close();

?>


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma
Reply With Quote
(#7 (permalink))
Old
blackdogruns's Avatar
Member
blackdogruns is an unknown quantity at this point
 
Posts: 75
Join Date: Dec 2011
Location: Salem, Oregon
Default 01-05-2012, 06:12 PM

Sweet, thanks d3iti for all your help. KARMA FOR YOU
Reply With Quote
(#8 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,537
Join Date: Jul 2009
Location: Spain
Default 01-05-2012, 06:19 PM

I also added a semicolon after the last two SQL statements(mysql_query.... and mysql_close).
I am glad that finally the code worked.


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma
Reply With Quote
(#9 (permalink))
Old
blackdogruns's Avatar
Member
blackdogruns is an unknown quantity at this point
 
Posts: 75
Join Date: Dec 2011
Location: Salem, Oregon
Default 01-05-2012, 06:20 PM

blah, nevermind. Now i'm getting this message -_-

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a6072331'@'10.1.1.47' (using password: NO) in /home/a6072331/public_html/otherpages/adduser.php on line 34
Reply With Quote
(#10 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 6,537
Join Date: Jul 2009
Location: Spain
Default 01-05-2012, 06:27 PM

It can be for 3 reasons.
1. The server database is temporarily down.

2. Some of the login data (user, server name, or password of the database) is not correct. Check that you have returned to put right password.

3. It is possible that the change I made mistakes in the code. You can find and replace lines 34 and line 35 by adding quotes to the variables so that they are as follows:
PHP Code:
// Connect to server and select databse.
mysql_connect('$host''$username''$password')or die("cannot connect"); 
mysql_select_db('$db_name')or die("cannot select DB"); 


Recuerda realizar copias de seguridad de tus sitios web. Si este mensaje te ayudó puedes pulsar sobre el botón karma
Reply With Quote
Reply

Tags
data, database, insert, php, sql

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com