Watch the updated version of this tutorial here: https://www.youtube.com/watch?v=BmHLvUdkCA0&list=PL530D33D6E548481F&index=1 For more video …
Original source
Watch the updated version of this tutorial here: https://www.youtube.com/watch?v=BmHLvUdkCA0&list=PL530D33D6E548481F&index=1 For more video …
Original source
44 responses to “How to Create an HTML Form That Stores Data in a MySQL Database Using PHP Part 2 of 4”
Great tutorials, but you talk a lot for no reason
Thank you John Morris, your tutorials really help me a lot!!
can't usewebsite: Access denied for user ''@'localhost' to database 'website'
On 7:44, I wasn't able to connect successfully. Where do I put my demo-form.php and demo.php files? Does it matter where I put them on my computer? Please advise. Thank you!
this is great! thank you john
U talk too much.
I did everything like you said, no errors, but the data is not getting uploaded to the database on phpmyadmin
Make sure to watch the updated version of this tutorial here: https://www.youtube.com/watch?v=BmHLvUdkCA0&list=PL530D33D6E548481F&index=1
Demo-form.php
<html>
<body>
<form action="demo.php" method="post">
<p>
</br>
<label> Name: <input type="text" name="name">
</br></br>
<label> Submit This Query Please! <input type="submit" value="Go For It!">
</p>
</form>
</body>
<html>
Demo.php
<?php
define('DB_NAME', 'form1');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link)
{
die ('Could not Connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if(!$db_selected)
{
die('can't use ' . DB_NAME . ': ' .mysql_error()) ;
}
echo " Dang";
$value = $_POST['name'];
$sql = "INSERT INTO demo (name) Values ('$value')";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
mysql_close();
?>
I don't know what's wrong in this code when i am trying to compile my code it says error in this line . i have no idea
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
Thank you so much for this series of videos! I'm definitely going to join. I like you teaching style. I'm having a problem and I'm hoping your still around to help out. I have my files live on my website. however i keep getting the error:
Could not connect: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
What does that mean? What do i have to do to fix it?
dude, just wanna say that there are some codes or words that beginner might not understand. thats what i found out to your tutorial. But btw thank you for sharing your knowledge. Good day !
I get this error when i run the demo.php
Parse error: syntax error, unexpected '$link' (T_VARIABLE)
You are awesome man!! you have goooooooooooood Fucher bye
<?php
define('DB_NAME', 'forms1');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Cant use ' . DB_NAME . ': ' . mysql_error());
}
echo 'Connected Successfully';
mysql_close();
?>
NEED HELP
how should i know if my code is correct.
here is my code:
demo.php
<?php
define('DB_NAME', 'forms1');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can't use ' . DB_NAME . ': ' . mysql_error());
}
?>
demo-form.php
<form action="demo.php" method="post" />
<p>Input 1: <input type="text" name="input" /></p>
<input type="submit" value="Submit" />
</form>
forms1
— phpMyAdmin SQL Dump
— version 3.3.9
— http://www.phpmyadmin.net
—
— Host: localhost
— Generation Time: Aug 19, 2014 at 07:05 AM
— Server version: 5.5.8
— PHP Version: 5.3.5
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT/;
/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS/;
/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION/;
/*!40101 SET NAMES utf8 */;
—
— Database: `forms1`
—
CREATE DATABASE `forms1` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `forms1`;
— ——————————————————–
—
— Table structure for table `demo`
—
CREATE TABLE IF NOT EXISTS `demo` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`input1` varchar(20) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
—
— Dumping data for table `demo`
—
i really need to know if its right or if it is wrong…
When I downloaded the demo from your actual site it didn't give me file with "demo-form.php" only a "demo.php" that is the form. It looks like you have six files open but I only have 5 that got downloaded. Help!!
Also do you happen to have a tutorial on how to create those country, state, city selectors? That's really what I'm looking for but I'm hoping to make it myself with the knowledge you have provided.
Let me know. 🙂
Thanks,
Naya
Hey in when I click save for the table it tells me that I need to enter a valid length . What does that mean ?
Whenever I go to make the database I do the ID and input1. When I go to get the final product, I get "MySQL returned an empty result set (i.e. zero rows). (Query took 0.0000 sec)" and I don't know what to do.
just a bullshit first of all i just came here to know how the informations stores into the database and you've described a lot about css and html (very disturbing) after that when i saw the main thing that i'm here for but its also not fully cleared you have done many things without showing how to
Yes here is my script.
<?php
define ('DB_NAME','newebay');
define ('DB_USER','root');
define ('DB_PASSWORD','bh05238');
define ('DB_HOST','localhost');
$link = mysql_connect('DB_HOST','DB_USER','DB_PASSWORD');
IF (!$link) {
die('Could not Connect :
' . mysql_error());
}
$db_selected = mysql_select_db (DB_NAME, $link);
if (!$db_selected) {
die('Can't use ' . DB_NAME . ': ' . mysql_error());
}
echo 'Connected successfully';
?>
Thanks for the Fast response!
Hi John, Love your videos so far. Having a issue trying to get php to connect to mysql. I keep getting this message. "php_network_getaddresses: getaddrinfo failed: Name or service not known". I think the issue is the 'DB_HOST'. I verified using mysql workbench that its name is local host. I even tried putting the port number into the variable 'DB_HOST' = 'localhost:3306' and still didn't work. What do you suggest?
WHY do you FORCE people to join?? WHEN did free stop being free??
That's my passion – making free things free.
why is the DB_NAME forms1 and not demo
Hello, you are an awesome man, here is my problem when i enter anything into the input1, it gets me to the demo.php page 🙁 please help
Hi, when I browse my demo.php. I get a blank page 🙁 please help! I don't know what is the problem! I had been following every single step! Many thanks!
I keep getting that it's failing….i'm not sure what i'm doing wrong….looks like it's not finding my table, idk….hmmm….ill keep trying….good video….
@Justin Emerson
If you delete the function he wrote in there that is called $value=$_POST['input1'];
and then where he has the next line of code stating $sql = "INSERT INTO demo (input1) VALUES ('$value'); and change it to $sql = "INSERT INTO Pledge (ID, Names) VALUES ('','$_POST[input1]')";
then it should work. Just remember that you need to add security to something like this and if you don't it is very easy to retrieve the information in your box by simply putting a retrieve code.
hey John I'm having a little problem with my form processing, don't know if you can help me out. I'm tired of debugging.
My info isn't showing up in my database. I get a new ID number but there is nothing in INPUT1. I watched your videos twice now and I can't seem to figure it out.
I've been watching your tutorials.. well, thanks a lot. ur really great 😀
Get hosting account for just 1 cent at hostgator using coupon "1centaprlmay2013".
phpMyAdmin.
Hi sir is that in Libreoffice database?
John could you please send me a link to your demo php file if still available. Thanks!
where is the source code of this video
hi John, I have a question Where can I find the PHP codes where you are showing define ('DB_name', demo') on my form I indicated ID, Login and Password (3 columns) but I do not know where can I find these code that you are showing PHP
what software did you use to construct html?
Dear John,
Can you tel me why i get the message cant use database
Thanks From Holland By Jan.
can i have the link to the demo.php file??
this is superb keep making tutorials brill!
you're awesome!!!!
@sli313 Yeah. No problem! 🙂
@JohnMorrisVideo ahh! thanks so much 🙂 this videos helped me alot once again thanks very much!
@sli313 On line #7, you have a $ in front of the mysql_connect() function. Remove that and you should be good. 🙂