mysql - Issue in retrieve data from sql database in php -
mysql - Issue in retrieve data from sql database in php -
i have created register form using php. have index.php,submit.php,functions.php , script.
now works fine, , need retrieve info database , display in front end end.
i new php, , learning. please help me this.
this data.php:
<?php include ('condb.php'); $query = mysql_query("select * test id='".$_get['id']."'"); $row = mysql_fetch_array($query); ?> <body> <h3>employee detail</h3> <p>emp name:</p> <?php echo $row['fname'];?> <p>lastname:</p> <?php echo $row['lname'];?> </body> <?php ?>
and action.php:
<?php include('condb.php'); extract($_post); $que=mysql_query("insert test (id, fname, lname) values ('$id', '$fname', '$lname')") or die("error msg!"); if($que) { header('location: data.php?id='.$id.''); } ?>
index.html:
<body bgcolor="#2e2e2e"> <table align="center" cellpadding="5" style="background:#a4a4a4; border-radius:4px; margin-top:40px; padding:15px;"> <h1 style="text-align:center; color:white; margin-top:50px">employee registration form</h1> <form method="post" action="action.php"> <tr><td>first name:</td><td> <input type="text" id="fname" name="fname" required /></td></tr> <tr><td>last name:</td><td> <input type="text" id="lname" name="lname"/></td></tr> <tr><td></td><td><input type="submit" value="register me!"/></td></tr> </form> </table> </body>
and condb.php:
<?php $con=mysql_connect("localhost","root","")or die("error!"); mysql_select_db("test") or die(mysql_error()); ?>
here have shown code 3 field , can other fields.you can create newfile , paste code their.
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('could not connect: ' . mysql_error()); } $sql = 'select fname, lname, email crop'; mysql_select_db('crop'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('could not data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, mysql_assoc)) { echo "first name :{$row['fname']} <br> ". "last name : {$row['lname']} <br> ". "email address : {$row['email']} <br> ". "--------------------------------<br>"; } echo "fetched info successfully\n"; mysql_close($conn); ?>
php mysql
Comments
Post a Comment