Jump to content

Recommended Posts

Hello,

I've been having trouble connecting to a MySQL database, I can't find the problem in the code, what am I doing wrong?

 

Getting the database file in the config file : require_once("db_connect.php");

 

db_connect.php :

<?php

$db = mysql_connect('83.172.155.14:3306', 'username', 'password') or die(mysql_error());

mysql_select_db('databasename', $db) or die(mysql_error());

?>

 

I need to connect to a PhpMyAdmin database.

I need this fixed asap since I'm doing this for someone and he wants the site done as quickly as possible.

P.S: The database used to work in php4 and now I need it to work on php5

Thanks in advance,

 

Link to comment
https://forums.phpfreaks.com/topic/261884-mysql-database-cant-connect/
Share on other sites

What do you get appearing all over your website?  If after setting those settings, you get notices / errors all over your site it means that your site wasn't built properly (i.e. issues thrown under the rug).

 

~awjudd

in the tables, Notice: Undefined variable: sumordered in /hsphere/local/home/chaaknl/carolavanderhaak.nl/bestelkop.php on line 640, is that the content failure or just the php only?

That notice means that you have a variable 'sumordered' (in the code $sumordered) on line 640 of bestelkop.php which is being used without a value being assigned to it.  This is just an informational message.

 

I just re-read your first post and you do have or die(mysql_error()) so you should actually be fine without that.  If you aren't getting any errors there, then you are connecting to the database correctly but something else in the code isn't working as planned.

 

There were a lot of changes to PHP between PHP4 and PHP5 so I'm guessing you have the use of something that is deprecated.

 

~awjudd

I just cant see the products on the list if i click on it.

 

What have you done to troubleshoot why you cannot see the products when you click on it? Is the link properly formed and has the correct information in it? What does the code at the target of that link expect for an input value? Is that input value present in the code when it runs? If the input value is present, what does the code do with that value? Is there matching data present in the database?

 

You are the only one here who can troubleshoot what your code and data are doing on your server, to pin down exactly at what point your code and data are doing what you expect and exactly at what point they are not. I can guarantee that the problem lies somewhere between those two points. If all you have done is to try to run the code on a page and you cannot see the products on the list if you click on it, all you have done is narrowed down the problem to the code that page. You have to narrow down the problem to a specific statement or a specific variable or a specific value that is not doing what you expect.

I just cant see the products on the list if i click on it.

 

What have you done to troubleshoot why you cannot see the products when you click on it? Is the link properly formed and has the correct information in it? What does the code at the target of that link expect for an input value? Is that input value present in the code when it runs? If the input value is present, what does the code do with that value? Is there matching data present in the database?

 

You are the only one here who can troubleshoot what your code and data are doing on your server, to pin down exactly at what point your code and data are doing what you expect and exactly at what point they are not. I can guarantee that the problem lies somewhere between those two points. If all you have done is to try to run the code on a page and you cannot see the products on the list if you click on it, all you have done is narrowed down the problem to the code that page. You have to narrow down the problem to a specific statement or a specific variable or a specific value that is not doing what you expect.

 

From what I'm seeing is that I cannot load products or users, The code should be good, I am not seeing any problems in it but I might be wrong so I posted it here, The code used to work on php4 so I don't know, what other information do you need to have?

Thanks,

From what I'm seeing is that I cannot load products or users, The code should be good, I am not seeing any problems in it but I might be wrong so I posted it here, The code used to work on php4 so I don't know, what other information do you need to have?

Thanks,

 

The actual code.

 

~awjudd

Bestel.php :

<?php

 

if(!$_COOKIE["user"])

{

header("Location: index.html");

}

 

//bestanden koppelen

require_once('db_connect.php');

require_once("func_query.php");

 

if (empty($_GET))

{

$vraag = "SELECT merkid, merk FROM merken WHERE actief=1 ORDER BY volgorde LIMIT 0,1";

$resultaat = Query($vraag);

$rij = mysql_fetch_array($resultaat);

$merkid = $rij["merkid"];

$merk = $rij["merk"];

$orderid = "0";

}

else

{

$merkid = $_GET["id"];

$vraag = "SELECT merk FROM merken WHERE merkid='?'";

$resultaat = Query($vraag, $merkid);

$rij = mysql_fetch_array($resultaat);

$merk = $rij["merk"];

$orderid = $_GET["orderid"];

if (strlen($orderid) == 0)

{

$orderid = "0";

}

}

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

<SCRIPT language="Javascript">

if (top==self) self.location.href="index.html";

</SCRIPT>

<html>

<head>

<title>Paradiso Beheer Systeem</title>

<link rel="shortcut icon" type="image/x-icon" href="graphics/favicon.ico" />

</head>

<frameset rows="*,0" frameborder="no" border="0" framespacing="0" id="hoofdframe" name="hoofdframe">

<frame src="bestelkop.php?id=<?php echo($merkid. "&merk=" .$merk. "&orderid=" .$orderid); ?>" name="kop" scrolling="No" noresize="noresize" id="kop" />

<frame src="bestelbody.php?merkid=<?php echo($merkid. "&orderid=" .$orderid); ?>" name="body" id="body" />

</frameset><noframes></noframes>

</html>

 

db_connect :

<?php

