add entry fails ?

Posted on 2008-10-16
Last Modified: 2013-12-13
I want the webpage to add an entry to a MySQL database table, on submit.
The following .htm and php fails to add an entry to the table, but does not
generate an error. What is the problem ?


  <TITLE>Add Log Entry</TITLE>



  <H1>Add an Entry</H1>

  <form method="POST" action="add.php">


   <input type="text" name="entry"><br>

   <b>log Entry:</b><br>

   <textarea cols="60" rows="6" name="entrytext"> 


  <input type="submit" name="submit" value="Submit">




.... add.php....


  if ($HTTP_POST_VARS['submit']) {





    $query ="INSERT INTO weblog (entrytitle,entrytext)";

    $query.=" VALUES ('$entrytitle','$entrytext')";


    if ($result) 

	echo "<b>Successful</b>";



Open in new window

Question by:pillmill
  • 5
  • 5
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 22728829
Try to change this line and check it

$result=mysql_query($query) or die("Could not insert, the error details,".mysql_error());

Open in new window

LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 22728835
also check on the php page whether you receive all the posted values...


print_r ($HTTP_POST_VARS);


Open in new window


Author Comment

ID: 22728991
I changed the $result and added a check on the posted values.

There is no output from -
print_r ($HTTP_POST_VARS);

The changed $result also produces no result.  The database is still not updated.

Any other possibilities ?
LVL 10

Expert Comment

ID: 22729212
Is your code block at all getting hit? What I mean is:
  if ($HTTP_POST_VARS['submit']) {
Is this IF condition getting satisfied? Did you check server configuration? Perhaps you can see this:

print_r ($_POST);

Does this return anything?

LVL 36

Accepted Solution

Loganathan Natarajan earned 500 total points
ID: 22729989
Ok,  what version of PHP you use? please create phpinfo.php and check it.

Then you can


print_r ($_POST);




echo phpinfo();


Open in new window

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.


Author Comment

ID: 22731972
Thanks. Here is the information from phpinfo():

 PHP Version => 5.2.6 System => Windows NT SYSTEM 5.1 build 2600
Build Date => May 2 2008 18:01:20
Configure Command => cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" "--with-extra-includes=
C:\Program Files (x86)\Microsoft SDK\Include;
C:\Program Files (x86)\Microsoft SDK\Lib;C:\PROGRA~2\MICROS~2\VC98\LIB;C:\PROGRA~2\MICROS~2\VC98\MFC\LIB"
Server API => Command Line Interface Virtual Directory Support => enabled Configuration File (php.ini)
Path => C:\WINDOWS Loaded Configuration File => C:\wamp\bin\php\php5.2.6\php.ini
PHP API => 20041225 PHP Extension => 20060613 Zend Extension => 220060519
Debug Build => no Thread Safety => enabled Zend Memory Manager => enabled IPv6 Support =>
enabled Registered PHP Streams => php, file, data, http, ftp, compress.zlib
Registered Stream Socket Transports => tcp, udp Registered Stream Filters => convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.*

Author Comment

ID: 22732491
I tried to test _POST.
It fails to return a value in this simple example:
What is the problem ?


   <form action="process.php" method="post">

    Name: <input type="text" name="emp_name"/>

    Salary: <input type="text" name="emp_sal"/>

    <input type="submit" value="submit"/>






  echo "emp name is : " . $_POST['emp_name'] . "<br/>";

  echo "salary is : " . $_POST['emp_sal']; 


Open in new window

LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 22733073
Can  you check whether register_global= is ON OR OFF???

Author Comment

ID: 22733340
PHP Core

Directive	Local Value	Master Value

allow_call_time_pass_reference	Off	Off

allow_url_fopen	On	On

allow_url_include	Off	Off

always_populate_raw_post_data	Off	Off

arg_separator.input	&	&

arg_separator.output	&	&

asp_tags	Off	Off

auto_append_file	no value	no value

auto_globals_jit	On	On

auto_prepend_file	no value	no value

browscap	no value	no value

default_charset	no value	no value

default_mimetype	text/html	text/html

define_syslog_variables	Off	Off

disable_classes	no value	no value

disable_functions	no value	no value

display_errors	On	On

display_startup_errors	Off	Off

doc_root	no value	no value

docref_ext	no value	no value

docref_root	no value	no value

enable_dl	On	On

error_append_string	no value	no value

error_log	c:/wamp/logs/php_error.log	c:/wamp/logs/php_error.log

error_prepend_string	no value	no value

error_reporting	6135	6135

expose_php	On	On

extension_dir	c:/wamp/bin/php/php5.2.6/ext/	c:/wamp/bin/php/php5.2.6/ext/

file_uploads	On	On	#FFFFFF	#FFFFFF

highlight.comment	#FF8000	#FF8000

highlight.default	#0000BB	#0000BB

highlight.html	#000000	#000000

highlight.keyword	#007700	#007700

highlight.string	#DD0000	#DD0000

html_errors	On	On

ignore_repeated_errors	Off	Off

ignore_repeated_source	Off	Off

ignore_user_abort	Off	Off

implicit_flush	Off	Off

include_path	.;C:\php5\pear	.;C:\php5\pear

log_errors	On	On

log_errors_max_len	1024	1024

magic_quotes_gpc	Off	Off

magic_quotes_runtime	Off	Off

magic_quotes_sybase	Off	Off

mail.force_extra_parameters	no value	no value

max_execution_time	30	30

max_input_nesting_level	64	64

max_input_time	60	60

memory_limit	128M	128M

open_basedir	no value	no value

output_buffering	4096	4096

output_handler	no value	no value

post_max_size	8M	8M

precision	14	14

realpath_cache_size	16K	16K

realpath_cache_ttl	120	120

register_argc_argv	Off	Off

register_globals	Off	Off

register_long_arrays	Off	Off

report_memleaks	On	On

report_zend_debug	On	On

safe_mode	Off	Off

safe_mode_exec_dir	no value	no value

safe_mode_gid	Off	Off

safe_mode_include_dir	no value	no value

sendmail_from	no value	no value

sendmail_path	no value	no value

serialize_precision	100	100

short_open_tag	Off	Off

SMTP	localhost	localhost

smtp_port	25	25

sql.safe_mode	Off	Off

track_errors	Off	Off

unserialize_callback_func	no value	no value

upload_max_filesize	2M	2M

upload_tmp_dir	c:/wamp/tmp	c:/wamp/tmp

user_dir	no value	no value

variables_order	GPCS	GPCS

xmlrpc_error_number	0	0

xmlrpc_errors	Off	Off

y2k_compliance	On	On

zend.ze1_compatibility_mode	Off	Off


Apache Version 	Apache/2.2.8 (Win32) PHP/5.2.6 JRun/4.0

Apache API Version 	20051115 

Open in new window


Author Comment

ID: 22733418
When I run the program and enter data in the
two textboxes, then press submit, it returns:

"; echo "salary is : " . $_POST['emp_sal']; ?>
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 22738583

How did you fix this issue?

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now