I just started using a web hosting service and I'm new to PHP and MySQL. I was trying to use the video I see here https://www.youtube.com/watch?v=gvGb5Z0yMFY as a simple recipe on adding a row to a table. I have a table called forumites
in my MySQL database and it has 3 columns -- username
, email
and password
.
HTML form:
<div class="boardbox hidden" id="regdiv">
<form id="regform" action="newuser.php" method="post">
<p>Username:<input class="threadipt" type="text" name="username"></p>
<p>Email address:<input class="threadipt" type="text" name="email"></p>
<p>Password:<input class="threadipt" type="text" name="password"></p>
<button onlick="phpfunction">Create Account</button>
</form>
</div>
newuser.php:
<?php
$conn = mysql_connect();
if (!$conn)
echo 'could not connect';
$db = mysql_connect_db('forumites');
$name = $_Post['username'];
$em = $_Post['email'];
$pass = $_POST['password'];
if (!mysql_query("INSERT INTO forumes VALUES('$name','$em','$pass')"))
echo 'Could not enter user info:';
?>
I think the part that is confusing me is the mysql_connect(...)
command. In the video I'm watching, the guy writes mysql_connect('localhost', 'root', '')
, but I'm not sure if he's using a web hosting service like I am. I read the W3Schools page on the command http://www.w3schools.com/php/php_mysql_connect.asp but it's not very informative.
Long story short, I'm trying to connect to the databse on my web hosting service and I'm probably doing a ton of things wrong. I was wondering if you guys could point out a few of the things I'm doing wrong.