Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.

Thread Tools Display Modes
Share |
Old 09-28-2008, 04:39 AM
flyingman's Avatar
flyingman flyingman is offline
Junior Member
Join Date: 05-31-08
Posts: 25
iTrader: 0 / 0%
[cannot insert into mysql]

hi am again,

i have problem with my connection is cannot insert data to table mysql..

here's the code :

first html code:
HTML Code:
<link href="css.css" rel="stylesheet" type="text/css" /> <title>::Table Budget Insert::</title> <body> <div class="tab_ins_font" id="tab_ins">TABLE BUDGET INSERT</div> <div id="table_layout_budget"> <form action="showtable.php" method="post" name="tblinst"> <table width="100%" style="table-layout:auto"> <tr> <td width="74" rowspan="2" valign="top" class="textfield"><div align="center"><strong>Item</strong></div></td> <td width="122" rowspan="2" valign="top" class="textfield"><strong>Price List </strong></td> <td colspan="12" class="textfield"><div align="center"><strong>Month</strong></div></td> <td width="349" rowspan="2" valign="top" class="textfield"><div align="center"><strong>Reason</strong></div></td> </tr> <tr> <td class="textfield" width="32"><strong>jan</strong></td> <td class="textfield" width="32"><strong>feb</strong></td> <td class="textfield" width="32"><strong>mar</strong></td> <td class="textfield" width="32"><strong>apr</strong></td> <td class="textfield" width="32"><strong>mei</strong></td> <td class="textfield" width="32"><strong>jun</strong></td> <td class="textfield" width="32"><strong>jul</strong></td> <td class="textfield" width="32"><strong>aug</strong></td> <td class="textfield" width="32"><strong>sep</strong></td> <td class="textfield" width="32"><strong>oct</strong></td> <td class="textfield" width="32"><strong>nov</strong></td> <td class="textfield" width="32"><strong>dec</strong></td> </tr> <tr> <td><input name="item" type="text" class="textfield" id="item" size="12"/></td> <td><input name="price" type="text" class="textfield" id="price" size="20"/></td> <td><input name="jan" class="textfield" type="text" id="jan" size="5" /></td> <td><input name="feb" class="textfield" type="text" id="feb" size="5" /></td> <td><input name="mar" class="textfield" type="text" id="mar" size="5" /></td> <td><input name="apr" class="textfield" type="text" id="apr" size="5" /></td> <td><input name="mei" class="textfield" type="text" id="mei" size="5" /></td> <td><input name="jun" class="textfield" type="text" id="jun" size="5" /></td> <td><input name="jul" class="textfield" type="text" id="jul" size="5" /></td> <td><input name="aug" class="textfield" type="text" id="aug" size="5" /></td> <td><input name="sep" class="textfield" type="text" id="sep" size="5" /></td> <td><input name="oct" class="textfield" type="text" id="oct" size="5" /></td> <td><input name="nov" class="textfield" type="text" id="nov" size="5" /></td> <td><input name="dec" class="textfield" type="text" id="dec" size="5" /></td> <td><input name="reason" class="textfield" type="text" id="reason" size="30" /></td> </tr> </table> <br /> <input type="submit" class="button" value="Save" size="50"/> </form> </div> </body>

second php code :

PHP Code:
$host="localhost"// Host name 
$username="root"// mysql username 
$password=""// mysql password 
$db_name="tabinput_db"// Database name 
$tbl_name="insert"// Table name 

// Connect to server and select database.
mysql_connect("$host""$username""$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$item     =$_POST['item'];
$price    =$_POST['price'];
$jan    =$_POST['jan'];
$feb     =$_POST['feb'];
$mar    =$_POST['mar'];
$apr    =$_POST['apr'];
$mei     =$_POST['mei'];
$jun    =$_POST['jun'];
$jul    =$_POST['jul'];
$aug     =$_POST['aug'];
$sep    =$_POST['sep'];
$oct    =$_POST['oct'];
$nov     =$_POST['nov'];
$dec    =$_POST['dec'];
$reason    =$_POST['reason'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name('item_id', 'price_list', 'jan_id', 'feb_id', 'mar_id', 'apr_id', 'mei_id', 'jun_id', 'jul_id', 'aug_id', 'sep_id', 'oct_id', 'nov_id', 'dec_id', 'reason_id')
$item', '$price', '$jan', '$feb', '$mar', '$apr', '$mei', '$jun', '$jul', '$aug', '$sep', '$oct', '$nov', '$dec','$reason')";

//VALUES('$item', '$price', '$jan', '$feb', '$mar', '$apr', '$mei', '$jun', '$jul', '$aug', '$sep', '$oct', '$nov', '$reason')

// if successfully insert data into database, displays message "Successful".

else {
//echo "<a href='insert_budget.php'>try again</a>"

// close connection
Reply With Quote



Old 09-29-2008, 02:56 PM
marc_gfx marc_gfx is offline
Contributing Member
Join Date: 07-01-06
Posts: 126
iTrader: 0 / 0%

$result = mysql_query($sql) or die(mysql_error());

to see whats going wrong.

and if you simply use the $_POST[] content you are providing an excellent oportunity for sql injection (some bad guys can get access to your machine)
Reply With Quote
Old 09-29-2008, 10:16 PM
flyingman's Avatar
flyingman flyingman is offline
Junior Member
Join Date: 05-31-08
Posts: 25
iTrader: 0 / 0%
tks marck, its success....,

but i have another problem again...

how insert into mysql if i want get 1 row in table design....here like this:

no | item | jan | feb | mar
1 | A | 50 | 2 | 3 ===> i want to get 1 row with all column and insert into db
2 | B | 25 | 3 | 2
3 | C | 30 | 1 | 1

thk's before

sorry my English language not well !
Reply With Quote
Old 09-30-2008, 05:00 AM
marc_gfx marc_gfx is offline
Contributing Member
Join Date: 07-01-06
Posts: 126
iTrader: 0 / 0%
you want to load data from a table? you will need to parse the html i guess. not quite sure what you are asking though.
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
insert multiple select into mysql janim Coding Forum 1 08-05-2007 04:08 PM
insert a .wav into the page ball420 Web Design Lobby 3 03-10-2007 06:38 PM
MySQL backup ref: INSERT INTO Woody Coding Forum 4 08-10-2006 09:03 AM
Cd Insert Brian Graphic Design Forum 6 06-30-2006 07:30 PM

V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory

All times are GMT -7. The time now is 06:03 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC