Jump to content

mysql in template possible?


wishbone
 Share

Recommended Posts

A form across 3 pages runs some mysql script in the last page (send email etc). The mysql code is included in the template (as are the forms as well).

Everything is fine, only the last page gives "Internal Server error".

When packed in a php file (without template), the mysql is executed fine.

Is it not possible to pack mysql code into a template or where is the mistake?

Link to comment
Share on other sites

Any chance you could specify exactly what (or how) you're trying to do? I don't see a relation between sending email and MySQL, so I'm a bit confused here :)

If it's SQL you're talking about, that shouldn't be a problem at template level, but you should probably run it through PW's own $db object:

$sql = "SELECT * FROM my_table WHERE my_field RLIKE 'my value'";

$result = $db->query($sql);
while ($row = mysqli_fetch_assoc($result)) {
    echo "this is a row from database: {$row['my_column']}";
}
  • Like 1
Link to comment
Share on other sites

thx!

It's an existing script, and it runs with another database than the PW install. It has to be integrated into the new PW site.

I don't know nothing about sql, so, sorry, I can't adapt it to PW's own $db object...

This is when Designers, starting to dream of processwire, get to their limitations...

it's these queries:

$connect = mysql_connect("rdbms.strato.de","user","password") or die
("Keine Verbindung moeglich");
mysql_select_db("DBxxx") or die
("Keine Verbindung moeglich");

$anfragedatum=date("d-m-Y");
$sql1 = "INSERT INTO fuhrung (anfragedatum,vorname,name,[...]) VALUES ('$anfragedatum','$vorname','$name', [...])";
mysql_query($sql1);

$sql2 = "Select * from login";
$ergebnis = mysql_query($sql2) OR die("Anfrage fehlgeschlagen: " . mysql_error());
    while ($row =mysql_fetch_array($ergebnis)) {
    $empfaenger2=$row['benutzermail'];
    mail($empfaenger2, $betreff, $text,
"From: [...]");

It is not the same database as the PW install...


 

Link to comment
Share on other sites

It's starting to make sense now :)

Only reason this could break (that I can think of right now) is that you've got multiple database connections open, so it might be necessary to define which connection is used here, like this:

mysql_query($sql1, $connection);

If that doesn't help, there's probably something else we're missing. You're getting "internal server error" by running this -- any chance you could take a look at Apache (web server) error log somehow? There should be a more detailed description of this error there.

PW has it's own error log at /site/assets/logs/errors.txt, which you should also take a look at and another thing you could try (unless this is a live site already!) would be turning ProcessWire debug mode on from /site/config.php. This might give you a bit more information about the nature of this error (though in this case I don't think PW will have a chance to actually put anything there..)

  • Like 2
Link to comment
Share on other sites

sry $connection didn't help. Server error logs I don't have access to.

But don't ask me why I had the idea to test every piece of the script...

so I found out part of it works...

only if no email has been entered, an "Internal server error" is thrown!

If email is specified - everything works fine!

It doesn't work in the templates directory - is that right? I put it in root.

Thank you for your help!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...