Advertisement

03.06.2008 at 02:41AM PST, ID: 23219026
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Need to insert/update data to an sql database

Asked by sbsupport in PHP and Databases, PHP Scripting Language, MySQL Server

Tags: , ,

Below is a quick preview of my table.

I have the most set up but I really need help on having the data from the form put into sql (and would like to keep all coding on one page)

Many Thanks in advanced!

=====================================================
[________] [Search]

ID   |   Start    |   Complete   |   Name   |   Subject   |   Enquiry   |   Assigned
----------------------------------------------------------------------------------------------
1     |01-01-01|   Yes            |    Jason  |    E-Mail     |    How do..|    JD
2     |02-01-01|   Yes            |    Adam  |    Printer    |    Is this... |    JD  <--any clicked, data goes below

Name:    [________]                                    Complete: [________]
Subject: [________]                                    Assigned:  [________]

[New Record] | [Update Record] | [Clear]
=====================================================

The PHP script is attached.

ThanksStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="table.css" type="text/css">
</head>
<body background="/Themes/default/images/main_bg.gif" style="margin: 0 0 0 0;">
<?
 
$idsel = $_GET['id'];
$search = $_GET['search'];
$sort = $_GET['sort'];
$order = $_GET['order'];
 
 if($order =='ASC'){
 $vorder = 'DESC';
 }
 else{
 $vorder = 'ASC';
 }
 
@$vstart = $_GET["vstart"];
if($vstart =='')
    $vstart =0;
 
$host = "localhost";
$username = "root";
$password = "password";
$db = "helpdesk";
$table ="helpdesk_data";
 
$link = mysql_connect($host,$username,$password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($db, $link);
if (!$db_selected) {
    die ("Can't use $db : " . mysql_error());
}
//total number of records in the table
 
$res = mysql_query("SELECT helpdesk_data.id as 'ID', helpdesk_data.start as 'Start', helpdesk_data.complete as 'Complete', if(CHAR_LENGTH(helpdesk_data.name)>15, concat(left(helpdesk_data.name,15),'...'), helpdesk_data.name) as 'Name', if(CHAR_LENGTH(helpdesk_data.subject)>20, concat(left(helpdesk_data.subject,20),'...'), helpdesk_data.subject) as 'Subject', if(CHAR_LENGTH(helpdesk_data.enquiry)>50, concat(left(helpdesk_data.enquiry,50),'...'), helpdesk_data.enquiry) as 'Enquiry', helpdesk_data.assigned_to as 'Assigned' FROM `$table`");
@$rows = mysql_num_rows ($res);
 
if($order ==''){
$result = mysql_query("SELECT helpdesk_data.id as 'ID', helpdesk_data.start as 'Start', helpdesk_data.complete as 'Complete', if(CHAR_LENGTH(helpdesk_data.name)>15, concat(left(helpdesk_data.name,15),'...'), helpdesk_data.name) as 'Name', if(CHAR_LENGTH(helpdesk_data.subject)>20, concat(left(helpdesk_data.subject,20),'...'), helpdesk_data.subject) as 'Subject', if(CHAR_LENGTH(helpdesk_data.enquiry)>50, concat(left(helpdesk_data.enquiry,50),'...'), helpdesk_data.enquiry) as 'Enquiry', helpdesk_data.assigned_to as 'Assigned' FROM `$table` WHERE id LIKE \"%$search%\" OR (start LIKE \"%$search%\" or  name LIKE \"%$search%\" or  subject LIKE \"%$search%\" or enquiry LIKE \"%$search%\" or  follow_up LIKE \"%$search%\") ORDER BY complete ASC, id DESC LIMIT $vstart,25");}
else{
$result = mysql_query("SELECT helpdesk_data.id as 'ID', helpdesk_data.start as 'Start', helpdesk_data.complete as 'Complete', if(CHAR_LENGTH(helpdesk_data.name)>15, concat(left(helpdesk_data.name,15),'...'), helpdesk_data.name) as 'Name', if(CHAR_LENGTH(helpdesk_data.subject)>20, concat(left(helpdesk_data.subject,20),'...'), helpdesk_data.subject) as 'Subject', if(CHAR_LENGTH(helpdesk_data.enquiry)>50, concat(left(helpdesk_data.enquiry,50),'...'), helpdesk_data.enquiry) as 'Enquiry', helpdesk_data.assigned_to as 'Assigned' FROM `$table` WHERE id LIKE \"%$search%\" OR (start LIKE \"%$search%\" or  name LIKE \"%$search%\" or  subject LIKE \"%$search%\" or enquiry LIKE \"%$search%\" or  follow_up LIKE \"%$search%\") ORDER BY $sort $order LIMIT $vstart,25");}
 
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
echo "<table align='center' width='750'><td><form>
<input type='hidden' name='id' value='$idsel'>
<input type='hidden' name='sort' value='complete asc,'>
<input type='hidden' name='order' value='id desc'>
<input name='search' type='text' value='$search'>&nbsp;
<input type='submit' value='search'></td></table>";
$cols = mysql_num_fields($result);
$records = mysql_num_rows ($result);
 echo "<table align='center' bgcolor='FFFFFF' width='750' cellspacing='1' cellpadding='0' border='0' >";
 echo "<tr bgcolor='505050' class='menu'>";
 
 for ($i = 0; $i < $cols;$i++)
 {
    echo "<td align='center'><a href='?id=$idsel&search=$search&sort=".mysql_field_name($result,$i)."&order=$vorder&vstart=$vstart'>".mysql_field_name($result,$i)."</a></td>";
 }
 echo "</tr>";
 while ($row = mysql_fetch_array($result, MYSQL_NUM))
 {
    echo "<tr bgcolor='F6F6F6' class='normal'>";
 
$idget = $row[0];
 
   foreach ($row as $value)
   { echo "<td class='table'><a href='?id=$idget&search=$search&sort=$sort&order=$order&vstart=$vstart'>".$value ."</a></td>";
   } 
   echo "</tr>";
 }
 $end = $vstart + $records;
 echo "
 
 <tr>
<td width='30'></td>
<td width='80'></td>
</tr>
 
 <tr  align = 'center' bgcolor = '505050' class='menu'><td colspan=$cols>";
 
     if($vstart != 0)
    {
    $prev = $vstart - 25;
    echo "<font size='2'>|</font> <a href='?id=$idsel&search=$search&sort=$sort&order=$order&vstart=$prev'>Previous</a> <font size='2'>|</font>";
    }
 
 echo " Records $vstart  to  $end  of $rows ";
 
 
      if($vstart<$rows-25)
     {
       $next = $vstart + 25;
       echo "<font size='2'>|</font> <a href='?id=$idsel&search=$search&sort=$sort&order=$order&vstart=$next'>Next</a> <font size='2'>|</font>";
    }
 
 
echo "</td></tr></form></table>";
 
  if ($id) {
    $sql = "SELECT * FROM helpdesk_data WHERE id=$id";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);
    $start = $myrow["start"];
    $complete = $myrow["complete"];
    $name = $myrow["name"];
    $email = $myrow["email"];
    $subject = $myrow["subject"];
    $enquiry = $myrow["enquiry"];
    $ext = $myrow["ext"];
    $follow_up = $myrow["follow_up"];
    $finish = $myrow["finish"];
    $assigned_to = $myrow["assigned_to"];
    $attachment = $myrow["attachment"];
 
echo "<input type=hidden name='id' value='$id''>";
  }
 
