PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello all i encounterd a problem wich i can't solve myself as i am no php wizard or any of that. I recently started on a website and a buddy of mine done the scripting in php but as he is out of the country for his work and won't be back for ages i am wondering if any of you would be able to assist me with the following problem. I whant to add a guestbook to a existing site / page system but it won't work for me. I tried it with a include or just plain copy paste add code thingy but everytime i try something the website gets kinda screwd .
http://www.zoef-design.be/villa/en/guest.php this is what happens. Curently i don't have a guestbook running as it doesn't work with any of the guestbooks i tried it with. So i was hoping someone could give me some pointers or maybe a way wich would work.
<?php
//First let's connect to the database
$connection = mysql_connect("your server name goes here", "the username goes here", "the password goes here");
update_data();//we call it when page load
function update_data()
{
$update_query = "SELECT* from yourTableName ORDER BY id DSC";/*yourTableName: is the table in the database that contain the guestbook data*/
$guestbook = mysql_query($update_query, $connection) or die ("can't display the comments");
// display all the comments
while($row= mysql_fetch_array($guestbook)){
echo "<div class=\"comment\">";
echo"Name:<p class=\"name\">" .$row['name'] . "</p>";
echo"Comments:<p class=\"comment\">" .$row['comments'] . "</p>";
}
}
if(isset($_POST['submit'])){we will do do this only when the user submit the comment
//lets retrieve the sended variables via POST
$name = mysql_real_escape_string($_POST['name']); /*clean the name from slashes or other caracter tha may mess our data base up*/
$email = mysql_real_escape_string($_POST['email']);
$url = mysql_real_escape_string($_POST['url']);
$comments = mysql_real_escape_string($_POST['comments']);
//prepare the query
$query = "INSERT into yourTableName(name, email, url, comments) VALUES('{$name}', '{$email}', '{url}', '{comments}')";
//execute the query
mysql_query($query, $connection) or die ("sorry we coudln't add ur comments");
update_data();//let's update our page to display th new comment submitted
}
?>
ps: please not that this code will display all the comments not as sections like 1 2 3 4 last>
this will need some more work
and you can style the comment div etc.. i hope this is helpfull for you
foregive me if i miss-typed something or i missed something
first question
"wich guest book did you use?"
i just come up with it it is a simple example
"wich sql setting i use"
i think u should give a cal to ur host to provide you with the data base account username and password and the server too
Thats not what i was talking about. I know my username and pasw and all the other things. What i was wondering was wich tables you made and so on and so fort. As i said my php knowladge lacks greatly and as that lacks also does my mysql I would greatly appreciate of anyone could use a existing php guestbook and explain to me how i can intigrate it into my existing website.
It is simple you just create a table with 4 field
name the table gustbook for example
an ID : type:INT(5) make it AUTOINCREMENT
Name: type :varchar and length make it 50 for example
email: type :varchar and make it 50 length
comments : type: text don't specify the lenght keep it blank
all that you can do it with phpMyAdmin on ur server