Page 1 of 1

writing records to databases not working.

Posted: Tue May 09, 2006 10:33 pm
by clemson_guy2001
Hi,
I'm new to this forum & infact am new to PHP also.
i was successful in generating some php code to write records into a table.
everything was fine for couple of months & since yesterday, same is not working when am trying to write records into a table.
I've checked with my hosting server who claims that everything from their end is good.
I've not changed any code in my files which used to work perfect until yesterday.

Here is the problem.
whenever I attempt to write a record into a table, it's inserting a record but only date field is getting populated & all other fields are empty.

here is my php code for database T1_DB & table T1_table

Code: Select all

<?php

include "config.php";

// connect to the mysql server
$link = mysql_connect("localhost", "user_name", "guest")

or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db("T1_DB")
or die ("Could not select database because ".mysql_error());

$Date = getdate();
// insert data into database
$insert = mysql_query("INSERT INTO `T1_table` (`Name`, `EMail`, `Comment`, `Date`, `URL`) VALUES ('$Name', '$Email', '$Comment', NOW(), '$url')", $link)
or die("Could not insert data because ".mysql_error());

mysql_close();

?>
& Here is my HTML form for input.

Code: Select all

<form action="form.php" method="post">
                      <table width=400 cellspacing=0 cellpadding=2 border=0>
                        <tr> 
                          <td> <font face=times color="003366"> Name<br>
                            <input type=text name="Name" value="">
                            </font> </td>
                        </tr>
                        <tr> 
                          <td> <font face=times color="003366"> E-Mail<br>
                            <input type=text name="Email" value="">
                            </font> </td>
                        </tr>
                        <tr> 
                          <td> <font face=times color="003366"> Comment<br>
                            <textarea wrap=virtual rows=5 cols=35 name="Comment" ></textarea>
                            </font> </td>
                        </tr>
                        <tr> 
                          <td> <font face=times color="003366"> URL<br>
                            <input type=text name="url" value="">
                            </font> </td>
                        </tr>
                        <tr> 
                          <td> <font color="003366"><br>
                            <font face=times> 
                            <input name="submit" type=submit value="Sign my Guestbook">
                            &nbsp;&nbsp; 
                            <input name="reset" type=reset value="Clear form">
                            </font></font> </td>
                        </tr>
                      </table>
                    </form>
Appreciate any help to fix this problem.

Posted: Tue May 09, 2006 10:47 pm
by hawleyjr
Welcome to the forum.

What does your table look like?

Run this query:

Code: Select all

SHOW CREATE TABLE T1_table

Posted: Tue May 09, 2006 10:56 pm
by clemson_guy2001
thanks for your quick reply.
here is the table structure.

Code: Select all

CREATE TABLE `T1_table` (
 `Name` varchar(100) NOT NULL default '',
 `EMail` varchar(100) NOT NULL default '',
 `Comment` longtext,
 `Date` date default NULL,
 `URL` varchar(100) default NULL
) TYPE=MyISAM

Posted: Tue May 09, 2006 11:01 pm
by hawleyjr
Where do the variables get there values from?

'$Name', '$Email', '$Comment', '$url'

Also, have you echoed out the query to see what it is trying to insert?

Posted: Tue May 09, 2006 11:18 pm
by clemson_guy2001
Variable values come from HTML file (code shown in my 1st post).
HTML form calls PHP code & also sends the variable values.

I inserted following line right before insert statement, but when i executed, I don't see any output :cry:

Code: Select all

echo $Name;

Posted: Tue May 09, 2006 11:20 pm
by hawleyjr
Try:

$_POST['Name']

$_POST['Email']

$_POST['Comment']

$_POST['url']

In place of the variables.

Posted: Tue May 09, 2006 11:23 pm
by John Cartwright
you have register globals turned OFF, which is a good thing! To understand why your script won't work read http://ca3.php.net/manual/en/security.globals.php