1 Replies - 274 Views - Last Post: 14 May 2013 - 05:36 AM Rate Topic: -----

#1 vsiry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-May 13

Got error without warning.

Posted 14 May 2013 - 05:26 AM

hey guys, i'm a newbie in PHP and i have problem with mysql database. please help me to fix it.

i use a simple dbconnect script like this
<?
$server = "localhost";
$user = "root";
$pass = "";
$db = "try";
mysql_connect($server, $user, $pass);
mysql_select_db($db);
?>



the script works without getting any error.
but the problem comes when i want to try making a simple registration user.
this is my registration submit script.
<?
include "dbconnect.php";
$username = $_POST['username'];
$fullname = $_POST['fullname'];
$password1 = md5($_POST['password1']);
$password2 = md5($_POST['password2']);
$group = $_POST['group'];
$number = $_POST['number'];
if ($password1 == $password2)
{
$query = "SELECT * FROM user WHERE username = '$username'";
$result = mysql_query($query);
$data = mysql_num_rows($result);
if ($data == 0)
{
$query = "INSERT INTO user(username, fullname, password, group, number) VALUES('$username', '$fullname', '$password1', '$group', '$number')";
$result = mysql_query($query);
echo "Welcome<b> ".$fullname."</b><br>Please Log in";
}
else echo "Username is already used, <a href=\"signup.php\" style=\"color:red\">Return</a>";
}
else echo "Password is incorrect, <a href=\"signup.php\" style=\"color:red\">Return</a>";
?>



when use the registration script above, it works successfully.
but when i checked my database on phpmyadmin there's nothing changed in database 'try'.
the database is still blank.
what should i do? i really don't understand because i got no warning error on my script when i run it.

This post has been edited by Dormilich: 14 May 2013 - 06:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Got error without warning.

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3490
  • View blog
  • Posts: 11,902
  • Joined: 12-December 12

Re: Got error without warning.

Posted 14 May 2013 - 05:36 AM

group is a reserved word in MySQL. You need to enclose it in back-ticks or, much better, change this field-name.

The mysql library is deprecated - see my signature;
You should not just post unchecked and unsanitised post-data into a database - use prepared statements;
You are not checking for the success or failure of your database operations (other than a single attempt to read the number of rows).

This post has been edited by andrewsw: 14 May 2013 - 05:37 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1