...

View Full Version : saving



angelstar
12-31-2007, 10:13 PM
hi,
i created a form in which you will put all the data, my prblem is, I want to save it in the database and at the same time it will appear on another page with a table form, I don't know if i used the right code.. please check my code below...

thanks :confused:

====this is the form code===
<form method="get" action ="#.php">
<table border=0 class="sam" align=center>
<td class="td1"><br><br>
<br>Users Information
<td class="td1"><td class="td1"><td class="td1">
<tr><td>
Department:<td>
<select name="department">
<option value="Select...">Select...</option>
<option value="Cebu">Cebu</option>
<option value="Davao">Davao</option>
<option value="Executive">Executive</option>
<option value="Finance">Finance</option>
<option value="Marketing">Marketing</option>
<option value="MIS">MIS</option>
<option value="Quality and Customer Care">Quality and Customer Care</option>
<option value="Sales">Sales</option>
<option value="Service">Service</option>
<option value="Supply Chain">Supply Chain</option></select>
</td>
<td>
&nbspDate:<td> <input type="text" name="dept" size="10">
</td>
<tr>
<td>
User Name:<td><input type="text" name="user" size="27">
</td>
<tr>
<td class="td1">
<br>
Issued Equipment
<td class="td1"><td class="td1"><td class="td1">
</td>
<tr>
<td>
Form:<td><select name="form">
<option value="Select...">Select...</option>
<option value="Desktop">Desktop</option>
<option value="Laptop">Laptop</option>
<option value="Notebook">Notebook</option>
</select>
</td>

===this is the save code===
<?php

