follow us on google+ follow us feedburner

FORUM
We will close this forum soon. Please, now use Stack Overflow. Don't forget to add the tag "easyphp" to your post.

You can follow your activity on Stack Overflow with the Stack Exchange Android App. An iPhone version is coming...

One more thing. EasyPHP is on GitHub. You will find the repositories at this address : https://github.com/easyphp. If you want to report a bug, please use the GitHub issue management system of each repository.

Database not updating, no errors.



Posted by: Schalk1807
September 23, 2013 05:40PM
Good day, I have coded a register page as well as a connect page. The register page connects to the database, apparently, because no connect errors. However, the database does not update with the registration details. Please assist.

Database name: antiques
Table name: user

Easyphp vers.:5.3.1.0

connect.php:

<?php

function quote_smart($value, $handle) {

if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}

if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value, $handle) . "'";
}
return $value;
}

function connect_server_db()
{
$user_name="root";
$password="";
$database="antiques";
$server="127.0.0.1";

$connection = mysql_connect ($server, $user_name, $password)
or die ("Could not connect to server");

$db_found = mysql_select_db($database)
or die ("Could not connect to database");

return $connection;
}

?>

<?php


if (isset($_REQUEST['register']))
{
$title = "";
$name = "";
$surname = "";
$uname = "";
$pword = "";
$errorMessage = "";
$num_rows = 0;

$title = $_REQUEST['title'];
$name = $_REQUEST['name'];
$surname = $_REQUEST['surname'];
$uname = $_REQUEST['username'];
$pword = $_REQUEST['password'];


$uname = htmlspecialchars($uname);
$pword = htmlspecialchars($pword);

$uname = quote_smart($uname, $connection);
$pword = quote_smart($pword, $connection);

$uLength = strlen($uname);
$pLength = strlen($pword);

if ($uLength >= 1 && $uLength <= 6) {
$errorMessage = "";
}
else {
$errorMessage = $errorMessage . "Username must be between 1 and 6 characters" . "<BR>";
}

if ($pLength >= 1 && $pLength <= 6) {
$errorMessage = "";
}
else {
$errorMessage = $errorMessage . "Password must be between 1 and 6 characters" . "<BR>";
}

if ($errorMessage == "") {

connect_server_db();

$uname = quote_smart($uname, $connection);
$pword = quote_smart($pword, $connection);

$SQL = "SELECT * FROM user WHERE username = $uname";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);

if ($num_rows > 0) {
$errorMessage = "Username already taken";
}

else {

$SQL = "INSERT INTO user (title, name, surname, username, password) VALUES ($title, $name, $surname, $uname, md5($pword))";

$result = mysql_query($SQL);

mysql_close(connect_server_db('$connection'));

session_start();
$_SESSION['login'] = "1";

header ("Location: home.php");
}
}
else {
$errorMessage = "Database Not Found";
}

}

?>




Register.php

<html>
<head>

<?php
include ("connect.php");
?>
<title>
################################
</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<h1>
#############################<br /><br />
</h1>

<h2><br /><br />
########
</h2>
<br><br>

<table border = '1' bgcolor = #a4a4a4>
<form action="connect.php" method="post">
<tr><td>Title: </td><td><input type="text" name="title"></td></tr>
<tr><td>Name : </td><td><input type="text" name="name"></td></tr>
<tr><td>Surname : </td><td><input type="text" name="surname"></td></tr>
</tr><td>Username : </td><td><input type="text" name="username"></td></tr>
</tr><td>Password : </td><td><input type="password" name="password"></td></tr>
</table>
<br><br>
<input type="submit" name="register" value="Register">
<input type="reset" value="Reset">
</form>

</body>
</html>
Options: ReplyQuote


Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.