writing records to databases not working.

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!

Moderator: General Moderators

Post Reply
clemson_guy2001
Forum Newbie
Posts: 3
Joined: Tue May 09, 2006 10:16 pm

writing records to databases not working.

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Welcome to the forum.

What does your table look like?

Run this query:

Code: Select all

SHOW CREATE TABLE T1_table
Last edited by hawleyjr on Tue May 09, 2006 10:56 pm, edited 1 time in total.
clemson_guy2001
Forum Newbie
Posts: 3
Joined: Tue May 09, 2006 10:16 pm

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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?
clemson_guy2001
Forum Newbie
Posts: 3
Joined: Tue May 09, 2006 10:16 pm

Post 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;
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Try:

$_POST['Name']

$_POST['Email']

$_POST['Comment']

$_POST['url']

In place of the variables.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Post Reply