This tutorial takes a look at how to insert data into a MySQL Table and specify which fields to insert data into. There is no example of using this to insert …
Original source
This tutorial takes a look at how to insert data into a MySQL Table and specify which fields to insert data into. There is no example of using this to insert …
Original source
45 responses to “PHP Tutorial 28 – MySQL Inserting Data (PHP For Beginners)”
It doesn't show no error but it is insert the values
Thank you so much chris, I've learned a lot from you, wherever you are good luck to you man 🙂
it helped alot thnks
Man thank you so much i've been searching for some tutorials like this for so long
Hi, can you please check why my code keeps on giving me "not inserted" error.
I tried to check the syntax but still the same error.
<?php
$con = mysqli_connect('********', '*********', '********');
if (!$con) {
echo 'Not connected to Server';
}
if(!mysqli_select_db($con,'***********'))
{
echo 'Database not selected';
}
$fname = $_POST['fname'];
$mname = $_POST['mname'];
$lname = $_POST['lname'];
$position = $_POST['position'];
$mobile1 = $_POST['mobile1'];
$mobile2 = $_POST['mobile2'];
$age = $_POST['age'];
$sql = "INSERT INTO workers (fname, mname, lname, position, mobile1, mobile2, age,) VALUES ('fname','mname','lname','position','mobile1','mobile2','age')";
if(!mysqli_query($con,$sql))
{
echo 'Not Inserted';
}
else
{
echo 'Inserted';
}
header("refresh:10000000; url=insertindex.html");
?>
hi
it says Parse error: syntax error, unexpected T_VARIABLE in /home/a8326296/public_html/hub/index.html on line 8
here is my code
<?php
$accounts = mysql_connect("mysql6.000webhost.com", "a8326296_profile", "***********")
or die (mysql_error());
mysql_select_dl("users", $accounts)
$sql = "
INSERT INTO users (username, password) VALUES('Chris', 'Pass123')
";
mysql_query($sql, $accounts)
?>
do you play cod4 (call of duty modern warfare 4)???
🙂
sir what if im using
$accounts=mysqli_connect("localhost", "root", "password") or die (mysqli_error());
mysqli_select_db("accounts", $accounts);
the error is
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:wampwwwMySQL.php on line 4
please help…
Parse error: syntax error, unexpected end of file in C:xampphtdocsSampleinsertvalues.php on line 13
<?php
$con = mysql_connect("localhost","root","");
if(!$con){
die("can not connect".mysql_error());
mysql_select_db("mydatabase",$con);
$sql= "INSERT INTO mytable(user_id, firstname, lastname) VALUES('1','jaime','rivera')";
mysql_query($sql,$con);
mysql_close($con);
?>
thanks!
Hi brother…. your videos are very useful to me….
I have one doubt that if we give data like this
INSERT INTO user2 (USERNAME,PASSWORD,FIRST_NAME,LAST_NAME) VALUES('asdf', 'pwd'123', 'dasdsa', 'sdfsdfsd');
it will truncate the password field upto pwd because php will take next ' as ending….how to overcome this problem….can you please clarify me this doubt….??
thanku..
<?php
$con = mysqli_connect("localhost","root","password","dbname") or die(mysql_error());
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Creating User
$sql = "INSERT INTO `users2`
(`ID`,
`Username`,
`Password`,
`FirstName`,
`LastName`)
VALUES (NULL,'user','password','fname','lname')";
// Checking if created
if (mysqli_query($con,$sql))
{
echo "User created successfully </br>";
}
else
{
echo "Error creating User: " . mysqli_error($con);
}
?>
this is for guys "doesn't worked help me !". 🙂
didn't worked because there is new versions of mysql…
and for mysql_connect i typed mysqli , and same on others…
or maybe you have not finished your script, explame: forgoted ";" or something like that.
I spent 3 days trying to get this to work and yours is the only example that actually worked when i changed it to my details, thanks a lot, now to just get these fields into a user submittable form 😀
Dear Chris,
Can you show us please how users can insert data to it, i mean with a <input type="text"> html input window.
To all the people that it isn't working for use this code in your text editor:
<?php
$accounts = mysql_connect("localhost", "root", "password")
or die(mysql_error());
mysql_select_db("accounts", $accounts);
$sql="
INSERT INTO users2 (Username, Password, FirstName, LastName) VALUES('Name', 'Password', 'FirstName', 'LastName')
";
echo $sql;
if (!mysql_query($sql, $accounts))
{
die('Error: ' . mysql_error());
}
echo "<h1> 1 record added to database </h1>";
?>
A quick tip for your future studying; the 'echo $sql' shows you the process and if it fails you can fix it, this is called 'debugging' and that simple line will help you vastly.
Hi Chris, Your videos really helped me to clear my basics in php & mysql…thanks a lot!! 🙂
I noticed that he uses the word 'bracket' which I took for [] and he meant (). Works great now.
Nice lesson.
people just skip the vide to 0:57 pls 🙂
hi , sorry 2 bother but i have a problem in this video and the last one because i did everything as u said since the first video i even downloaded the same porgram u showed in the tutorials and am using windows 7 ultimate 64-bit but in the last 2 videos technically i couldn't even add a group to the ((accounts)) database using php , so i can't even modify it or add values to it, the question is what do u think that the problem is?? thank u so much………….
Hey, I tried to link the php page using GET method. And allowed the user to enter the username password etc using an html form.. I am able to link it to the php page which has the mysql query connected to it.. That's not working.. I mean I use the username and password types by the user and save it to the database.. Not working..
Hi,
Good Job …!!
I m new for PHP but i m stucked at a problem ..
how to update value?
if user enters ID than rest valuse update otherwise it will insert into new row with different ID?
thanks in advance
Still not connecting to my database. I really wish I could figure this out.
thank you for the Tutorials …..
"I'm not going to lie and say I was like doing exams…
…[I've] just been playing Modern Warfare 3 the whole time and it's, ugh, its so good." : ) made me laugh.
Thanks for teaching me php in a day. : )
Awesome tutorial…
very much helpful for me to understand php.
I surely recommend this for beginners..
though the browser doesnt show any error but my table is not updated
why
hi thanks for your tut
can you make a tutorial where i can read from .txt file and insert the data into mysql database
this is my data:
SEASON OF THE WITCH DONE
RED DAWN DONE
ZERO DARK THIRTY DONE
THE HOBBITS DONE
THE BEST EXOTIC MARIGOLD HOTEL DONE
my database table is going to have 3 colones one for id one for movie one for done or not
Amazing tutorials, thank you so much, this is an amazing time saver, everything works just just like you do it, thumbs up bro 🙂
Wow when you cough like that in the middle of the tutorial when I am using earphones, volume loud…that's something. Please don't do that.
Thanks for the video man.
I created the database using the PHP code and I am not getting any error but still the table is not created in phpMYAdmin..:(
feeling happy………..
mysql_select_db("accounts", $accounts); you forgot the quotation
Sorted- there is a " missing behind "accounts.
Sorry for spamming
Parse error: syntax error, unexpected 'INSERT' (T_STRING) in C:xampphtdocstutorialsdata.php on line 9
$accounts = mysql_connect("localhost", "root", "dolinar")
or die(mysql_error());
mysql_select_db("accounts, $accounts);
$sql= "
INSERT INTO users2(Username , Password , First , Last) VALUES('Chris','pass123','Chris','Johnson')
";
mysql_query($sql, $accounts);
Can anyone help me?
OMG… look at how many subscribers he has
Omg data is not being inserted in QAWHBES[FVKHBDJQBJLCDJVS;SL
F,
]DM .V,
check that "user2" is really your table name, cuz for Chriss it is "users".
Thanx!
Hey, thanks for taking the time to make all these video tutorials! They are great.
$db_connection = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("accounts", $db_connection);
$sql = "
INSERT INTO user2 (USERNAME,PASSWORD,FIRST_NAME,LAST_NAME) VALUES('asdf', 'pwd123', 'dasdsa', 'sdfsdfsd')
";
mysql_query($sql, $db_connection);
which one it shud be? I am also facing same issue
the mysql_connect(…) or die (mysql_error());
is not working for me, no errors show up if i type the password wrong, so im not sure that i am even connected… maybe its the phpMyAdmin, config but i have no idea…
any help?
Check your brackets { } or ( ).
Sir Teachmecomputer can you make tutorial about making biometric in vb,net i love your tutorial and understand it. Hope you make a tutorial about vb,net biometric cause i cant find one tutorial about biometric in youtube thanks sir
Hope so im sorry maybe i miss something .thanks bro