Page 1 of 1
Help: PHP w/ mySQL on MacOS 10.3: no connection to localhost
Posted: Fri Nov 21, 2003 11:51 am
by imme
Hi,
I got a big problem with MacOS X, PHP and mySQL. I installed mySQL and PHP and both are running (I can do mySQL stuff through the Terminal and phpMyAdmin) but php scripts which have been working on other machines don't work on my localhost. There is no error, it just isn't doing anything.
Thank you in advance!
- imme
Posted: Fri Nov 21, 2003 11:55 am
by mrvanjohnson
phpMyAdmin is a web based PHP application so if that's working then everything seems like it's set up correctly. What's the error message you are getting?
What is the address you use to connect to phpMyAdmin?
Drop a
into your web server root and see what you get.
Posted: Fri Nov 21, 2003 12:02 pm
by imme
phpmyadmin runs on localhost...
that what's confussing me so much. it seems to be set up correctly.
I get no error message. The select statements don't fetch any data or it is not displayed. I don't know...

Posted: Fri Nov 21, 2003 12:10 pm
by mrvanjohnson
Run a phpinfo and let establish that is OK. Also post some of your code. Sounds more like a coding problem than anything else.
Post the Select statment you are trying
Posted: Fri Nov 21, 2003 12:22 pm
by imme
phpinfo works
here's one simple code example that does not work:
(it does work perfectly fine on our ISP server)
<?php
/* connect db */
mysql_connect("localhost");
mysql_select_db("kaspar");
?>
<HTML>
<HEAD>
<title>Telefonverzeichnis</title>
</HEAD>
<BODY>
<H2>Telefonverzeichnis</H2>
<!----------- Eingabemaske----------------------->
<form action="telefon.php" method="post">
<input type="Hidden" name="ersteraufruf" value="1">
<table border="0" align="center">
<tr>
<td>Name:</td>
<td><input type="Text" name="name"></td>
</tr>
<tr>
<td>Vorname:</td>
<td><input type="Text" name="vorname"></td>
</tr>
<tr>
<td>Telefon:</td>
<td><input type="Text" name='telnr'></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="Text" name='email'></td>
</tr>
<tr>
<TD COLSPAN="2" ALIGN="CENTER"><input type="Submit" value="Abschicken"></td>
</tr>
</table>
</form>
<!----------- Auswertung der Eingabe ----------------------->
<table border=0 >
<tr>
<B>
<td>Name:</td>
<td>Vorname:</td>
<td>Telefonnummer:</td>
<td>Email:</td>
</B>
</tr>
<?php
//-------------------- Eingabefelder auswerten---------------
if ($ersteraufruf==1) {
if ($name=="" || $vorname=="" || $telnr=="" || $email=="" ) {
?>
<script>
window.alert('Bitte alle Felder ausfüllen.');
</script>
<?php
} else {
// -------------------- Werte in Db eintragen---------------
$datum=date("Y-m-d");
mysql_query
("INSERT INTO kk_tel (name,vorname,telnr,email) VALUES ('$name','$vorname','$telnr','$email')");
}
}
// --------------------Ausgeben alle Datens‰tze der DB ---------------
// -------------------- SQL-Statement ausfü ren---------------
$anweisungs_id=mysql_query
("SELECT name,vorname,telnr,email FROM kk_tel ORDER BY name");
// -------------------- Anzahl der Datens‰tze ---------------
$num = mysql_numrows($anweisungs_id);
// -------------------- Datensätze Zeile f¸r Zeile ausgeben---------------
for($i=0;$i<$num;$i++)
{
// -------------------- eine Zeile vorbereiten ---------------
$zeile = mysql_fetch_array($anweisungs_id);
$name=htmlspecialchars($zeile["name"]);
$vorname=htmlspecialchars($zeile["vorname"]);
$telnr=htmlspecialchars($zeile["telnr"]);
$email=htmlspecialchars($zeile["email"]);
// --------------------eine Zeile ausgeben---------------
echo "<tr>
<td>$name</td>
<td>$vorname</td>
<td>$telnr</td>
<td><a href='mailto:$email'>$email</a></td>
</tr>";
}
?>
</table>
</BODY>
</HTML>
<! -------------------- Verbindung zur DB schliessen--------------->
<?php
mysql_close();
?>
Posted: Fri Nov 21, 2003 12:49 pm
by mrvanjohnson
OK very good. What doesn't work? Does the page not display when you first attempt to hit it or is it after you try to submit the form.. A little more information please.
You might want to edit your last post and throw your code into [ code ] tags.
Posted: Fri Nov 21, 2003 1:09 pm
by mrvanjohnson
Alright first question, is this file telefon.php? So in other words you are submitting back to itself right?
Next question, after you POST you don't seem to pick up the variables again fro mthe POST. Unless you have register_globals=ON this will not work.
Next, depending on the status of "$ersteraufruf" (which I can't find defined anywhere in your code before the IF statment) you do an insert. Then regardless of the INSERT you turn around and do a SELECT to fill you table at the bottom of the page. But you don't actually grab the data you just get a [php_man]mysql_numrows[/php_man] and then go into a for loop. I think what you wanted to do here was something like this
Code: Select all
<?php
while ($zeile = mysql_fetch_array ($anweisungs_id)){
echo "<tr>
<td>".$zeile['name']."</td>
<td>".$zeile['vorname']."</td>
<td>".zeile['telnr']."</td>
<td><a href="mailto:".$zeile['email']."">".$zeile['email']."</a></td>
</tr>";
}
?>
in place of this chunk of code
Code: Select all
$num = mysql_numrows($anweisungs_id);
// -------------------- Datens&auml;tze Zeile f¸r Zeile ausgeben---------------
for($i=0;$i<$num;$i++)
{
// -------------------- eine Zeile vorbereiten ---------------
$zeile = mysql_fetch_array($anweisungs_id);
$name=htmlspecialchars($zeileї"name"]);
$vorname=htmlspecialchars($zeileї"vorname"]);
$telnr=htmlspecialchars($zeileї"telnr"]);
$email=htmlspecialchars($zeileї"email"]);
// --------------------eine Zeile ausgeben---------------
echo "<tr>
<td>$name</td>
<td>$vorname</td>
<td>$telnr</td>
<td><a href='mailto:$email'>$email</a></td>
</tr>";
}
Also I think in your situation, you would mainly use the [php_man]htmlspecialchars[/php_man] during the insert of data into your database.
Hope some of this helps.
Posted: Sat Nov 22, 2003 9:53 am
by imme
hi mrvanjohnson,
thanks for your help so far. I guess it really is a coding problem. Funny that it works on the ISP server, though.
I'll try your suggestions. Unfortunately, I won't get to do that before Monday...
- imme
Posted: Sat Nov 22, 2003 2:03 pm
by mrvanjohnson
Just let us know how it goes.
Posted: Thu Dec 11, 2003 3:33 am
by imme
Besides the badly written script, the problem turned out to be a configuration error. Since I'm using a relatively new PHP version, "Register_globals" in the php.ini was by default set to "off".
