cant save the data into DB...!!!!!!!!!!

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
tyngtyng
Forum Newbie
Posts: 1
Joined: Mon Oct 02, 2006 8:58 am

cant save the data into DB...!!!!!!!!!!

Post by tyngtyng »

twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi...
i'm new to the php and now i'm getting a problem to insert my data into my DB..
Now,i'm having trouble catching what i'm doing wrong.... Here's my code ....

Code: Select all

<html>
<head>
<title>Add New Pili Bomba</title>
</head>

<h1>Add New Pili Bomba Information</h1>
<hr/>

<?php

if(isset($_POST['submit']))
{

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect:'.mysql_error());
}

mysql_select_db("pili_bomba",$con)or die ('unable to select the database');


include 'config.php';

$pili_id=$_POST['pili_id'];
$branch=$_POST['branch'];
$zone=$_POST['zone'];
$location=$_POST['location'];
$type=$_POST['type'];
$subtype=$_POST['subtype'];
$alamat=$_POST['alamat'];
$latest_updated=$_POST['latest_updated'];

$query = "INSERT INTO pili(pili_id, branch, zone, location, type, subtype, alamat, latest_updated) VALUES 
('$pili_id', '$branch', '$zone', '$location', '$type', '$subtype', '$alamat', '$latest_updated')";

mysql_query($query) or die('Error, insert query failed');

echo "<table cellpadding=8 border=1>"; 
echo "<tr>";
echo "<td>$pili_id</td>";
echo "<td>$branch</td>";
echo "<td>$zon</td>";
echo "<td>$location</td>";
echo "<td>$type</td>";
echo "<td>$subtype</td>";
echo "<td>$alamat</td>";
echo "<td>$latest_updated</td>";
echo "</tr>";
echo "</table>";



echo "New pili Bomba added";
}
else
{
?>

<form action="" method=post> 

<TABLE cellSpacing=2 cellPadding=6 align=center border=1>
<TR>
<TD colSpan=4>
<H3 align=center>Add Pili Bomba&nbsp</H3></TD></TR>
<TR>
<TD> Branch</TD>
<TD><SELECT name=branch>
<OPTION value=selected>select branch
<OPTION value=branch>Tun Mustapha
<OPTION value=branch>Kg Jawa
<OPTION value=branch>Layang-layangan
</OPTION>
</SELECT></TD>
<TD> Location</TD>
<TD><INPUT name= location></TD>
<TR>
<TD> Pili ID</TD>
<TD><INPUT name=pili_id></TD>
<TD> Zone</TD>
<TD><INPUT name=zone></TD>
<TR>
<TD> Type</TD>
<TD><SELECT name=type>
<OPTION value=0 selected>select type
<OPTION value=type>PH
<OPTION value=type>GH
</OPTION>
</SELECT></TD>
<TD> Subtype</TD>
<TD><SELECT name=subtype>
<OPTION value=0 selected>select subtype
<OPTION value=subtype>A
<OPTION value=subtype>V
</OPTION>
</SELECT></TD>
<TR>
<TD>Alamat</TD>
<TD><INPUT name=alamat></TD>
<TR>
<TD> Latest updated</TD>
<TD><INPUT name=latest_updated</TD> 
<TD><INPUT type='submit' value='Save'></TD>
<TD><INPUT type='reset' value='Reset'></TD>

<TR>
</TABLE>
</form>
<?php
}
?>

</body>
</html>
what would be the solution for this?
Can anyone give me a clue..?
thanks...!!!!

thankx


twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

There is no field "submit" in a form, so there is no connection to database and no insert.
Add "submit" field

Code: Select all

<input type="hidden" name="submit" value="" />
to the form or instead of

Code: Select all

if(isset($_POST['submit']))
you can use

Code: Select all

if(count($_POST) > 0)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

tyngtyng: Be sure to use [ php ] tags the next time you post, thanks!

Personally, I'd use:

Code: Select all

if (!empty($_POST))
Don't forget to clean up after magic quotes and escape your data with mysql_real_escape_string(). Right now, your code is vulnerable to SQL injection attempts.
Post Reply