Jump to content


Photo

code to insert values in mysql table?


  • Please log in to reply
2 replies to this topic

#1 shams

shams
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 16 April 2006 - 01:32 AM

hi,
This is the code to insert the valuse to mysql but doesn't work:
<html>
<body>
<?php
$db = mysql_connect("localhost", "root", "******");
mysql_select_db("mydb",$db);
$query="INSERT INTO student4 VALUES (NULL, "zubair", "second", 500)";
$rt=mysql_query($query);
echo mysql_error();

if($rt){echo " Command is successful ";}
else {echo " Command is not successful ";}
?>
</html>
</body>
and this is the student4 table:
| id | name | class | mark |
+----+---------+-------+------+
| 1 | shakeel | first | 500 |
+----+---------+-------+------+
1 row in set (0.05 sec)
any help please?

#2 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 16 April 2006 - 05:14 AM

try this
$query="INSERT INTO student4(id,name,class,mark)VALUES ('NULL', 'zubair', 'second', '500')";
$rt=mysql_query($query);

The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#3 shams

shams
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 16 April 2006 - 02:52 PM

hi shortj75,
thanks for your hint, your posted code works, then i tried this one, this was also successfull:
$query="INSERT INTO student4 VALUES ('NULL', 'nabeel', 'fifth', '900'),('NULL', 'khalid', 'sixth', '1000')";




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users