Jump to content

[SOLVED] error trapping from databases


kidzkit

Recommended Posts

Can anyone help me. I am trying to error trap. This is my pseudo code

if no records arent there then display and error and if records are returned then i want to tell the user they are in the database. Any ideas? here is my code that i am trying to figure out

 

$result = mysql_query("SELECT * FROM users")

or die(mysql_error());

$row = mysql_fetch_array($result);

if (($row['username'] < 0 )  || ($row['pass'] < 0 ))

{

$errors += 1;

}

if($errors > 0)

{

echo "Please go back and make corrections";

}

else

{

echo "User is in the database";

}

 

some help would be nice

 

Link to comment
https://forums.phpfreaks.com/topic/113639-solved-error-trapping-from-databases/
Share on other sites

This is what i got now but it keeps jumping to the else statement whether the person is there or not

$result = mysql_query("SELECT * FROM users")

or die(mysql_error());

$row = mysql_fetch_array($result);

$count = mysql_num_rows($result);

if ($count == 1)

{

echo "User is in the databases";

}

else

{

echo "Please go back and make corrections";

}

 

i am fairly new to this stuff

can you help me write a working code to? i been workin on this shit all day hahahaha.

here is my full code. If maybe you could fix anything you see wrong

<?php

//phpinfo();

$name = $_POST["name"];

$pass = $_POST["pass"];

$errors = 0;

$con = mysql_connect("****","****","****");

$creDB  = "CREATE DATABASE login";

$db = mysql_select_db("login", $con);

 

 

$result = mysql_query($creDB);

if (!$db)

{

die(mysql_error());

}

if (!$con)

  {

  die(mysql_error());

  }

 

mysql_select_db('login') or die('Cannot select database');

 

$result = mysql_query("SELECT * FROM users")

or die(mysql_error());

$row = mysql_fetch_array($result);

$count = mysql_num_rows($result);

if ($count != 1)

{

echo "User is in the databases";

}

else

{

echo "Please go back and make corrections";

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.