Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

HOW TO SAVE USER INPUT INTO MYSQL??

I need this small code to save the user input on a website into mysql database pls help
You will also need the connect function that will let you connect to the MySQL database, I suggest you read here: http://www.tizag.com/mysqlTutorial/mysqlinsert.php
(Apr 1, 2011 03:23 PM)-VeX- Wrote:  
PHP Code

<?php 
mysql_query
("INSERT INTO table VALUES (*your vablues here*)") 

simple as that!

I have done this :

Code
<?php
$Name = $_POST['Name'];
$Country = $_POST['Country'];
$Cell = $_POST['Cell'];
$Service = $_POST['Service'];
$Email = $_POST['Email']

mysql_connect("localhost","my_admin","my_password") or die('Error: '. mysql_error());
mysql_select_db("uh1_site");

$query="INSERT INTO tester(Name,Country,Cell,Service,Email)VALUES('".$Name."', '".$Country."', '".Cell."', '".Email."')";

?>

query not generating any error but data is not inserted
(Apr 1, 2011 03:44 PM)The Real Slim Shaddy Wrote:  I have done this :

Code
<?php
$Name = $_POST['Name'];
$Country = $_POST['Country'];
$Cell = $_POST['Cell'];
$Service = $_POST['Service'];
$Email = $_POST['Email']

mysql_connect("localhost","my_admin","my_password") or die('Error: '. mysql_error());
mysql_select_db("uh1_site");

$query="INSERT INTO tester(Name,Country,Cell,Service,Email)VALUES('".$Name."', '".$Country."', '".Cell."', '".Email."')";

?>

query not generating any error but data is not inserted

I'm sorry but your code is terribly wrong, your submitting the query wrong. I just wrote this up quick for you.

Code
$Host = "localhost"; // Do NOT change unless specified by your host
$SQL_Username = " " // Your mysql db username
$SQL_Password = " " // Your mysql db password
$db_name = " " // your mysql database name

$Connection = mysql_connect($Host, $SQL_Username, $SQL_Password) or die(mysql_error()); // Creates a Connection to the mysql database
mysql_select_db($db_name, $Connection) or die(mysql_error()); // Selects the MySQL Database to be used

$query = mysql_query("INSERT INTO tablename(Column_1, Column_2, Column_3)VALUES('value1', 'value2', 'value3')") or die(mysql_error()); // Processes MySQL Query
I have used this code now :

PHP Code

<?
$Host = "localhost"; // Do NOT change unless specified by your host
$SQL_Username = "username" // Your mysql db username
$SQL_Password = "password" // Your mysql db password
$db_name = "db_name" // your mysql database name

$Connection = mysql_connect($Host, $SQL_Username, $SQL_Password) or die(mysql_error()); // Creates a Connection to the mysql database
mysql_select_db($db_name, $Connection) or die(mysql_error()); // Selects the MySQL Database to be used

$query = mysql_query("INSERT INTO tablename(Name,Country,Cell,Service,Email)VALUES('$_POST[Name]','$_POST[Country]','$_POST[Cell]','$_POST[Email]')") or die(mysql_error()); // Processes MySQL Query

?>

and getting this erro

Parse error: syntax error, unexpected T_VARIABLE in /home/uh1/public_html/post.php on line 4
(Apr 2, 2011 01:55 AM)The Real Slim Shaddy Wrote:  I have used this code now :

PHP Code

<?
$Host = "localhost"; // Do NOT change unless specified by your host
$SQL_Username = "username" // Your mysql db username
$SQL_Password = "password" // Your mysql db password
$db_name = "db_name" // your mysql database name 

Check your original source code starting line 4. You should terminate the variables properly with a semicolon.
OK now everything looks fine just one error that is :
Code
Column count doesn't match value count at row 1
Thats because you are addressing 5 columns but only allocating values to four. if you have only 4 values then you need to add a NULL value in there somewhere.
You may also want to add some security to the script. It's massively exploitable.
Just add
PHP Code

<?php 
mysql_real_escape_string
($_POST['value goes here']) 
To your script for each value.
That will make it a bit better.
YES YES YES YES YES YES YES DONE THANK YOU GUYS !!!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by realsunjesterFeb 1, 2019 12:50 AM 11 513 Feb 1, 2019 12:50 AM
Last Post: Squito
[PHP] by SkidyDec 17, 2017 02:10 AM 3 256 Dec 17, 2017 02:10 AM
Last Post: CryptoJeeb
[PHP] by Sai HungJun 21, 2017 03:20 AM 8 264 Jun 21, 2017 03:20 AM
Last Post: TCP