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
https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/
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')");

 

}

?>

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());

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" }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.