$db = mysql_connect("83.172.155.14", "username", "password") or die(mysql_error());

mysql_select_db("databasename", $db) or die(mysql_error());

?>

There's nothing in the posted code that is php4/php5 version specific or even php.ini configuration specific.

 

P.S. Your login check code is not secure. All a hacker needs to do is ignore the header() redirect and he can access the code on that page the same as if he was logged in. You need an exit; statement after the header() redirect to prevent the remainder of the code on that page from running while the browser requests the new page. Also, anyone can create and set a cookie to any value, so anyone could create a $_COOKIE['user'] and visit your site and appear to be logged in as any user.

Hire a developer to go through the application and figure out what the actual issue is?

 

~awjudd

Isn't there any other way?

I can post the javascripts also but I don't know how usefull it will be.

The MySQL version is 5.0.67

It really used to work perfectly on php4 but now it doesn't work on php5

Given that the issue could be anywhere in your code, I am extremely doubtful that anyone is willing to go through (and jump through hoops while doing it) snippets of source code provide one at a time on a forum.  If there is anyone out there willing to do that ... well you have more patience that I do.

 

So either learn PHP and figure it out yourself or hire someone to do it for you.

 

~awjudd

[Edit: longer version of what awjudd stated above...]

 

Isn't there any other way?

 

Since you haven't provided any actual information about what wrong output you are getting and where and at what point it is happening and you don't seem to have the troubleshooting skills to debug the code yourself, yes that would be the only way.

 

You started this thread suggesting the code cannot connect to the database, posted the two lines mysql_connect/mysql_select_db code, without stating what symptom you got that makes you believe the problem is because of the database connection.

 

In reply #2, your statement - "I just cant see the products on the list if i click on it" is pointless (except it probably does indicate that the page is getting information out of the database to produce links for the products) because you haven't provided any information about what list you are talking about, what code and data produced that list, if the links in the list are correct, what exactly happened when you clicked on a link, what the code is that runs when a link is clicked, what output you did get, what was incorrect about that output, what the expected output was supposed to be ...

 

You don't have enough experience with php to know how to set its error reporting/display errors settings to get php to help you. And when you did do this, you cannot determine the meaning of an undefined variable message.

 

In reply #10 I suggested some specific things that you would need to look at to pin down where the problem is occurring at. Your reply was - "I cannot load products or users". That doesn't tell us anything useful, without the complete code and data that reproduces that symptom.

 

In reply #13, you posted some code, but didn't state exactly what symptom you got that leads you to believe there is a problem with that code. You didn't state or show what output you got from that code, what was wrong with that output, and what the expected output should have been. The only thing that code showed is there is nothing in that piece of posted code that has anything to do with php4 vs php5 and that the person who originally wrote this code didn't know anything about securing web pages.

 

You seem to think that there is an exact one to one relationship between each symptom and the problem causing that symptom or that someone can tell you exactly what your code is doing that is no longer working when the php version or more likely the php.ini settings changed, without seeing your code and at least an example of your data. Programming does not work that way. It's impossible to tell what is causing any one symptom without seeing the code and data that produces that symptom. In programming, due to its general purpose nature and multiple ways of accomplishing any task, there is not a one to one relationship between any symptom and what is causing it. Six different people could have written code that implements the same application and they could all be getting the same exact symptom, but the actual cause could be different in each case because of differences in server settings or in their actual code, data, and methodology used to implement the application.

 

The only way anyone in a help forum can help you fix any one symptom or error is if you post all the relevant code and data needed to reproduce that symptom or error, state exactly what output, symptom, or error you got (and if you got a blank page, what does the 'view source' of that blank page show in your browser) , and usually state what the expected output should have been.

 

Sorry for the above 'reading the riot act' to you, but we are not standing right next to you and only see the information you supply. You want a specific answer based on vague 'the code worked before, doesn't now' statements, but we cannot tell you anything specific without specifically having the relevant code and data.

K, I've solved that problem, now I have another problem, If i click the button "opslaan" It gives me an error, I've been searching for the error on internet but I still don't know how to fix that, the error should be : Error while reading : TypeError: besteldArray.item(rij).firstChild is null, As far as i see it says the FirstChild is 0, How can i fix that?

The code where it says so is :

function handleOpslaan()
{
if (xmlHttp.status == 200)
{
	try
	{
		var xmlResponse = xmlHttp.responseXML;
		var xmlRoot = xmlResponse.documentElement;
		var fout = document.getElementById("fout");
		var foutcode = xmlRoot.getElementsByTagName("errorcode")[0].childNodes[0].nodeValue;
		if (foutcode != 0)
		{
			fout.innerHTML = "Fout bij het schrijven naar de Database. Probeer het nogmaals.";
		}
		besteldArray = xmlRoot.getElementsByTagName("bestel");
		var besteld;
		for (var rij=0; rij < besteldnodeList.length; rij++)
		{
			besteld = document.getElementById("besteld_" + (rij+1));

			if (besteldArray.item(rij).firstChild.data != "-")
			{
				besteld.innerHTML = besteldArray.item(rij).firstChild.data;
			}
			else
			{
				besteld.innerHTML = "";
			}
		}
	}
	catch(e)
	{
		alert("Fout bij het lezen: " + e.toString());
	}
}

Thanks

Guest
This topic is now 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.