Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Help with PHP INSERT INTO ... VALUES
Old 08-16-2004, 09:31 AM Help with PHP INSERT INTO ... VALUES
Novice Talker

Posts: 7
Trades: 0
Hello there,
I have a database table called "staff" and I am trying to update the table from a form. The problem is that it does not insert the new data into the table. I have allowed all options for the user in the table properties.
Below is what I have in the file:

<html>

<?php
if ($submit)
{

// Variable Declarations.
$db = mysql_connect ("localhost", "root", "") ;
mysql_select_db ("mysql", $db) ;
$sqlquery = "INSERT INTO staff (emp_id, first_name, last_name, email, dept) VALUES ('$emp_id', '$first', '$last', '$email', '$dept')" ;

$results = mysql_query ($sqlquery) ;

echo "Information has been entered.\n" ;
}

else
{
?>
<form method="post" action="input_form.php">
ID Number:: <input type="text" name="emp_id"> <br><br>
First Name: <input type="text" name="first"> <br><br>
Last Name: <input type="text" name="last"> <br><br>
E-Mail: <input type="text" name="email"> <br><br>
Department: <input type="text" name="dept"> <br><br>
<input type="submit" name="submit" value=" Submit"></form>
<?
}
?>

</html>

Can you tell me what is wrong with the piece of code.
Thanx very much.
Artful Dodger is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-16-2004, 09:37 AM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
What is the exact error your getting?

Try this echoing the sql query:
echo $sqlquery;
May give you some clues as to how it looks after the values have been plugged into it.

I also noticed that you have $emp_id wrapped in quotes, I'm assuming it's an integer field so you shouldn't have the quotes on there.

If you give us the error your getting we can help you better.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 08-16-2004, 09:44 AM
Novice Talker

Posts: 7
Trades: 0
Sorry guys, ignore the Q. in this post
I have just fixed the problem by removing the line "(emp_id, first_name, last_name, email, dept) " in the INSERT statement. I still would like to know why it was not working with that line.
Thank you.
Artful Dodger is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help with PHP INSERT INTO ... VALUES
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11623 seconds with 12 queries