how do i insert data to mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
harsha
Forum Contributor
Posts: 103
Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India

how do i insert data to mysql

Post by harsha »

<?php

$db=mysql_connect("127.0.0.1","hi","getche");
mysql_select_db("jawab",$db);
if ((isset($jname)) AND (isset($jemail))) {
$sql="INSERT INTO jawab VALUES('$jid','$jname','$jemail','$jdate','$jcomment')";
$result=mysql_query($sql,$db);

$jdate=date(M,d,Y);
echo "data inserted";
}
?>

<form method=POST action="/jawab/index.php">
<INPUT TYPE="text" NAME="jname">
<br>
<input type=text name=jemail ><br>
<textarea cols=30 rows=8 name=jcomment ></textarea>
<input type=submit name=submit value=add>
</form>


i am using this but it is not working plz help me :?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

what errors are you getting? or what is happening?
Geschi
Forum Newbie
Posts: 21
Joined: Wed Jul 10, 2002 3:21 am
Location: Germany

Post by Geschi »

Ok, there are some points to discuss:
1. The table "jawab" has the same name as the database? Maybe you mispelled something.
2. Better put
$jdate=date(M,d,Y);
before your SQL query
AND this is the right way to use date():

Code: Select all

$jdate=date("M d Y");
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you have a problem with some code please:
  • Tell us what isn't working;
  • Give any error messages you are receiving;
  • Explain what your code is trying to do.
This makes it easier for us to help you and means we don't have to go through each part of your code and can concentrate on the parts that are throwing up errors.[/list]

To summarise, posting some code, asking for help and giving no additional information is rude.

Mac
Post Reply