Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Connecting to a MySQL database and adding new records
Old 06-28-2005, 06:01 PM Connecting to a MySQL database and adding new records
Novice Talker

Posts: 7
Trades: 0
I swear thought this code would work, but when I hit my 'ADD' button the screen blinks and nothing happens. The info that I inputted into the form field disappears. It is like the action=filename doesn't work, because I am not being redirected. Even if I go to mysql command line client and do a SELECT * from ups; (which is one of the tables) it shows an empty set. Can someone help please, because I am now on a time table and I don't know what else to do. Here is the html form and the php file:

HTML form:

<html>
<BODY BGCOLOR=#3399CC>
<head>
<title>CHS Master Inventory System</title>
</head>
<TABLE Border=
<B><FONT SIZE=10><CENTER>CHS Master Inventory</CENTER></FONT SIZE></B>
<h1><i><u><center>UPS Table</center></u></i></h1>
<form method="POST" action="http://localhost/newUpsRec.php">
<fieldset>
<legend><b>UPS Information</b></legend>
<b>ID:</b><input type=text name="id" size="15">
<b>Room/Area:</b><input type=text name="rmArea">
<b>CHS ID:</b><input type=text name="chsId" size="4">
<b>Model:</b><input type=text name="model" size="12"><br/><br/>
<b>Serial:</b><input type=text name="serial" size="15">
<b>Manufacturer:</b><input type=text name="manuf">
</fieldset><br/>
<input type='submit' value='ADD'><BR>
</form>
</body>
</html>

php file:

<html>
<head>
<title>CHS Master Inventory System</title>
</head>
<body bgcolor="#3399CC">
<?php
/* set's the variables for MySQL connection */
$dbhost = "localhost:3306"; // this is the server address and port
$dbuname = "root";// username
$dbpass = "hoover"; // password
$dbname = "chs";

/* Connects to the MySQL server */
$dbase = mysql_connect($dbhost, $dbuname, $dbpass) or die ("Could not connect to SQL Server");

/* Defines the Active Database for the Connection */
mysql_select_db($dbname, $dbase)

$id=$_POST['id']; $rmArea=$_POST['rmArea']; $chsid=$_POST['chsID']; $model=$_POST['model']; $serial=$_POST['serial']; $manuf=$_POST['manuf'];


$results = "INSERT INTO ups (id, room/area, chs id, model, serial, manuf) values ($id, $rmArea, $chsid, $model, $serial, $manuf)";
mysql_query($results);
echo "Record has been added.<br><a href="upsTBL.html">Click here</a>to return to UPS Table<br>";

mysql_close($dbase);
?>
</body>
</html>
rhinton6 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-28-2005, 06:24 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Try changing your form action to an absolute value rather than a relative one. Also turning error reporting on is always a good idea.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 06-29-2005, 12:35 PM
Novice Talker

Posts: 7
Trades: 0
how do you turn on error reporting? I thought that the or die was part of that.
rhinton6 is offline
Reply With Quote
View Public Profile
 
Old 06-29-2005, 04:04 PM
Novice Talker

Posts: 7
Trades: 0
My previous problem was dealing with my browser Firefox, because when I used IE I was redirected to my .php file. The problem now is that when the script has the INSERT command in it the screen is white and I don't see any error indication. Now if I comment that out the page contains the bgcolor that I specified. If I go to MySQL command line client and do a select command on the table, I get empty set. I generated that Insert command with phpmyadmin, which I do a query with phpmyadmin and it adds the record. Here is the php file:

<html>
<head>
<title>CHS Master Inventory System</title>
</head>
<body bgcolor="#3399CC">
<?php

/* set's the variables for MySQL connection */
$dbhost = "localhost:3306"; // this is the server address and port
$dbuname = "";// username
$dbpass = ""; // password
$dbname = "chs";

