Pages: 123Next
Current Page: 1 of 3
how to store values into database
Posted by: nav2626 (---.nycmny.east.verizon.net)
Date: May 26, 2008 04:47AM

Hi,

I am new to wampserver..Actually i'm working on a website, in which on first html + PHP page by clikng on a button the username and password should be stored in a databse that i have created using Phpmyadmin. i was succesful in buildind the connection i think but after using the insert statement i am still not able to insert the values in the database...kindly help me please.

Options: ReplyQuote
Re: how to store values into database
Posted by: yfastud (Moderator)
Date: May 26, 2008 05:41AM

When using insert, you need to include all fields in your db or it will fail; for example, you might setup 3 fields such as id, first_name, and last_name, but only insert first_name and last_name

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.nycmny.east.verizon.net)
Date: May 26, 2008 07:37AM

i did tht i mean included all the fields but still cant get thru

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.nycmny.east.verizon.net)
Date: May 26, 2008 07:46AM

actually i'm using
$sql="INSERT INTO table (username, password)
VALUES
('$_POST[username]','$_POST[password]')";
and it showed an error
your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table(username, password) VALUES ('joe','joe')'

Options: ReplyQuote
Re: how to store values into database
Posted by: toivo (---.nsw.bigpond.net.au)
Date: May 26, 2008 08:59AM

Hi,

Try this:

$username = $_POST['username'];
$password = $_POST['password'];

$sql="INSERT INTO table (username, password) VALUES ('$username','$password')";

Be aware that unless you validate the contents of the POST variables, the above code can be exploited in an SQL injection attack - for an explanation and how to fix this vulnerability, see for example: [www.phpbuilder.com]

Regards,

toivo
Sydney, Australia

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.nycmny.east.verizon.net)
Date: May 27, 2008 03:43AM

hi..thanks a lot but still i'm getting the same error..please help me in this...
MY CODE IS:

<html>
<head>
<title>insert.php</title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","mang"winking smiley;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("navjyoti", $con);

$username = $_POST['username'];
$password = $_POST['password'];

$sql="INSERT INTO table (username, password) VALUES ('$username','$password')";


if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>

</body>
</html>

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.nycmny.east.verizon.net)
Date: May 27, 2008 03:44AM

ERROR IS: check the manual that corresponds to your MySQL server version for the right syntax to use near 'table(username, password) VALUES ('joe','joe')'

Options: ReplyQuote
Re: how to store values into database
Posted by: toivo (---.nsw.bigpond.net.au)
Date: May 27, 2008 10:30AM

Does the table called table exist in your database? The word table cannot be used because it is a reserved word, which is likely to explain the error you see:

[dev.mysql.com]

Regards,

toivo
Sydney, Australia



Edited 1 time(s). Last edit at 05/27/2008 11:15AM by toivo.

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.dl.stevens-tech.edu)
Date: May 27, 2008 09:31PM

hi, thanks for replying...

Yes it exist in my database navjyoti..I too had the similar confusion with this then i made a databse web and made an add as a name table in that but i was facing the same problem....
Just wanna make sure i hope we dont have to add or edit some files in any of the .dll file..

last thing that i wanna be sure of is i have made these databases using phpmyadmin. am i going in the correct direction.

Options: ReplyQuote
Re: how to store values into database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: May 27, 2008 09:55PM

$sql="INSERT INTO table (username, password) VALUES ('$username','$password')";


your mistake seems easy, u made a database in phpmyadmin.. but did u add a table? with the columsn username and password?


and what is the name or your table



i doubt u called it table?
where i have tablename should be the name of the table?


$sql="INSERT INTO tablename (username, password) VALUES ('$username','$password')";

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.dl.stevens-tech.edu)
Date: May 27, 2008 10:07PM

hi steven..

no.... i mean table is the name of the table that i have created using phpmyadmin with two columns named username and passwprd...after executing this i'm gettin an error like



check the manual that corresponds to your MySQL server version for the right syntax to use near 'table(username, password) VALUES ('joe','joe')'

Options: ReplyQuote
Re: how to store values into database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: May 27, 2008 10:32PM

oh ok
u need to query the database

$sql=mysql_query("INSERT INTO tablename (username, password) VALUES ('$username','$password')"winking smiley;

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.nycmny.east.verizon.net)
Date: May 28, 2008 04:19AM

Thanks a lot steven....it worked..


its storing the values in my database but i don't know i'm stil getting an error....


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1.....

But there's nothing on line one.....or u can say my code startsfrom <html> which was written on line 2...i don know y i am geting this message...i hp this wont make ny difference...

Options: ReplyQuote
Re: how to store values into database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: May 28, 2008 04:23AM

post up ur full code so i can see

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.nycmny.east.verizon.net)
Date: May 28, 2008 11:43PM

hi..steven here's my full code....actually i have made two pages one is html( the interface) u can say which post its method on the second page insert. and the error is in insert page here's the code for that page..

thanks a lot..

<html>
<head>
<title>insert.php</title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","managed1"winking smiley;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("minhas", $con);

$username = $_POST['username'];
$password = $_POST['password'];

$sql=mysql_query("INSERT INTO customer (username, password) VALUES ('$username','$password')"winking smiley;


if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>






</body>
</html>

Options: ReplyQuote
Re: how to store values into database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: May 29, 2008 04:27AM

a few little errors in it. use this below.


<html>
<head>
<title>insert.php</title>
</head>
<body>
<?php

$con = mysql_connect("localhost","root","managed1"winking smiley or die ('Error connecting to mysql');

$dbname = 'minhas';
mysql_select_db($dbname,$con);


$username = $_POST['username'];
$password = $_POST['password'];

$sql=("INSERT INTO customer (username, password) VALUES ('$username','$password')"winking smiley;

@mysql_query($sql) or die('Error in query: [<b>' . $sql . '</b>]. The error was: ' . mysql_error());
echo "1 line added";


?>




</body>
</html>

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.nycmny.east.verizon.net)
Date: May 29, 2008 05:57AM

Oh thats great steven it worked thanks a lot once again.....

i am sorry but i wanna ask u one more thing actually these operations i am doin at home Because i am not able to operate can say wamp is not working properly in my university...the main problem is when i try to open phpmyadmin to set password its asking me to go to first localhost. And on openin localhost
there's some interface with username and password how to set that can u please help me in this.

i'll be really thankful to u.

Options: ReplyQuote
Re: how to store values into database
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: May 29, 2008 06:27AM

if your college have phpmyadmin blocked in this way,,, then u need a username and password to access it..t someone there will ahve to help you get access to it,

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: how to store values into database
Posted by: yfastud (Moderator)
Date: May 29, 2008 06:13PM

Follow this instruction to setup login screen for phpmyadmin
[guides.jlbn.net]

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: how to store values into database
Posted by: nav2626 (---.dl.stevens-tech.edu)
Date: May 29, 2008 10:37PM

i have one query...suppose i have column names in my database like allow_members; e_Mail and on the Html page they are Allow members to view; E-Mail Address.

how do i rite this using PHP ..
i mean in this way

$username = $_POST['username'];
$password = $_POST['password'];

$sql="INSERT INTO table (username, password) VALUES ('$username','$password')";

Options: ReplyQuote
Pages: 123Next
Current Page: 1 of 3


Sorry, only registered users may post in this forum.