1

I have this in side my two php files.

<?php

include 'dbh.php';

$first = $_POST['first']
 $last = $_POST['last']
 $uid = $_POST['uid']
 $pwd = $_POST['pwd']

 echo $first;
 echo $last;
 echo $uid;
 echo $pwd;

?>

and

<?php

$conn = mysql_connect("localhost", "root", "", "login");

if (!$conn) {
die("Connection faile:".mysql_connect_error());
}

?>

and my html is down there. What could be problem in my connection to mysql? Can anyone help me? I don't have much experience with mysql but i think it should be ok.

<!DOCTYPE html>
<html>
<head>
 <title></title>
</head>
<body>

<form action="http://localhost/signup.php" method="POST">
 <input type="text" name="first" placeholder="name"><br>
 <input type="text" name="last" placeholder="lastname"><br>
 <input type="text" name="uid" placeholder="username"><br>
 <input type="pasword" name="pwd" placeholder="pasword"><br>
 <button type="submit">sign up</button>
</form>

</body>
</html>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Danilo Ivanovic
  • 1,216
  • 1
  • 10
  • 18
  • your code is failing on too many levels – Funk Forty Niner Mar 05 '17 at 00:05
  • I know but i fixed my problem. :D – Danilo Ivanovic Mar 05 '17 at 00:08
  • If you're writing new code, **_please_ don't use the `mysql_*` functions**. They are old and broken, were deprecated in PHP 5.5 (which is so old it no longer even receives security updates), and completely removed in PHP 7. Use [`PDO`](https://secure.php.net/manual/en/book.pdo.php) or [`mysqli_*`](https://secure.php.net/manual/en/book.mysqli.php) with _prepared statements_ and _parameter binding_ instead. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Mar 05 '17 at 02:56

2 Answers2

0

First change this database connection, and don't use mysql beacause is deprecated use mysqli instead.

<?php
// host, user, password, database name
$conn = mysqli_connect("localhost", "root", "", "login");

// if u use mysql then ur connection need to connect first then select database
// $conn = mysql_connect("localhost", "root", "");
// $db = mysql_select_db("database name");

if (!$conn) {
   die("Connection faile: " . mysqli_connect_error());
}

?>
Mario
  • 518
  • 2
  • 19
  • sorry for wasting your time. I'm idiot. I forgot ";" at end. In my first php. But thanks for that post i didn't know about second way of connection. – Danilo Ivanovic Mar 05 '17 at 00:02
  • Why did you Mario go and change their original code http://stackoverflow.com/revisions/42602613/2 - you're NOT allowed to do that. I rolled it back to its original post. – Funk Forty Niner Mar 05 '17 at 00:04
  • no problem, just keep in mind to use mysqli. and use error_report(1); on top of your script when u coding to show u errors. – Mario Mar 05 '17 at 00:06
  • sorry @Fred-ii- i didn't know that is forbidden. – Mario Mar 05 '17 at 00:07
0

use mysqi because it is more secured and you only need to adjust mostly on parameters but better if you start using it, mysql is deprecated already so try to avoid using mysql functions and start using mysqli.. connect using this

$db_host = '192.168.1.9'; //sample
$db_user = 'dbuser'; //sample usename
$db_pass = 'dbpass'; //sample password
$db_name = 'databasename';

$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

if(mysqli_connect_errno($db))
die('Failed to connect to MySQL: ' . mysqli_connect_error());

hope this helps.

Aaron Magpantay
  • 405
  • 1
  • 5
  • 17