Hello i am designing a project which is intended to store the values entered in a browser into database. Finding some difficulties in displaying the database contents on browser.

Below i am posting my entire code. The data i enter in browser are getting inserted into the database. I checked it manually. But while displaying the contents on browser there are some errors that will be displayed. i am posting the error shown as well. please help me find out what is the problem

My code has two parts 1 which is php code deals with the database and 2 XML which deals with the front end

Php code:

$mysql=mysql_connect("localhost","root","")or die("connect error");
$result=mysql_query("insert into form values('$name','$addressline1','$addressline2','$email')");
print "name=$name addressline1=$addressline1 addressline2=$addressline2 email=$email result=$result";

<title>query DB</title>
<? if($result==1) print "record inserted successfully"; ?>
<h4>current DB contents</h4>
<? $result=mysql_query("select * from form"); ?>
<table border="1" align="center" width="500">
<? while($array=mysql_fetch_row($result))
	print "<tr>";
	print "<td>" . $array[0] . "</td>";
	print "<td>" . $array[1] . "</td>";
	print "<td>" . $array[2] . "</td>";
	print "<td>" . $array[3] . "</td>";
	print "</tr>";

XML code:

<?xml version="1.0" encoding="utf-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<form action="http://localhost/13a.php" method="post">
<table width="500">
<td><input type="text" name="name"></td>
<td><input type="text" name="addressline1"></td>
<td><input type="text" name="addressline2"></td>
<td><input type="text" name="email"></td>

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

Error shown

name=pruthvi addressline1=kadur addressline2=bangalore email=ppp result=

current DB contents

"; print ""; print ""; print ""; print ""; print ""; } mysql_free_result($result); mysql_close($mysql); ?>

name addressline1 addressline2 email
" . $array[0] . " " . $array[1] . " " . $array[2] . " " . $array[3] . "

Please help how to debug this error and make the contents display in my browser.


ok, first thing is your using $result twice, basically you have colliding variables. second thing is that your insert statement is incorrect. Whenever you use an insert statement you need to define the table fields, then use the "VALUES" to insert into the table fields.


$con = //Connection;
mysql_select_db("db", $con);
$sql = "INSERT into table(name,addressline1,addressline2,email) VALUES('$name','$addressline1','$addressline2','$email')";
if(mysql_query($sql,$con)) {
    die('Error: ' . mysql_error());
} else {
    print "name=$name addressline1=$addressline1 addressline2=$addressline2 email=$email ";

On the database display, you cannot use 0 or 1 or 2 or 3. define them from your table fields. Also, you have to use fetch_array not fetch_row. A really great website is www.w3schools.com

God i was so silly... :D Thanks a lot for correcting me sir. That corrected my code :) Many Thanks, Tak care:)