Help: PHP w/ mySQL on MacOS 10.3: no connection to localhost
Moderator: General Moderators
Help: PHP w/ mySQL on MacOS 10.3: no connection to localhost
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
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
- mrvanjohnson
- Forum Contributor
- Posts: 137
- Joined: Wed May 28, 2003 11:38 am
- Location: San Diego, CA
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.
What is the address you use to connect to phpMyAdmin?
Drop a
Code: Select all
<?php
phpinfo () ;
?>- mrvanjohnson
- Forum Contributor
- Posts: 137
- Joined: Wed May 28, 2003 11:38 am
- Location: San Diego, CA
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();
?>
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();
?>
- mrvanjohnson
- Forum Contributor
- Posts: 137
- Joined: Wed May 28, 2003 11:38 am
- Location: San Diego, CA
- mrvanjohnson
- Forum Contributor
- Posts: 137
- Joined: Wed May 28, 2003 11:38 am
- Location: San Diego, CA
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
in place of this chunk of code
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.
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>";
}
?>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>";
}Hope some of this helps.
- mrvanjohnson
- Forum Contributor
- Posts: 137
- Joined: Wed May 28, 2003 11:38 am
- Location: San Diego, CA