Bigg Posted January 14, 2007 Share Posted January 14, 2007 Hey, I'm trying to do the simplest thing I wan to make one form text box to put it's data in my mydb.mdb. It has one Table named Table1 and a Color column. Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/ Share on other sites More sharing options...
kenrbnsn Posted January 14, 2007 Share Posted January 14, 2007 Have you written any code yet? If so, post what you have.Ken Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160350 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [code]<?phpif ($_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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160352 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 Please send me back some edited code so I can look it over. Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160355 Share on other sites More sharing options...
Philip Posted January 14, 2007 Share Posted January 14, 2007 "VALUES ('$Color[b]''[/b])"; You have 2 single quotes (') Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160356 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [quote author=KingPhilip link=topic=122315.msg504404#msg504404 date=1168756114]"VALUES ('$Color[b]''[/b])"; You have 2 single quotes (')[/quote]Still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160503 Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 Try some debugging...[code=php:0]if ($rs = odbc_exec($conn,$sql)) { echo "insert success";} else { echo odbc_error() ."<br />". $sql;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160507 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160512 Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 Is my code producing any error? What is it? Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160514 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [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] <?phpif ($_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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160516 Share on other sites More sharing options...
GingerRobot Posted January 14, 2007 Share Posted January 14, 2007 Well thats not what thorpe suggested. What is the output if you add in the debugging that he proposed? Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160518 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160519 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [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. Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160531 Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160556 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [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 9Notice: Undefined index: Color1 in C:\Program Files\Abyss Web Server\htdocs\p\php imput box\insert.php on line 9[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160728 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 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 9Notice: 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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160730 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160731 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [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] Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160734 Share on other sites More sharing options...
trq Posted January 14, 2007 Share Posted January 14, 2007 [code]<?phperror_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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160743 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [quote author=thorpe link=topic=122315.msg504795#msg504795 date=1168811965][code]<?phperror_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. Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160746 Share on other sites More sharing options...
Philip Posted January 14, 2007 Share Posted January 14, 2007 Try this:[code]<?phperror_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 Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160748 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [quote author=KingPhilip link=topic=122315.msg504800#msg504800 date=1168812878]Try this:[code]<?phperror_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. Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160758 Share on other sites More sharing options...
Philip Posted January 14, 2007 Share Posted January 14, 2007 [code]<?phperror_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? Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160775 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 It just doesn't go into the database. No errors. Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160777 Share on other sites More sharing options...
Bigg Posted January 14, 2007 Author Share Posted January 14, 2007 [quote author=Bigg link=topic=122315.msg504829#msg504829 date=1168814746]It just doesn't go into the database. No errors.[/quote]Any Idea's? Quote Link to comment https://forums.phpfreaks.com/topic/34097-help-doing-the-simplest-thing/#findComment-160786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.