Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2013, 03:08 AM   PM User | #1
sigridish
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sigridish is an unknown quantity at this point
cant connect php to database

Hi all! I would like to ask for help. i have a code that i got from youtube. my problem is i cant connect to my database and i dont know why. i dont think that i have a problem in my code. i have 2 php file. reg.php for the connection and demo-form.php for adding the record.

demo-form.php
PHP Code:
<form action="reg.php" method="post" />
<
p>First Name: <input type="text" name="fname" /> </p>
<
p>Middle Name: <input type="text" name="mname" /> </p>
<
p>Last Name: <input type="text" name="lname" /> </p>
<
p>Home address: <input type="text" name="homeadd" /> </p>
<
p>Email address: <input type="text" name="emailadd" /> </p>
<
p>Office/project number: <input type="text" name="ofcnum" /> </p>
<
p>Mobile number: <input type="text" name="mobilenum" /> </p>
<
p>Home number: <input type="text" name="homenum" /> </p>
<
p>Position
<
select name="position">
  <
option value ="">Select</option>
  <
option value ="Project Manager">Project Manager</option>
  <
option value ="Practice Lead">Project Manager</option>
  <
option value ="Team Leader">Team Leader</option>
  <
option value ="Team Member">Team Member</option>
</
select>
<
p>Practice
<
select name="position">
  <
option value ="">Select</option>
  <
option value ="Solutions">Solutions</option>
  <
option value ="Outsourcing">Outsourcing</option>
 </
select>
<
p>Project Name: <input type="text" name="projname" /> </p>
<
p>Project Manager: <input type="text" name="projmgr" /> </p>
<
p>Team Leader: <input type="text" name="teamlead" /> </p>

<
input type="submit" value="Submit" />
<
body bgcolor="cccccc">
</
form

reg.php

PHP Code:
<?php[/b]


[
b]define ('DB_NAME''emp');
define ('DB_USER''root');
define ('DB_PASSWORD''');
define ('DB_HOST''localhost');[/b]


[
b]$link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);[/b]


[
b]if (!$link) {
die(
'Could not connect: ' mysql_error());
}[/
b]


[
b]$db_selected mysql_select_db(DB_NAME$link);[/b]


[
b]if (!$db_selected) {
die(
'Can\'t use ' DB_NAME ': ' mysql_error());
}[/
b]


[
b]$value1 $_POST["fname"];
$value2 $_POST["mname"];
$value3 $_POST["lname"];
$value4 $_POST["homeadd"];
$value5 $_POST["emailadd"];
$value6 $_POST["ofcnum"];
$value7 $_POST["mobilenum"];
$value8 $_POST["homenum"];
$value9 $_POST["position"];
$value10 $_POST["practice"];
$value11 $_POST["projname"];
$value12 $_POST["projmgr"];
$value13 $_POST["teamlead"];[/b]


[
b]$sql "INSERT INTO employee (fname, mname, lname, homeadd, emailadd, ofcnum, mobilenum, homenum, position, projname, projmgr, teamlead) 
  VALUES ('$value1', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12')"
;
 
if (!
mysql_query($sql)) {
die(
'Error: ' mysql_error());
}[/
b]


[
b]mysql_close();[/b]


[
b]?>
sigridish is offline   Reply With Quote
Old 01-31-2013, 07:43 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Have your got any errors?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-31-2013, 07:56 AM   PM User | #3
needsomehelp
Regular Coder

 
Join Date: Oct 2009
Posts: 307
Thanks: 4
Thanked 3 Times in 3 Posts
needsomehelp can only hope to improve
Here's my 2pence worth...

try changing the inset line to this...

Code:
$sql = "INSERT INTO `employee` (`fname`, `mname`, `lname`, `homeadd`, `emailadd`, `ofcnum`, `mobilenum`, `homenum`, `position`, `projname`, `projmgr`, `teamlead`) 
  VALUES ('$value1', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12')";
needsomehelp is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 10:23 AM.


Advertisement
Log in to turn off these ads.