$newv = "INSERT INTO helpdesk_data (start, complete, name, email, subject, enquiry, ext, follow_up, finish, assigned_to, attachment) VALUES ($start, $complete, $name, $email, $subject, $enquiry, $ext, $follow_up, $finish, $assigned_to, $attachment)";
 
$new = $_GET['new'];
if($new =='New Record'){
$newv;
 }
else{}
 
$updatev = "UPDATE helpdesk_data SET start = $start, complete = $complete, name = $name, email = $email, subject = $subject, enquiry = $enquiry, ext = $ext, follow_up = $follow_up, finish = $finish, assigned_to = $assigned_to, attachment = $attachment WHERE id = $id";
 
$update = $_GET['update'];
if($update =='Update Record'){
$updatev;
}
else{}
 
echo "<table align='center' width='750'><td>
<form>
<tr>
<td width='50'>ID:</td><td>$id</td><input name='id' type='hidden' value='$id'>
<td width='50'>Start:</td><td><input name='start' type='text' value='$start'></td>
</tr>
<tr>
<td width='50'>Name:</td><td><input name='name' type='text' value='$name'></td>
<td width='50'>Complete:</td><td><input name='complete' type='text' value='$complete'></td>
</tr>
<tr>
<td width='50'>Subject:</td><td><input name='subject' type='text' value='$subject'></td>
<td width='50'>Assigned:</td><td><input name='assigned' type='text' value='$assigned_to'></td>
</tr>
<tr>
<td width='50'>Enquiry:</td><td><textarea name='enquiry' cols=35 rows=8>$enquiry</textarea></td>
<td width='50'>Follow:</td><td><textarea name='follow' cols=35 rows=8>$follow_up</textarea></td>
</tr>
<tr>
<td width='50'>Ext:</td><td><input name='ext' type='text' value='$ext'></td>
<td width='50'>Finished:</td><td><input name='finished' type='text' value='$finish'></td>
</tr>
<tr>
<td width='50'>Attachment:</td><td><a target='_blank' href='/support/admin/files/$attachment'>$attachment</a></td>
</tr>
</table>
<table align='center' width='750'><td>
<tr>
<td width='10'><input name='new' type='submit' value='New Record'></td>
<td width='10'><input name='update' type='submit' value='Update Record'></td></form>
<td><form>
<input name='id' type='hidden' value=''>
<input name='clear' type='submit' value='Clear'></td></form>
</tr></td></table>";
?>
</body>
</html>
Attachments:
 
Screenshot
Screenshot
 
 
 
[+][-]03.06.2008 at 04:57AM PST, ID: 21059644

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language, MySQL Server
Tags: PHP, MySQL, Internet Explorer, http://localhost
Sign Up Now!
Solution Provided By: Angelp1ay
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.06.2008 at 05:00AM PST, ID: 21059660

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.06.2008 at 06:49AM PST, ID: 21060625

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628