Jump to content

Help doing the simplest thing!!!!!!!!!!!!!


Bigg

Recommended Posts

[code]<?php

if ($_POST[submit] == "Submit")
{

//Collect form data and assign to scalar variables


$Color = $_POST[Color];


//Establish a connection to the Database

$conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=Dir to my .mdb file','','');

//SQL Statement

$sql = "INSERT INTO Table1 " .
"VALUES ('$Color'')";

//Execute SQL Statement and store results as a recordset

$rs = odbc_exec($conn,$sql);

odbc_close($conn);

}

?>[/code]
[quote author=thorpe link=topic=122315.msg504556#msg504556 date=1168786964]
Try some debugging...

[code=php:0]
if ($rs = odbc_exec($conn,$sql)) {
  echo "insert success";
} else {
  echo odbc_error() ."<br />". $sql;
}
[/code]
[/quote]
Doesn't work.  All I want to is put a value into Table1 in the Color field.  Anyone know how to do this?
[quote author=thorpe link=topic=122315.msg504563#msg504563 date=1168787965]
Is my code producing any error? What is it?
[/quote]No, it just doesn't work! 
[code=php:0] <?php

if ($_POST[submit] == "Submit")
{

//Collect form data and assign to scalar variables


$Color = $_POST[Color];


//Establish a connection to the Database

$conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\to my dir\mydb.mdb','','');

//SQL Statement

$sql = mysql_query("INSERT INTO Table1 (Color1, Color2)
VALUES ('Color1', 'Color2')");


//Execute SQL Statement and store results as a recordset

$rs = odbc_exec($conn,$sql);

odbc_close($conn);

}
[/code]

?>
[quote author=Bigg link=topic=122315.msg504568#msg504568 date=1168789493]
[quote author=GingerRobot link=topic=122315.msg504567#msg504567 date=1168789468]
Well thats not what thorpe suggested. What is the output if you add in the debugging that he proposed?
[/quote]Nothing!
[/quote]By the way now I have to columns Color1 and Color2.
What is this?

[code=php:0]
$sql = mysql_query("INSERT INTO Table1 (Color1, Color2) VALUES ('Color1', 'Color2')");
[/code]

Your not even using mysql.

[code=php:0]
$sql = "INSERT INTO Table1 (Color1, Color2) VALUES ('Color1', 'Color2')";
[/code]

And please, use my code for debugging. If your not getting any errors place this at the top of your script.

[code]
<?php error_reporting(E_ALL) ; ini_set("display_errors","1"); ?>
[/code]
[quote author=thorpe link=topic=122315.msg504605#msg504605 date=1168793700]
What is this?

[code=php:0]
$sql = mysql_query("INSERT INTO Table1 (Color1, Color2) VALUES ('Color1', 'Color2')");
[/code]

Your not even using mysql.

[code=php:0]
$sql = "INSERT INTO Table1 (Color1, Color2) VALUES ('Color1', 'Color2')";
[/code]

And please, use my code for debugging. If your not getting any errors place this at the top of your script.

[code]
<?php error_reporting(E_ALL) ; ini_set("display_errors","1"); ?>
[/code]
[/quote]Still doesn't work, any way I put your code in for debug and got [code]Notice: Use of undefined constant Color1 - assumed 'Color1' in C:\Program Files\Abyss Web Server\htdocs\p\php imput box\insert.php on line 9

Notice: Undefined index: Color1 in C:\Program Files\Abyss Web Server\htdocs\p\php imput box\insert.php on line 9[/code]
My current code is

[code]
<?php error_reporting(E_ALL) ; ini_set("display_errors","1"); ?>
[/code]
[/quote]Still doesn't work, any way I put your code in for debug and got [code]Notice: Use of undefined constant Color1 - assumed 'Color1' in C:\Program Files\Abyss Web Server\htdocs\p\php imput box\insert.php on line 9

Notice: Undefined index: Color1 in C:\Program Files\Abyss Web Server\htdocs\p\php imput box\insert.php on line 9[/code]

My full code is now [code]
<?php error_reporting(E_ALL) ; ini_set("display_errors","1"); ?>
<?php

{

//Collect form data and assign to scalar variables


$Color1, Color2 = $_POST;


//Establish a connection to the Database

$conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Program Files\Abyss Web Server\htdocs\p\php imput box\mydb.mdb','','');

//SQL Statement


$sql = "INSERT INTO Table1 (Color1, Color2) VALUES ('Color1', 'Color2')";

//Execute SQL Statement and store results as a recordset

$rs = odbc_exec($conn,$sql);

odbc_close($conn);

}

?>
<html>
[/code][/quote]
[quote author=Bigg link=topic=122315.msg504781#msg504781 date=1168810655]
My error is now [code]
Parse error: parse error, unexpected '}' in C:\Program Files\Abyss Web Server\htdocs\p\php imput box\insert.php on line 26
[/code]
[/quote]

My form code is [code]<form action="insert.php" method="post" name="Color" id="Color">
  <label for="textarea">Color1</label>
  <input name="textarea" type="text" id="Color1">
    <input name="textarea" type="text" id="Color2">
  <label for="Submit"></label>
  <input type="submit" name="Submit" value="Submit" id="Submit">
</form>
[/code]
[code]
<?php
error_reporting(E_ALL) ;
ini_set("display_errors","1");
if (isset($_POST['Color1']) && isset($_POST['Color2']) {
  $Color1 = $_POST['Color1']
  $Color2 = $_POST['Color2'];
  $conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Program Files\Abyss Web Server\htdocs\p\php imput box\mydb.mdb','','');
  $sql = "INSERT INTO Table1 (Color1, Color2) VALUES ('$Color1', '$Color2')";
  if (odbc_exec($conn,$sql)) {
    echo "insert success";
  } else {
    echo "insert failed<br />";
    echo odbc_error()."<br />";
    echo $sql;
  }
odbc_close($conn);
}
?>
[/code]
[quote author=thorpe link=topic=122315.msg504795#msg504795 date=1168811965]
[code]
<?php
error_reporting(E_ALL) ;
ini_set("display_errors","1");
if (isset($_POST['Color1']) && isset($_POST['Color2']) {
  $Color1 = $_POST['Color1']
  $Color2 = $_POST['Color2'];
  $conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Program Files\Abyss Web Server\htdocs\p\php imput box\mydb.mdb','','');
  $sql = "INSERT INTO Table1 (Color1, Color2) VALUES ('$Color1', '$Color2')";
  if (odbc_exec($conn,$sql)) {
    echo "insert success";
  } else {
    echo "insert failed<br />";
    echo odbc_error()."<br />";
    echo $sql;
  }
odbc_close($conn);
}
?>
[/code]
[/quote]

Getting error [code]
Parse error: parse error, unexpected '{' in C:\Program Files\Abyss Web Server\htdocs\p\php imput box\insert.php on line 4
[/code]when I took out the { it gave me another error.
Try this:
[code]<?php
error_reporting(E_ALL);
ini_set("display_errors","1");
if (isset($_POST['Color1']) && isset($_POST['Color2'])) {
  $Color1 = $_POST['Color1'];
  $Color2 = $_POST['Color2'];
  $conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Program Files\Abyss Web Server\htdocs\p\php imput box\mydb.mdb','','');
  $sql = "INSERT INTO Table1 (Color1, Color2) VALUES ('$Color1', '$Color2')";
  if (odbc_exec($conn,$sql)) {
    echo "insert success";
  } else {
    echo "insert failed<br />";
    echo odbc_error()."<br />";
    echo $sql;
  }
odbc_close($conn);
}
?>[/code]

There were a few typos in thorpe's coding. ;)
[quote author=KingPhilip link=topic=122315.msg504800#msg504800 date=1168812878]
Try this:
[code]<?php
error_reporting(E_ALL);
ini_set("display_errors","1");
if (isset($_POST['Color1']) && isset($_POST['Color2'])) {
  $Color1 = $_POST['Color1'];
  $Color2 = $_POST['Color2'];
  $conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Program Files\Abyss Web Server\htdocs\p\php imput box\mydb.mdb','','');
  $sql = "INSERT INTO Table1 (Color1, Color2) VALUES ('$Color1', '$Color2')";
  if (odbc_exec($conn,$sql)) {
    echo "insert success";
  } else {
    echo "insert failed<br />";
    echo odbc_error()."<br />";
    echo $sql;
  }
odbc_close($conn);
}
?>[/code]

There were a few typos in thorpe's coding. ;)
[/quote]
Nope, no errors but it's not inserting it into the database.
[code]<?php
error_reporting(E_ALL);
ini_set("display_errors","1");
if (isset($_POST['Color1']) && isset($_POST['Color2'])) {
  $Color1 = $_POST['Color1'];
  $Color2 = $_POST['Color2'];
  $conn = odbc_connect('Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Program Files\Abyss Web Server\htdocs\p\php imput box\mydb.mdb','','');
  $sql = "INSERT INTO Table1 (Color1, Color2) VALUES ('$Color1', '$Color2')";
echo $sql;
  if (odbc_exec($conn,$sql)) {
    echo "insert success";
  } else {
    echo "insert failed<br />";
    echo odbc_error()."<br />";
    echo $sql;
  }
odbc_close($conn);
}
?>[/code]

What does it say now?

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.