Jump to content

Recommended Posts

Hi,

 

I'm a graphic design student and have no PHP experience, however, I need to incorporate a guestbook into my Flash website.

I downloaded a customisable guestbook and customised it to fit in with my site, but it doesn't work, could someone have a look

at the PHP for me and see if that's where I'm going wrong.

 

Thanks in anticipation of your help,

dan

Link to comment
https://forums.phpfreaks.com/topic/84913-beginner-php-guestbook/
Share on other sites

Hi,

 

By doesnt work, I mean it posts no results back to the guestbook.

 

The guestbook can be seen at www.thismeatisfresh.com, then by clicking on book of meat link at top right corner.

 

Here is the script:

 

<?php

 

//---------------------------------------------- DO NOT CHANGE FOLLOWING (UNLESS U KNOW WHAT UR DOING) -------------------//

 

if(isset($_POST['name'])){

//retrieve variables

$name = $_POST['name'];

$email = $_POST['email'];

$message = $_POST['message'];

$date = date("Y-m-d");

}

 

 

//create connection to the database

$conn = mysql_connect($host, $username, $password) or die("could not connect to server");

$select_db = mysql_select_db($db,$conn);

 

if(isset($_POST['name'])){

//insert entry into guest book

$insertSQL = "INSERT INTO guestbook_tbl (Name, Email, Message, Date) VALUES ('$name', '$email', '$message', '$date')";

$rs = mysql_query($insertSQL,$conn);

 

if($rs){

  //insertion was successful now lets send back to flash all entries in the database in XML Format

  retrieveData();

}else{

  echo '&entryadded=FAIL&';

  exit();

}

 

}else{

retrieveData();

}

 

 

function retrieveData(){

    global $conn;

 

//get entries from guestbook

    $selectSQL = "SELECT * FROM guestbook_tbl ORDER BY ID DESC";

    $rs = mysql_query($selectSQL,$conn);

 

//generate the xml file

echo "<?xml version=\"1.0\"?>\n";

echo "<entries>\n";

 

while($row = mysql_fetch_assoc($rs)){

echo "<log>\n";

echo "<name>".$row['Name']."</name>\n";

echo "<email>".$row['Email']."</email>\n";

echo "<date>".$row['Date']."</date>\n";

echo "<message>".$row['Message']."</message>\n";

echo "</log>\n";

}

#now lets end the xml file

echo "</entries>\n";

 

 

#close the mySQL connection

mysql_close($conn);

}

?>

 

Thanks for the reply,

dan

Remove your login details from the post (but not the script).

 

Change (in two places)

$rs = mysql_query($insertSQL,$conn);

 

to

 

$rs = mysql_query($insertSQL,$conn) or die ("Error in query: $insertSQL " . mysql_error());

 

And post the error.

 

$rs = mysql_query($selectSQL,$conn) or die ("Error in query: $selectSQL " . mysql_error());

 

 

Hi,

 

could only find it in one place,

 

It's not to replace this line as well is it?

 

$rs = mysql_query($selectSQL,$conn) or die ("Error in query: $selectSQL " . mysql_error());

;

 

Thanks again,

dan

 

Cool, I've done that and realised I had the database name wrong in the login details so changed that too.

 

Now at http://www.thismeatisfresh.com/process.php

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/.hesta/graphikdzine/thismeatisfresh.com/process.php on line 56

 

 

Thanks,

Dan

Something is still wrong with the connection, try this code and put your connection parameters up top.

 

<?php
//put your connection info up here

$name = "Test";
$email = "Email@email.com";
$message = "Message";
$date = date("Y-m-d");

//create connection to the database
$conn = mysql_connect($host, $username, $password) or die("could not connect to server");
$select_db = mysql_select_db($db,$conn);

$insertSQL = "INSERT INTO guestbook_tbl (Name, Email, Message, Date) VALUES ('$name', '$email', '$message', '$date')";
$rs = mysql_query($insertSQL,$conn) or die ("Error in query: $insertSQL. " . mysql_error());

   if($rs){
     echo "ADDED";
   }else{
     echo 'FAILED' .mysql_error();
     exit();
   }
   


?>

   

1 Test Email@email.com Message 2008-01-07

      2 Test Email@email.com Message 2008-01-07

      3 Test Email@email.com Message 2008-01-07

      4 Test Email@email.com Message 2008-01-07

      5 Test Email@email.com Message 2008-01-07

      6 Test Email@email.com Message 2008-01-07

      7 Test Email@email.com Message 2008-01-07

      8 Test Email@email.com Message 2008-01-07

 

 

I'm seeing this yeah, is that right, I presume it is?

 

Dan

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.