0

I created a .php file and when I am trying to execute it via- localhost, it shows nothing. If the script is working fine, then it should print something on the screen. <- The basic idea of the script, but nothing is getting displayed.

<?php
$con = mysql_connect("localhost","somanshu","somanshu");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("james007", $con);

$result = mysql_query("SELECT * FROM info");
while($row = mysql_fetch_array($result))
  {
  if($_POST['mail'] == $row['email'])
  {
  echo "Logged In.<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=home\">";
  }
  else
  {
  $sql="INSERT INTO info (email, password)
  VALUES
  ('$_POST[mail]','$_POST[pwd]')";
   if (!mysql_query($sql,$con))
   {
   die('Error: ' . mysql_error());
   }
   else
   {
   echo "Added. <META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=home\">";
   }
  }
  }
mysql_close($con);
?>
1
  • You are using a soon-to-be-removed API. Use PDO or MySQLi, not ext/mysql, or you will suddenly find that your code doesn't work. Also, it's famously insecure due to lack of proper(ly used) escaping and lack of prepared statements Commented Feb 23, 2013 at 12:50

3 Answers 3

2

Use ini_set('error_reporting', E_ALL); and see if its give errors.

add below code at top of the page.

error_reporting(E_ALL);
ini_set('display_errors', '1');

if its still not display errors then try

mysqli_select_db("james007", $con)or die(mysqli_error());

Also check

mysqli_query("SELECT * FROM info")or die(mysqli_error());
Sign up to request clarification or add additional context in comments.

2 Comments

I meant code doesn't looks broke, if someone likes to ignore official warnings from PHP team, that's a bit about personal preferences. Of course it's better to switch to PDO or mysqli
Thanks for the information. If that API is going down, its good to change our approach right now.
0

Ensure that there is data in the database to select. If SELECT * FROM info returns no rows, this script will not output anything.

1 Comment

This works. Actually, I emptied my table ( via TRUNCATE method. ) Thanks for help.
0

First things first: Is php executed at all? To find out create a file called test.php and write

<?php
phpinfo();
?>

inside.

If this is not working you have to set up php for your webserver properly.

2 Comments

phpinfo() not php_info() I can't edit your post as it's not a big enough edit.
Sorry, doing this from memory while in the hospital :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.