Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

MySQL problems when using MySQL within a custompage.

Heya!
I got a little problem.. I created a new page with this code inside
CodeDownload  

<form action="http://svartpeppar.net/viewpage.php?page_id=8" method="post">
<table>
<tr><td><b>Låntagare</b></td><td><input type="text" name="name"></td></tr>
<tr><td><b>Summa</b></td><td><input type="text" name="summa"></td></tr>
<tr><td valign="top"><b>Ev. kommentar</b></td><td><textarea name="comment"></textarea></td></tr>
<tr><td></td><td><input type="submit" value="Spara"></td></tr>
</table>
</form>

<?php
$name=$_POST['name'];
$summa=$_POST['summa'];
$comment=$_POST['comment'];
$date   = date("d/m/y");
$owner=$userdata['user_name'];
             
$connection = mysql_connect("localhost", "xxx", "xxx") or die("Kunde inte skapa koppling!");
            
mysql_select_db("xxx") or die("Kunde inte välja databas");
$laggTill = "INSERT INTO my_loans (date, owner, name, summa, comment) VALUES ('$date', '$owner', '$name', '$summa', '$comment')";

mysql_query($laggTill) or die("Det gick inte att lägga till information!");
print("Lånet är registrerat!");
          
mysql_close($connection);
?>



And when I fill in the formula it first create a blank line (except date and owner) in the mysql table and then on the next row it stands perfect. When I run this script from outside phpfusion it'll behave as it should but as fast as I run it from a custom page this happens. Why ?

The printtag after mysql_query($laggTill) also prints before even the submitbutton is used along with "No database is selected". The database I'm using i correctly spelled and everything and the script really adds a new line in the mysqltable anyway (but with a nearly blank line in front of it). Why is phpfusion acting like this and what do I do wrong?

Quote

And when I fill in the formula it first create a blank line (except date and owner) in the mysql table and then on the next row it stands perfect. When I run this script from outside phpfusion it'll behave as it should but as fast as I run it from a custom page this happens. Why ?

You do not check if there is a value in $_POST. You write into the DB every time you access this page. use:
CodeDownload  
if(!empty($_POST['name'])){
//Yourcode
}


for instance. (usually you check for the input name, but your input does not have a name)

The "no Database slected" is probably put out by php-fusion, because you closed the database connection ad thus also the one of php-fusion. you should either use the same database or reopen/reselct php-fusion's database connection after finishing your script.
omg, it was that simple =) Thank you!

But why am I closing php fusions connection? They have the same name or what? I mean, I do wanna close My connection - don't I? ^^

Well, thanks for a real quick answer!
Yes, but you selected a database. You have to select PHP-Fusions Database after closing your script so PHP-Fusion can query its database again.
e.g:
mysql_select_db($db_name);
Not really support of me but i think you may be happy with a little problem :)
Sometimes we get sql errors because of to much ppl online @ the same moment requesting the same page...
Thats not funny :):p
thanks Matanor for your big help! And I guess I should thank you JurjenD too for the hint :)
Thread Information
Author
Replies
6 posts
Views
1,564 times
Last Post
Last updated on 13 years ago
You can view all discussion threads in this forum.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.