Jump to content

error...insert query failed AND undefined index?????


tyngtyng

Recommended Posts

hi...i'm new to the php and now i'm getting an error to insert my data inside the form..and also undefined index in latest_updated......Now,i'm having trouble catching what i'm doing wrong.... Here's my code to the query entry...<?phpinclude '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 = "INSECT INTO pili VALUES (pili_id, branch, zone, location, type, subtype, alamat, latest_updated)('$pili_id', '$branch', '$zone', '$location', '$type', '$subtype', '$alamat', '$latest_updated')";mysql_query($query) or die('Error, insert query failed');echo " '$pili_id' <b> '$branch' </b> ,'$zone', '$location', '$type', '$subtype', '$alamat','$latest_updated'";?>Can anyone give me a clue..?thanks...!!!!

Link to comment
Share on other sites

Try this

<?phpinclude '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'];$con = mysql_connect("localhost","user","pass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("my_db", $con); $query = "INSERT INTO pili VALUE ('$pili_id', '$branch', '$zone', '$location', '$type', '$subtype', '$alamat', '$latest_updated')";mysql_query($query) or die('Error, insert query failed');echo " '$pili_id' <b> '$branch' </b> ,'$zone', '$location', '$type', '$subtype', '$alamat','$latest_updated'";?>

Link to comment
Share on other sites

<?phpinclude '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'];$connection = mysql_connect("localhost","username","password");if (!$connection) { die('Could not connect: ' . mysql_error()); }mysql_select_db("databasename" , $connection) or die ('unable to select the database');$query = "INSERT INTO pili VALUES (pili_id, branch, zone, location, type, subtype, alamat, latest_updated)('$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>";// and similarly add for othersecho "</tr>";echo "</table>";// OR
echo " '$pili_id' <b> '$branch' </b> ,'$zone', '$location', '$type', '$subtype', '$alamat','$latest_updated'";
// this could be useful if u want to display your results in a table, ?>
Well if u still get erros please do tell us, there would be someone to help u all the time.
Link to comment
Share on other sites

i still cant insert and save my data into my DB, even after i made a little modification...how was tat..?here's my codes again.. :) <html><head><title>Add New Pili Bomba</title></head><h1>Add New Pili Bomba Information</h1><hr/><?phpif(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 </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? thankx

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...