Jump to content

insertion problem


lunate

Recommended Posts

hi all ,

i m new to PHP and also in this forum.

please check outthe following code ,specially "query" and point out my errors and also help me to understand and solve it.

i have a table STD in mysql .(rollno int , name char(25) )

 

i create a simple HTML page.

 

<body><h2 align="center" > Student Entry </h2>

<form action="test_insertion.php" method="post">

<table border="2" align="center">

<tr>

<td>Roll No :</td>

<td><input type="text" name="rn" />

</td></tr>

<tr>

<td>Student Name :</td>

<td>

<input type="text" name="sn" /></td>

</tr>

 

</table>

<br />

<center>

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

</center>

</form>

</body>

 

 

then i write a small PHP script as.

 

<body><?php

$rn=$_POST['rn'];

$sn=$_POST['sn'];

echo $rn ;

echo $sn;

$conn=mysql_connect("localhost","sec","sec");

$db=mysql_select_db("mysql",$conn);

 

$query=mysql_query("insert into std (rollno , name) values ($rn , $nm )" , $conn);

while ($res=mysql_fetch_row($query))

echo $res[0] ." " .$res[1] ."<br>";

 

?></body>

 

please help me .

Link to comment
Share on other sites

no clue what your trying to do here... but you always want to protect variables before they go into a database...

 

<body>
<h2 align="center">Student Entry</h2>
<form action="test_insertion.php" method="post">
<table border="2" align="center">
  <tr>
   <td>Roll No :</td>
   <td><input type="text" name="rn" /></td>
  </tr>
  <tr>
   <td>Student Name :</td>
   <td><input type="text" name="sn" /></td>
  </tr>
</table>
<center>
  <input type="submit" value="Submit" />
</center>
</form>
</body>

 

 

 

<body><?php
$rn=addslashes(strip_tags($_POST['rn']));
$sn=addslashes(strip_tags($_POST['sn']));
echo $rn.$sn;
$conn=mysql_connect("localhost","sec","sec");
$db=mysql_select_db("mysql",$conn);

$query=mysql_query("insert into std (rollno , name) values ($rn , $sn)");
while($res=mysql_fetch_row($query)) echo $res[0] ." " .$res[1];

?></body>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.