Jump to content

Only ID and Date is writing to MySql


kristiankeith

Recommended Posts

If anyone can assist me I would appreciate it. I have been trying to make this work for the past 3 days. I am doing a simple guestbook with PHP into MySQl and it connects, the ID and Date stamps work and appear in the guestbook but the name, email, hometown and comments do not. Here is the code. Again thank you in advance for any assistance.

 

<body bgcolor="#000000">

 

<?php

$host="localhost"; // Host name

$username=""; // Mysql username

$password=""; // Mysql password

$db_name=""; // Database name

$tbl_name="guestbook"; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect server");

mysql_select_db("$db_name")or die("cannot select DB");

 

$date=date("y-m-d"); //date

 

$sql="INSERT INTO $tbl_name(name, email, hometown, comments, date)VALUES('$name','$email','$hometown','$comments','$date')";

$result=mysql_query($sql);

 

//check if query successful

if($result){

echo "Successful";

echo "<BR>";

echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page

}

 

else {

echo "ERROR";

}

 

mysql_close();

?>

 

Link to comment
Share on other sites

I recognize the code (i was on that website TOO).

And what I got needed to be tinkered with before it would work.  Try re-reading the webpages before it to make sure any files or code that was used in a tutorial PRIOR to this one, are written properly and in your pocession.

 

Check to make sure all the file names and field names follow the same structure.  Good luck!

Link to comment
Share on other sites

I see what mikosiko is saying.

Your DATE is being GIVEN on the same page.  So date and ID (which I assume is automated by the table) are sort of a guarantee.  If you're putting data in for the other fields from a form, you need to MATCH the 'name' in the form with the 'name' in this script so that it can be put into the table (make sense).

Backtrack your steps, and make sure the form ACTION is naming THIS FILE with EXTENSION.

Link to comment
Share on other sites

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.