Jump to content

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";

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.