Solved

add entry fails ?

Posted on 2008-10-16
11
3,533 Views
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 ?
<HTML>
 <HEAD>
  <TITLE>Add Log Entry</TITLE>
 </HEAD>
 <BODY>
  <H1>Add an Entry</H1>
  <form method="POST" action="add.php">
   <b>Title:</b><br>
   <input type="text" name="entry"><br>
   <b>log Entry:</b><br>
   <textarea cols="60" rows="6" name="entrytext"> 
   </textarea><br>
  <input type="submit" name="submit" value="Submit">
  </form>
 </BODY>
</HTML>
.... add.php....
<?php
  if ($HTTP_POST_VARS['submit']) {
    mysql_connect('localhost','admin','admin');
    mysql_select_db('tables');
    $entrytitle=$HTTP_POST_VARS['log.entrytitle'];
    $entrytext=$HTTP_POST_VARS['log.entrytext'];
    $query ="INSERT INTO weblog (entrytitle,entrytext)";
    $query.=" VALUES ('$entrytitle','$entrytext')";
    $result=mysql_query($query);
    if ($result) 
	echo "<b>Successful</b>";
      }
 ?>

Open in new window

0
Comment
Question by:pillmill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
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

0
 
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

0
 

Author Comment

by:pillmill
ID: 22728991
Thanks.
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 ?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 10

Expert Comment

by:iamanindian
ID: 22729212
Is your code block at all getting hit? What I mean is:
===================================================
<?php
  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?

Regards
WC
0
 
LVL 36

Accepted Solution

by:
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

<?php

print_r ($_POST);

?>


phpinfo.php
 
<?php
echo phpinfo();
?>

Open in new window

0
 

Author Comment

by:pillmill
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:\PROGRA~2\MICROS~2\VC98\ATL\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\MFC\INCLUDE" "--with-extra-libs=
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.*
0
 

Author Comment

by:pillmill
ID: 22732491
I tried to test _POST.
It fails to return a value in this simple example:
What is the problem ?
<html>
 <body>
   <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"/>
  </form>
 </body>
</html>
 
-----process.php------
 <?php
  echo "emp name is : " . $_POST['emp_name'] . "<br/>";
  echo "salary is : " . $_POST['emp_sal']; 
 ?>

Open in new window

0
 
LVL 36

Expert Comment

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

Author Comment

by:pillmill
ID: 22733340
Thanks.
register_globals=OFF
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
highlight.bg	#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
 
apache2handler
Apache Version 	Apache/2.2.8 (Win32) PHP/5.2.6 JRun/4.0
Apache API Version 	20051115 

Open in new window

0
 

Author Comment

by:pillmill
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']; ?>
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 22738583
Hi,

How did you fix this issue?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 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