Jump to content

I dont understand why its not working


sinista

Recommended Posts

HI all I dont understand whats going wrong ,

 

My problem is that when i try and access a Database using php that is run from my web browser nothing happens (run from Firefox & IE) i do not recieve an error message and nothing is displayed at all i just get a blank white screen.

 

here is the code that im using

 

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="*********"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?> 

 

the full tutorial where i got the code from is found at

 

http://www.phpeasystep.com/workshopview.php?id=6.

 

the same problem happens to all of my code nothing is displayed no errors, nothing , nada.

 

This is what im using

 

Windows 2000 profesional SP4

Php 5.2.5

Apache 2.2

MySql 5.0.51a

 

I have made a second pc with the above installed to be used as a webserver , with the intention to learn php & mysql.

 

I am asuming that Apache is instaled correctly as i can access the site by typing in http://localhost seeing my index page, I can also see the page from my other pc (but i have to type 192.168.1.4 rather than http://localhost). also i can see the site buy typing in http://sinista.no-ip.org. into my mobile phone. My IP is dynamic so i use http://www.no-ip.com to redirect my computer.

 

I am assuming that php is installed corectly as I have installed PHPBB and it appears to be working correctly.

 

I am assuming that Mysql is installed correctly as phpmyadmin is installed and i can create DB's & Tables using this.

I can aslo type into the DOS command line

 

C:\>mysqlshow -u root -p

 

and when i enter the password the databases are displayed.

 

form within phpmyadmin i can run SQL querys like

 

CREATE TABLE `members` (

`id` int(4) NOT NULL auto_increment,

`username` varchar(65) NOT NULL default '',

`password` varchar(65) NOT NULL default '',

PRIMARY KEY (`id`)

) TYPE=MyISAM AUTO_INCREMENT=2 ;

 

--

-- Dumping data for table `members`

--

 

INSERT INTO `members` VALUES (1, 'john', '1234');

 

and the table gets updated.

 

 

Dont know if this helps but the tutorial i used to install Apache , php & mysql can be found at

http://apacheguide.org/apache.php

 

any advice would be great or even a pointer in the right direction would help loads .

 

thanks in advance and i appologise if this is in the wrong part of the forum but im thinking its a sql error.

 

:)

 

 

Link to comment
https://forums.phpfreaks.com/topic/97011-i-dont-understand-why-its-not-working/
Share on other sites

I believe this is not sql any way try

 

error reporting to see the error

<?php
error_reporting(E_ALL);
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="*********"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?> 

hey thanks,

 

I turned on the error reporting now i get

 

Fatal error: Call to undefined function mysql_connect() in C:\sinista\checklogin.php on line 9

 

so this is a php error right? and ive done my php.ini file wrong? or is apache or mysql

 

thanks again , lol im so happy i can now see something even if it only an error

 

:)

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.