Got error without warning

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Tue May 14, 2013 4:34 am

Got error without warning

Postby vsiry » Tue May 14, 2013 4:35 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

Code: Select all

$server = "localhost";
$user = "root";
$pass = "";
$db = "try";
mysql_connect($server, $user, $pass);

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.

Code: Select all

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 on 'user' table in database 'try'.
the user table 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.

User avatar
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions

Re: Got error without warning

Postby sandeep605085 » Tue May 14, 2013 12:14 pm


does your code able to connect to mysql?

try below code to get the error if any but you should not use this die function when you build your live site.

mysql_connect($server, $user, $pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());

also try echoing the variable inside your if condition and try to run that echoed query directly from phpmyadmin to check query is correct.

$query = "INSERT INTO user(username, fullname, password, group, number) VALUES('$username', '$fullname', '$password1', '$group', '$number')";
echo $query;

Sandeep Agrawal
Mindfire Solutions.

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 4 guests