inserting info into a mysql db
Posted: Thu Aug 22, 2002 3:15 am
I am newbie php programmer trying to insert info into a mysql database using the very basic "insert into db" command but nothing happens or noshould I say nothing is inserted. But if use phpmyadmin to insert data it inserts the info fine.
THis is the 'basic' code that I can't get to work----->
<?php
if($submit)
{
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb", $db);
$sql = "insert into personnel (firstname, lastname, nick, email, salary) Values
('$first', '$last', '$nickname', '$email', '$salary')";
$result = mysql_query($sql);
echo "Thank you! Information Entered. \n";
}
else
{
?>
<form method="post" action="input.php">
First name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Nickname: <input type="text" name="nickname"><br>
E-mail: <input type="text" name="email"><br>
Salary: <input type="text" name="salary"><br>
<input type="submit" name="submit" value="Enter Information">
</form>
<?
}
?>
I know this code works 'cos i copied it from a book and it doesn't spit out any errors, is there anything else that I could check that could make this process work.
Thanks Guys
THis is the 'basic' code that I can't get to work----->
<?php
if($submit)
{
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb", $db);
$sql = "insert into personnel (firstname, lastname, nick, email, salary) Values
('$first', '$last', '$nickname', '$email', '$salary')";
$result = mysql_query($sql);
echo "Thank you! Information Entered. \n";
}
else
{
?>
<form method="post" action="input.php">
First name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Nickname: <input type="text" name="nickname"><br>
E-mail: <input type="text" name="email"><br>
Salary: <input type="text" name="salary"><br>
<input type="submit" name="submit" value="Enter Information">
</form>
<?
}
?>
I know this code works 'cos i copied it from a book and it doesn't spit out any errors, is there anything else that I could check that could make this process work.
Thanks Guys