Jump to content

[SOLVED] Using POST to update Mysql db


cleary1981

Recommended Posts

Can anyone tell me where i have went wrong here? when I submit the database isn't updated.

 

<form id=addCompany action="addCompany.php" method="POST">
<label for="accno">Account Number</label>
<input type = "text" value = "" name = "accno" id = "accno"></br>
<label for="compName">Company Name</label>
<input type = "text" value = "" name = "compName" id = "compName"></br>
<label for="contact">Contact Name</label>
<input type = "text" value = "" name = "contact" id = "contact"></br>
<label for="add1">Address</label>
<input type = "text" value = "" name = "add1" id = "add1"></br>
<input type = "text" value = "" name = "add2" id = "add2"></br>
<label for="town">Town/City</label>
<input type = "text" value = "" name = "town" id = "town"></br>
<label for="county">County</label>
<input type = "text" value = "" name = "county" id = "county"></br>
<label for="pcode">Post Code</label>
<input type = "text" value = "" name = "pcode" id = "pcode"></br>
<label for="tel">Telephone No.</label>
<input type = "text" value = "" name = "tel" id = "tel"></br>
<input type = "submit" value = "Submit">

 

 

<?php

if($_POST['submit'])
{
   require "config.php"; // database connection details
   
   //convert all the posts to variables:
   $accno = $_POST['accno'];
   $compName = $_POST['compName'];
   $contact = $_POST['contact'];
   $add1 = $_POST['add1'];
   $add2 = $_POST['add2'];
   $town = $_POST['town'];
   $county = $_POST['county'];
   $pcode = $_POST['pcode'];
   $tel = $_POST['tel'];
   
   //Insert the values into the correct database with the right fields
   $result=MYSQL_QUERY("INSERT INTO company VALUES ('$accno', '$compName', '$contact', '$add1', '$add2', '$town', '$county', '$pcode', '$tel')"); 

}
?>

Link to comment
Share on other sites

//Insert the values into the correct database with the right fields
   $result = mysql_query("INSERT INTO company VALUES ('$accno', '$compName', '$contact', '$add1', '$add2', '$town', '$county', '$pcode', '$tel')") or die (mysql_error()); 

 

try this.

Link to comment
Share on other sites

<?php

//try debugging here....

var_dump($_POST);

 

if($_POST['submit'])

{

  require "config.php"; // database connection details

 

  //convert all the posts to variables:

  $accno = $_POST['accno'];

  $compName = $_POST['compName'];

  $contact = $_POST['contact'];

  $add1 = $_POST['add1'];

  $add2 = $_POST['add2'];

  $town = $_POST['town'];

  $county = $_POST['county'];

  $pcode = $_POST['pcode'];

  $tel = $_POST['tel'];

 

  //Insert the values into the correct database with the right fields

  $result=MYSQL_QUERY("INSERT INTO company VALUES ('$accno', '$compName', '$contact', '$add1', '$add2', '$town', '$county', '$pcode', '$tel')");

 

}

?>

Link to comment
Share on other sites

are you working with multiple database connections? cause if anyone would care to read a manual they would notice that mysql_query() actually have 2 parameters, so try adding the db connection resource (optional is only to be used when you in no way are able to write the parameter):

 

$query = "INSERT INTO ..";

$result = mysql_query($query, $dbConnection);

 

if (!$result) die(mysql_error());

Link to comment
Share on other sites

the output to that is

 

array(9) { ["accno"]=> string(4) "uhuh" ["compName"]=> string(4) "uhuh" ["contact"]=> string(4) "uhuh" ["add1"]=> string(4) "uhuh" ["add2"]=> string(4) "uhuh" ["town"]=> string(4) "uhuh" ["county"]=> string(4) "uhuh" ["pcode"]=> string(4) "uhuh" ["tel"]=> string(4) "uhuh" }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.