/* Connects to the MySQL server */
$dbase = mysql_connect($dbhost, $dbuname, $dbpass) or die ("Could not connect to SQL Server");

/* Defines the Active Database for the Connection */
mysql_select_db($dbname, $dbase);


$sql = 'INSERT INTO `ups` VALUES ('''', '$_GET['rmArea']', '$_GET['chsID']', '$_GET['model']', '$_GET['serial']', '$_GET['manuf']')';
$result = mysql_query($sql, $dbase);
if ($result) {echo "record added!";
} else {
echo "something went wrong";
}

mysql_close($dbase);
?>
</body>
</html>
rhinton6 is offline
Reply With Quote
View Public Profile
 
Old 06-30-2005, 06:58 PM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
Trades: 0
Just wanna asked if u've solved your problem or still want more explantion.
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.

Please login or register to view this content. Registration is FREE
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Old 07-01-2005, 01:58 PM
Novice Talker

Posts: 7
Trades: 0
It still is doing the same thing. I just thought if I stepped away for awhile then it would come to me. To answer your question, no. Whenever I press my Add button it just changes to the .php file, but I don't see anything. I mean no error message or nothing. But in the address, I do see all my variables that were passed on from the html form. They are just not being written to the SQL Database.
rhinton6 is offline
Reply With Quote
View Public Profile
 
Old 07-01-2005, 06:40 PM
metho's Avatar
Ultra Talker

Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
Trades: 0
Get some error reporting in there. If the script isn't getting past the sql statement, then it's handy to see what mysql wants to say.

change $result = mysql_query($sql, $dbase);

to : $result = mysql_query($sql, $dbase) or die(mysql_error());

I bet $2 you get a syntax or index error.
__________________
I do
Please login or register to view this content. Registration is FREE
based.
Spend a lot of time in
Please login or register to view this content. Registration is FREE
.
And
Please login or register to view this content. Registration is FREE
chews up the rest.
metho is offline
Reply With Quote
View Public Profile Visit metho's homepage!
 
Old 07-01-2005, 08:34 PM
Uche's Avatar
Extreme Talker

Posts: 174
Location: Nigeria/Lagos
Trades: 0
You mean wen u preview it it shows blank pages ? and report .php
__________________
Life is just lyke a school where everybody goes to learn one or two thing. the more u school, the more u learn more about school..The more we live our lifes.. the more we learn more about life.

Please login or register to view this content. Registration is FREE
Uche is offline
Reply With Quote
View Public Profile Visit Uche's homepage!
 
Old 07-02-2005, 11:54 AM
Novice Talker

Posts: 7
Trades: 0
This code worked for me:

<html>
<head>
<title>CHS Master Inventory System</title>
</head>
<body bgcolor="#3399CC">
<?php

/* set's the variables for MySQL connection */
$dbhost = "localhost:3306"; // this is the server address and port
$dbuname = "root";// username
$dbpass = "hoover"; // password
$dbname = "chs";

/* Connects to the MySQL server */
$dbase = mysql_connect($dbhost, $dbuname, $dbpass);

/* Defines the Active Database for the Connection */
mysql_select_db($dbname, $dbase);

/* Define Variables */
$rmArea = $_GET['rmArea'];
$chsID = $_GET['chsID'];
$model = $_GET['model'];
$serial = $_GET['serial'];
$manuf = $_GET['manuf'];


$sql = "INSERT INTO ups VALUES ('''', '$rmArea', '$chsID', '$model', '$serial', '$manuf')";
$result = mysql_query($sql, $dbase) or die (mysql_error());

/* Let us know if it worked or if it didnt! */

if(!$result) {
echo("Query Failed!");
}
else
{
echo("Successful Entry");

}

mysql_close($dbase);
?>
<br>
<b><i><a href="upsTBL.html">Click here</a></i></b> to return to UPS Table.
</body>
</html>
rhinton6 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Connecting to a MySQL database and adding new records
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32975 seconds with 12 queries