header("Expires: Thu, 17 May 2001 10:17:17 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s"). " GMT");
header("cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

session_start();
$_SESSION['mainFrameurl']=$_SERVER["REQUEST_URI"];

include_once("images/connect.php");

$sserial = $_REQUEST['serial'];

if($sserial)

{
$sql="SELECT*FROM tblmaster WHERE serial =".$sserial;

$result = mysql_query($sql);

$sLoaddepartment = mysql_result($result,$i,"department");
$sLoaduserName = mysql_result($result,$i,"userName");
$sLoadissued = mysql_result($result,$i,"issued");

$sLoadform = mysql_result($result,$i,"form");
$sLoadbrand = mysql_result($result,$i,"brand");
$sLoadmodel = mysql_result($result,$i,"model");
$sLoadserial = mysql_result($result,$i,"serial");
$sLoaddatepurchased = mysql_result($result,$i,"datepurchased");

$sLoadprocessor = mysql_result($result,$i,"processor");
$sLoadsystem = mysql_result($result,$i,"system");
$sLoadusb = mysql_result($result,$i,"usb");
$sLoadmemory = mysql_result($result,$i,"memory");
$sLoadharddisk = mysql_result($result,$i,"harddisk");
$sLoadphone = mysql_result($result,$i,"phone");

$sLoadcost = mysql_result($result,$i,"cost");
$sLoadremarks = mysql_result($result,$i,"remarks");

}
?>

====and this is the table code where I want those data to appear====
<table border=1>
<th class="td1">Department</th>
<th class="td1">User Name</td></th>
<th class="td1">Form</td></th>
<th class="td1">Type/Model</td></th>
<th class="td1">Brand</td></th>
<th class="td1">Date Purchased</td></th>
<!---the primary key-->
<th class="td1">Serial Number</td></th>
<th class="td1">Processor</td></th>
<th class="td1">Operating System</td></th>
<th class="td1">Memory</td></th>
<th class="td1">USB Flash Drive</td></th>
<th class="td1">Harddisk Capacity</td></th>
<th class="td1">Telephone Model</td></th>
<th class="td1">Acquisition Cost</td></th>

<tr>
<td name="department"></td>
<td name="user"></td>
<td name="form"></td>
<td name="model"></td>
<td name="brand"></td>
<td name="purchase"></td>
<td name="serial"></td>

StupidRalph
12-31-2007, 10:31 PM
Check the links here (http://www.codingforums.com/showthread.php?t=68462) and here (http://www.codingforums.com/rules.htm).

StupidRalph
12-31-2007, 10:33 PM
You are trying to SELECT but never actually INSERT INTO the database. You have to insert the values into the table before you can SELECT them. Try reading up some one SQL.

angelstar
01-01-2008, 12:03 PM
ohh I see thanks....but i'm confuse where do i put that INSERT INTO code..do i need to create another file? ...

INSERT INTO 'tblmasterinvent' ('department', 'userName', 'issued', 'form', 'brand', 'model', 'serial', 'datepurchased', 'processor', 'system', 'usb', 'memory', 'harddisk', 'phone', 'cost', 'remarks' )

is this what you mean? where do i put this one.... also i'm using phpmyadmin... i created there my database and table.....

thanks again... :confused:

StupidRalph
01-01-2008, 10:19 PM
You should add it to the save code...since the insert is what actually saves the information...also in your INSERT code you're inserting those static values and not variables.


<?php

header("Expires: Thu, 17 May 2001 10:17:17 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s"). " GMT");
header("cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

session_start();
$_SESSION['mainFrameurl']=$_SERVER["REQUEST_URI"];

include_once("images/connect.php");

$sserial = $_REQUEST['serial'];

if($sserial)

{
$sql = "INSERT INTO 'tblmasterinvent' ('department', 'userName', 'issued', 'form', 'brand', 'model', 'serial', 'datepurchased', 'processor', 'system', 'usb', 'memory', 'harddisk', 'phone', 'cost', 'remarks' )";

$result = mysql_query($sql) or die(mysql_error()); // you will want error testing while you're developing

$sql="SELECT*FROM tblmaster WHERE serial =".$sserial;

$result = mysql_query($sql) or die(mysql_error()); //same here

$sLoaddepartment = mysql_result($result,$i,"department");
$sLoaduserName = mysql_result($result,$i,"userName");
$sLoadissued = mysql_result($result,$i,"issued");

$sLoadform = mysql_result($result,$i,"form");
$sLoadbrand = mysql_result($result,$i,"brand");
$sLoadmodel = mysql_result($result,$i,"model");
$sLoadserial = mysql_result($result,$i,"serial");
$sLoaddatepurchased = mysql_result($result,$i,"datepurchased");

$sLoadprocessor = mysql_result($result,$i,"processor");
$sLoadsystem = mysql_result($result,$i,"system");
$sLoadusb = mysql_result($result,$i,"usb");
$sLoadmemory = mysql_result($result,$i,"memory");
$sLoadharddisk = mysql_result($result,$i,"harddisk");
$sLoadphone = mysql_result($result,$i,"phone");

$sLoadcost = mysql_result($result,$i,"cost");
$sLoadremarks = mysql_result($result,$i,"remarks");

}
?>

angelstar
01-02-2008, 06:18 AM
thanks again..... i tried what you've suggested, when i hit the save button, this messages appear You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1...i also tried to replace the $sLoad into this $add like this...

$adddepartment = $_REQUEST['department'];
$adduserName = $_REQUEST['userName'];
$addissued = $_REQUEST['issued'];

it also do the same... what will I do? I also want that if I hit the save button it will give me a message if it successfully save on my database for confirmation.... hope u can help me again please...

StupidRalph
01-02-2008, 12:07 PM
Just a note..I'm just copying and pasting your code I'm not actually debugging your script b/c I want you to learn. But I will point out the things that I do notice.



$sql = "INSERT INTO 'tblmasterinvent' ('department', 'userName', 'issued', 'form', 'brand', 'model', 'serial', 'datepurchased', 'processor', 'system', 'usb', 'memory', 'harddisk', 'phone', 'cost', 'remarks' )"; //you quoted the table name (tblmasterinvent).....those should be either left off or replaced with backticks ( ` ).

Review this link.
http://www.w3schools.com/php/php_mysql_insert.asp

StupidRalph
01-02-2008, 12:10 PM
Actually, I just looked at all your code and I've noticed a few things wrong such as you using the "get" method opposed to "post". I'm actually on my way to bed but if you haven't figured anything out in a few hours then I'll break it all down for you.

hammer65
01-02-2008, 09:11 PM
Input values that are inserted into queries also need to be escaped using the appropriate escaping function for the database you are using. In this case mysql_real_escape_string().

There are security considerations that require escaping, but you also can run into trouble if any input contains single quotes (like the name O'Grady).

Find a tutorial on PHP and MySQL. There are plenty out there. You reall need at least knowledge of the basics of database access, SQL and security to do this sort of thing right.

angelstar
01-03-2008, 02:36 AM
sorry for my late response, just trying to managed my time, 'coz I'm a working student...anyway thanks for your advice..I'm going to try what you all said, hope I can make it right now.. Thanks again..

angelstar
01-03-2008, 12:20 PM
hey, thanks sooooo much! :) I did it! it save to my database, now i'm trying to do the next step, that it will appear into other page all the data that i've save for viewing.. the table form.... can you give me some sort of hint.. what to do...


thanks so much again :thumbsup:

==this is the sample table that i'm working on===
table border=1>
<th class="td1">Department</th>
<th class="td1">User Name</td></th>
<th class="td1">Form</td></th>
<th class="td1">Type/Model</td></th>
<th class="td1">Brand</td></th>
<th class="td1">Date Purchased</td></th>
<!---the primary key-->
<th class="td1">Serial Number</td></th>
<th class="td1">Processor</td></th>
<th class="td1">Operating System</td></th>
<th class="td1">Memory</td></th>
<th class="td1">USB Flash Drive</td></th>
<th class="td1">Harddisk Capacity</td></th>
<th class="td1">Telephone Model</td></th>
<th class="td1">Acquisition Cost</td></th>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum