Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I created an html page contains the 1

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
I created an html page contains the following form:

<form action=&quot;insert.php&quot; method=&quot;post&quot;>
<input name=&quot;fullname&quot;>
<input name=&quot;email_address&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
<input type=&quot;reset&quot; value=&quot;Clear&quot;>
</form>
the insert php:

<?php

$connection = mysql_connect (&quot;192.168.0.2:3306&quot;, &quot;root&quot;, &quot;mypassword&quot;);
$db=&quot;test_database&quot;;
// here we check what errors if any are given
$err_no=mysql_errno();
if ($err_no > 0 ){

// if errors show them
echo mysql_errno() . &quot;: &quot; . mysql_error() . &quot;\n&quot;;

}
// here we select which database to use
@mysql_select_db($db,$connection) ;

$err_no=mysql_errno();

if ($err_no > 0 ){

echo &quot; Error: &quot; . mysql_errno() . &quot;: &quot; . mysql_error() . &quot;<br>&quot;;

exit;

}

// this is your query to be called
$query = &quot;insert into email_info values ('$fullname', '$email')&quot;;


// connect to the db and run the insert
$insert=mysql_query($query, $connection) ;

// here we check what errors if any are given
$err_no=mysql_errno();
if ($err_no > 0 ){

// if errors show them
echo mysql_errno() . &quot;: &quot; . mysql_error() . &quot;\n&quot;;

}

//show number of rows affected on successful query
printf (&quot;Records inserted: %d\n&quot;, mysql_affected_rows());

?>

I get the following message: Records inserted: 1

But the records was blank, and not as I entered in the form.

I replaced
$query = &quot;insert into email_info values ('$fullname', '$email')&quot;;
With:
$sql=&quot;INSERT into email_info (fullname,email_address) values ('$fullname', '$email')&quot;;
And
$insert=mysql_query($query, $connection) ;
With
$insert=mysql_query($sql, $connection) ;

But I get the same result!! what is wrong here???
Thanks in advance.
 
what field type and lengths are you using in your MySQL table? =================================
Imagination is more important than knowledge.
(A.E.)
 
Thank you for your answer,

Type: varchar(255)
Null: Yes
Default: NULL

But when I run the code without using the html form page, the Records insert in the database correctly.
i.e.

$query=&quot;INSERT into email_info (fullname,email_address) values ('myname', 'myemail')&quot;;
 
What version of PHP do you have ....
maybe you need to use $_POST[fullname] and $_POST like :

$sql=&quot;INSERT into email_info (fullname,email_address) values ('[b]$_POST[fullname][/b]', '[b]$_POST[email][/b]')&quot;;
<hr>
There's no present like the time, they say. - Henry's Cat.
 
I have the PHP Version 4.2.0. thank you very much KarveR, now the code is working ery good when i used $_POST
 
I have the PHP Version 4.2.0. thank you very much KarveR, now the code is working very good when i used $_POST
 
KarveR
I tried to edit the “add.php” included in the news posting script as following:

<?
if (!$submit)
{
?>
<table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot;>
<form action=&quot;<? echo $PHP_SELF; ?>&quot; method=&quot;POST&quot;>
<tr>
<td valign=&quot;top&quot;><b><font size=&quot;-1&quot;>Slug</font></b></td>
<td><input size=&quot;50&quot; maxlength=&quot;250&quot; type=&quot;text&quot; name=&quot;slug&quot;></td>
</tr>
<tr>
<td valign=&quot;top&quot;><b><font size=&quot;-1&quot;>Content</font></b></td>
<td><textarea name=&quot;content&quot; cols=&quot;40&quot; rows=&quot;10&quot;></textarea></td>
</tr>
<tr>
<td valign=&quot;top&quot;><font size=&quot;-1&quot;>Contact person</font></td>
<td><input size=&quot;50&quot; maxlength=&quot;250&quot; type=&quot;text&quot; name=&quot;contact&quot;></td>
</tr>
<tr>
<td colspan=2><input type=&quot;Submit&quot; name=&quot;submit&quot; value=&quot;Add&quot;></td>
</tr>
</form>
</table>
<?
}
else
{
// includes
include(&quot;../conf.php&quot;);
include(&quot;../functions.php&quot;);

// set up error list array
$errorList = array();
$count = 0;

// validate text input fields
if (!$slug) { $errorList[$count] = &quot;Invalid entry: Slug&quot;; $count++; }

if (!$content) { $errorList[$count] = &quot;Invalid entry: Content&quot;; $count++; }

// set default value for contact person
if (!$contact) { $contact = $def_contact; }

// check for errors
// if none found...
if (sizeof($errorList) == 0)
{
// open database connection
$connection = mysql_connect($host, $user, $pass) or die (&quot;Unable to connect!&quot;);

// select database
mysql_select_db($db) or die (&quot;Unable to select database!&quot;);

// generate and execute query
$query = &quot;INSERT INTO news(slug, content, contact, timestamp) VALUES('$_POST[slug]', '$_POST[content]', '$_POST[contact]', NOW())&quot;;
$result = mysql_query($query) or die (&quot;Error in query: $query. &quot; . mysql_error());

// print result
echo &quot;<font size=-1>Update successful. <a href=list.php>Go back to the main menu</a>.</font>&quot;;

// close database connection
mysql_close($connection);
}
else
{
// errors found
// print as list
echo &quot;<font size=-1>The following errors were encountered: <br>&quot;;
echo &quot;<ul>&quot;;
for ($x=0; $x<sizeof($errorList); $x++)
{
echo &quot;<li>$errorList[$x]&quot;;
}
echo &quot;</ul></font>&quot;;
}
}
?>

but still won’t insert data into table !! Without getting any error message. Is this a PHP Version 4.2.0 problem?? Do I need to install another version to get best result??
 
you'll need to change these

if (!$_POST[submit])
{
?>
<table cellspacing=&quot;5&quot; cellpadding=&quot;5&quot;>
<form action=&quot;<? echo $_POST[PHP_SELF]; ?>&quot; method=&quot;POST&quot;> <hr>
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top