sucessfull message after insert into table

Hii Guys,

after many many tries i had to give up.

i want to display a successful message after i insert into the table where the yellow td is something like
“data sucessfully submited”
i want to display it on that specific location of the main form and not on the php file .
so save this to a html file and see what i mean:

<html>
<head>
<basefont face="Arial">
</head>
<body>
<form name='people' method='POST' action="InsertingIntoDb.php">
<table width = '35%' border = '1' cellspacing = '1' cellpadding = '1'>
<tr>
<td>Firstname</td>
<td><input type='text' name='firstname' value='Petter'></td>
</tr>
<tr>
<td>Lastname</td>
<td><input type='text' name='lastname' value='Pankerson'></td>
</tr>
<tr>
<td>Address</td>
<td><input type='text' name='address' value='185 thisISnotaRalAddress street'></td>
</tr>
<tr>
<td>city</td>
<td><input type='text' name='city' value='bronx'></td>
</tr>
<tr>
<td>state</td>
<td><input type='text' name='state' value='yy'</td>
</tr>
<tr>
<td>zipcode</td>
<td><input type='text' name='zipcode' value='55555'></td>
</tr>
<tr>
<td>Phone</td>
<td><input type='text' name='phone' value='1111111111111'></td>
</tr>
<tr>
<td>submit all data</td>
<td><input type='submit' name='submit' value='Insert to DB'></td>
</tr>
<tr>
<td colspan='2' bgcolor='yellow' align='center'>This is where the successful message.</td>
</tr>

</table>
</form>
</body>
</html>

php code:
[php]

<?php if (isset($_POST['submit'])) { $fname= $_POST['firstname']; $lname= $_POST['lastname']; $phone= $_POST['phone']; $address= $_POST['address']; $state= $_POST['state']; $city= $_POST['city']; $zcode= $_POST['zipcode']; $host = "localhost"; $user = "root"; $pass = ""; $db = "wilson_db"; $conn = mysql_connect($host,$user,$pass) or die ("unable to connect"); mysql_select_db($db) or die("unable to select db"); $query = "INSERT INTO people (fname,lname,phone,address,state,city,zipcode) VALUES ('$fname','$lname','$phone','$address','$state','$city','$zcode')"; mysql_query($query) or die ("error in $query query"); mysql_close($conn); echo "Data sucessfully inserted into the database."; } ?>

[/php]

bt the way my code works.
i didnt manage to display the result message on my html form instead of my php

Thanks ,
wilson B

hello wilson382,
i have merge your both file code in single file. so just save this file with .php like demo.php extension and run the code. it will works for you fine.

[php]

<?php if (isset($_POST['submit'])) { $fname= $_POST['firstname']; $lname= $_POST['lastname']; $phone= $_POST['phone']; $address= $_POST['address']; $state= $_POST['state']; $city= $_POST['city']; $zcode= $_POST['zipcode']; $host = "localhost"; $user = "root"; $pass = ""; $db = "wilson_db"; $msg = ''; $conn = mysql_connect($host,$user,$pass) or die ("unable to connect"); mysql_select_db($db) or die("unable to select db"); $query = "INSERT INTO people (fname,lname,phone,address,state,city,zipcode) VALUES ('$fname','$lname','$phone','$address','$state','$city','$zcode')"; $result = mysql_query($query) if(! $result ) { die("error in $query query" . mysql_error()); } else { $msg = "Data sucessfully inserted into the database."; } mysql_close($conn); } ?> <? if(!empty($msg)) { ?> <? } ?>
Firstname
Lastname
Address
city
state <input type='text' name='state' value='yy'
zipcode
Phone
submit all data
This is where the successful message.
[/php]

i hope this will helpful for you.
SR

yeap man works btw u forgot to put the endsing semi colon for one of the line and that got me an error but i fixed for you xd

i have a question in order to make it work like i want the php and html code must be in the same file ?

hello wilson382,
it’s not necessary to put php and html code in same file.
it’s demand on your requirement.

SR

can i have codes on different files even thought i want to display error on the html codes for example a required textbox was left empty?

if you want to display error on same HTML page than it’s better to use php and HTML code in same file if possible other wise you need to pass error message on HTML page vai get method see below.
login.php?error=‘username or password is incorrect.’
Note : here you must save html file as php means now your login.html must be login.php

SR

great thankz

Sponsor our Newsletter | Privacy Policy | Terms of Service