i have attached the fla file of my guestbook which does not seem to work.
could you please download and help me?
the code for the php script is as follows:
code for postguestbook.php is:
<?php
$db=mysql_connect("http://members.lycos.co.uk/myperception","myperception","password");
mysql_select_db("myperception_uk_db",$db);
$request1=insert into guestbook values(a,b);
$result1=mysql_query($request1);
$request2=select * from guestbook;
$result2=mysql_query($request2);
$desiredContent=mysql_fetch_array($result2,MYSQL_ASSOC);
mysql_free_result($result1);
mysql_free_result($result2);
print "guestbook=$desiredContent[guestbook]";
?>
//Code for viewguestbook.php is:
<?php
$db=mysql_connect("http://members.lycos.co.uk/myperception","myperception","password");
mysql_select_db("myperception_uk_db",$db);
$request=select * from guestbook;
$result=mysql_query($request2);
$desiredContent=mysql_fetch_array($result2,MYSQL_ASSOC);
mysql_free_result($result);
print "guestbook=$desiredContent[guestbook]";
?>
i could not attach the php scripts because the forum allows only one file to be attached.
please see through the php scripts and download the .fla and help me.
note: the password in the php scripts was intentionally typed as password because i was posting the php scripts in the forum.
1- Your Flash is wrong. There are a few problems with it, and I’m not going to explain what is wrong with it yet. I’m just going to give you the answer you are looking for.
because you are using the “POST” method, there is no reason to put the variables in the query string. Change the code on your button to this:
on(release){
loadVariablesNum("http://members.lycos.co.uk/myperception/postguestbook.php", 0,"POST");
a=b="";
}
2- because you are using the post method, you have to use the $_POST[] method to grab them from the script. Your php should look something like this:
<?php
$a = $_POST['a'];
$b = $_POST['b'];
$db=mysql_connect("http://members.lycos.co.uk/myperception","myperception","password");
mysql_select_db("myperception_uk_db",$db);
$request1 = "insert into guestbook values('$a','$b')";
$result1 = mysql_query($request1);
$request2 = "select * from guestbook";
$result2 = mysql_query($request2);
$desiredContent = mysql_fetch_array($result2);
print "guestbook = " . $desiredContent[guestbook];
?>
I have a few questions about the PHP script… a) Why is there a second script? You don’t need that because you do exactly the same thing in the first script. b) what is that last line doing? I understand that its printing it out, but why does it say ‘guestbook’ in the brackets, and why are the brackets there?
for your variable $request1 I think you have to do this:
$request1 = "INSERT INTO guestbook tableName(field1, field2) VALUES('$var1', '$var2')";
Just put the name of your table where it says tableName and the names of your fields in spots 1 and 2.
the viewguestbook.php is run when somebody is just viewing all the entries of the guestbook.
the postguestbook.php is run when somebody wants to add to the guestbook.
for eg: Mr.X wants to read all the entries in my guestbook so I run viewguestbook.php. And If Mr.Y wants to add to my guestbook then I have to insert his comments and also display them - this is done in postguestbook.php.
Also the insert statement is correct. One does not need to write the column values if one passes the column values in the proper order- ie. in the order in which the table was created.
hey, jubba i remember you did prepare a guestbook for me and even hosted that on your server. Please pardon me for not using it. I HAD TO HAVE MY OWN GUESTBOOK. So I searched for a free PHP host, learnt a bit of PHP. Sorry, if I do sound haughty.
THANK YOU VERY MUCH JUBBA. Hope your suggestions work!
sorry, jubba i did make the two corrections you asked me to make. ie. changing the code in the on(release) function and in the php script. but it does not seem to work. could you please tell me what else is wrong?
thanks.