Hello,
I am new to php and any help would be appreciated. I have a simple connection script I wrote for php to put data into a mysql database. I got it to work once, but when I refresh the browser to try it again, I get an error. What am I doing wrong? Here’s the code:
html doc:
<?php include("connec.php"); ?> Hello username:password:
Here is the connection file:
<?php $db_host = 'localhost'; $db_user = 'root'; $db_pass = 'root'; $dbc = mysql_connect($db_host,$db_user,$db_pass); if(!$dbc){ die("No Server!"); } echo ""; $dbase = mysql_select_db("testing", $dbc); if(!$dbase){ die("No Database!"); } $value = $_POST['username']; $value1 = $_POST['password']; $sql = "INSERT INTO login (username, password) VALUES ('$value', '$value1')"; if(!mysql_query($sql)){ die("No Tables!"); } mysql_close(); ?>
I got it to work once but when I refresh the browser, I get an error. It got it to work again When I emptied the database. Strange…
Any help would be appreciated.
I’m using a Macbook Pro and mamp.