mysql - HTML and PHP Database Connectivity -


i using code. insert name , rollno in table named 'tablename' in database 'dbname'.

db.php

<html>     <body>         <form name="db" action="db.php" method=post>             enter name <input type=text name="nam"/><br><br>             enter rollno. <input type=text name="rno"/><br><br>             <input type=submit value="click me"/>         </form>  <?php $nam = $_post['nam']; $rno = $_post['rno']; mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db('dbname') or die(mysql_error()); $sql="insert tablename values('$nam','$rno')";  mysql_query($sql); ?> </body> </html> 

it show error, that
notice: undefined index: nam in c:\wamp\www\db connectivity\db.php on line 10
notice: undefined index: rno in c:\wamp\www\db connectivity\db.php on line 11

plz give solution, how use html , php in same page without error.

you're not checking if form submitted or not give name submit element & have check using isset,

    <input type=submit name="submit" value="click me"/>     </form>  <?php if(isset($_post['submit'])){      $nam = isset($_post['nam']) ? $_post['nam'] : '';      $rno = isset($_post['rno']) ? $_post['rno'] : '';      //and rest of php operation need perform after submit. ?> 

warning: please, don't use mysql_* functions in new code. no longer maintained and officially deprecated. see red box? learn prepared statements instead, , use pdo or mysqli - this article decide which. if choose pdo, here tutorial.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -