Current location: Hot Scripts Forums » Programming Languages » PHP » How do you UPDATE an SQL from PHP


How do you UPDATE an SQL from PHP

Reply
  #1 (permalink)  
Old 10-24-11, 02:40 PM
phildcan phildcan is offline
New Member
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
How do you UPDATE an SQL from PHP

So I built this form and the inputs on the form are inserted to my SQL. My Problem is, i dont know how to recall the information and then update it instead of deleting the row and then re inserting.

here is my form...account info was taken out

Code:
<?php 
if (!isset($_POST['submit'])) { 
// form not submitted 
?> 

<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
<h1>Online Work Order Form</h1>
<tr>
<td align="right">Work Order #:</td>
<td><input type="text" name="wotext" size="20" /></td>
<td align="right">Date:</td>
<td><input type="text" name="datetext" size="10" /></td>
</tr>
<tr>
<td align="right">Customer:</td>
<td><input type="text" name="custext" size="20" /></td>
<td align="right">Location:</td>
<td><input type="text" name="loctext" size="20" /></td>
</tr>
	<br />
	<br />	
<tr>
<td align="right">Total Qty:</td>
<td><input type="text" name="Tqty" size="2" /></td>
<td align="right">Remaining:</td>
<td><input type="text" name="Rqty" size="2" /></td>
</tr>
	<br />
	<br />
<tr>
<td align="right">Cylinder #1:</td>
<td><input type="text" name="cyl1text" size="20" /></td>
<td align="right">Status:
<select name="stat1text" />
  <option></option>
  <option>Standard (1-2 weeks)</option>
  <option>Rush (3-4 days)</option>
  <option>Next Day (1-2 days)</option>
  <option>DELIVERED</option>
</select></td>
<td align="right">Comments:</td>
<td><input type="text" name="comm1text" size="20" /></td>
</tr>
	<br />
<tr>
<td align="right">Cylinder #2:</td>
<td><input type="text" name="cyl2text" size="20" /></td>
<td align="right">Status:
<select name="stat2text" />
  <option></option>
  <option>Standard (1-2 weeks)</option>
  <option>Rush (3-4 days)</option>
  <option>Next Day (1-2 days)</option>
  <option>DELIVERED</option>
</select></td>
<td align="right">Comments:</td>
<td><input type="text" name="comm2text" size="20" /></td>
</tr>
	<br />
<tr>
<td align="right">Cylinder #3:</td>
<td><input type="text" name="cyl3text" size="20" /></td>
<td align="right">Status:
<select name="stat3text" />
  <option></option>
  <option>Standard (1-2 weeks)</option>
  <option>Rush (3-4 days)</option>
  <option>Next Day (1-2 days)</option>
  <option>DELIVERED</option>
</select></td>
<td align="right">Comments:</td>
<td><input type="text" name="comm3text" size="20" /></td>
</tr>
	<br />
<tr>
<td align="right">Cylinder #4:</td>
<td><input type="text" name="cyl4text" size="20" /></td>
<td align="right">Status:
<select name="stat4text" />
  <option></option>
  <option>Standard (1-2 weeks)</option>
  <option>Rush (3-4 days)</option>
  <option>Next Day (1-2 days)</option>
  <option>DELIVERED</option>
</select></td>
<td align="right">Comments:</td>
<td><input type="text" name="comm4text" size="20" /></td>
</tr>
	<br />	
<tr>
<td align="right">Cylinder #5:</td>
<td><input type="text" name="cyl5text" size="20" /></td>
<td align="right">Status:
<select name="stat5text" />
  <option></option>
  <option>Standard (1-2 weeks)</option>
  <option>Rush (3-4 days)</option>
  <option>Next Day (1-2 days)</option>
  <option>DELIVERED</option>
</select></td>
<td align="right">Comments:</td>
<td><input type="text" name="comm5text" size="20" /></td>
</tr>
	<br />
	<br />
<input type="submit" name="submit">
</form>
	
<?php 
} 
else { 
// form submitted 
// set server access variables 
$host = 'localhost';
$user = 'user'; 
$pass = 'password';
$db = 'database';
     
// get form input 
    // check to make sure it's all there 
    // escape input values for greater safety 
    $wo_text = empty($_POST['wotext']) ? die ("ERROR: Enter a work order number") : mysql_escape_string($_POST['wotext']);
	$date_text = empty($_POST['datetext']) ? die ("ERROR: Please enter date recieved") : mysql_escape_string($_POST['datetext']);
	$cus_text = empty($_POST['custext']) ? die ("ERROR: Enter a customer Name") : mysql_escape_string($_POST['custext']);
	$loc_text = empty($_POST['loctext']) ? die ("ERROR: Enter customer Location") : mysql_escape_string($_POST['loctext']);
	$T_qty = empty($_POST['Tqty']) ? die ("ERROR: Enter total qty. of cylinder(s) on work order") : mysql_escape_string($_POST['Tqty']);
	$R_qty = empty($_POST['Rqty']) ? die ("ERROR: Enter remaining qty. of cylinder(s) on work order") : mysql_escape_string($_POST['Rqty']);
	$cyl1_text = empty($_POST['cyl1text']) ? die ("ERROR: Must have atleast 1 Cylinder") : mysql_escape_string($_POST['cyl1text']);
	$cyl2_text = ($_POST['cyl2text']);
	$cyl3_text = ($_POST['cyl3text']);
	$cyl4_text = ($_POST['cyl4text']);
	$cyl5_text = ($_POST['cyl5text']);
	$stat1_text = ($_POST['stat1text']);
	$stat2_text = ($_POST['stat2text']);
	$stat3_text = ($_POST['stat3text']);
	$stat4_text = ($_POST['stat4text']);
	$stat5_text = ($_POST['stat5text']);
	$com1_text = ($_POST['com1text']);
	$com2_text = ($_POST['com2text']);
	$com3_text = ($_POST['com3text']);
	$com4_text = ($_POST['com4text']);
	$com5_text = ($_POST['com5text']);	
		
    // open connection 
    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
     
    // select database 
    mysql_select_db($db) or die ("Unable to select database!"); 
     
    // create query 
	$query = "INSERT INTO `testing` (`Work Order`, `Date`, `Customer`, `Location`, `Tqty`, `Rqty`, `Cyl1`, `Cyl2`, `Cyl3`, `Cyl4`, `Cyl5`, `Stat1`, `Stat2`, `Stat3`, `Stat4`, `Stat5`, `Com1`, `Com2`, `Com3`, `Com4`, `Com5`) VALUES ('$wo_text', '$date_text', '$cus_text', '$loc_text', '$T_qty', '$R_qty', '$cyl1_text', '$cyl2_text', '$cyl3_text', '$cyl4_text', '$cyl5_text', '$stat1_text', '$stat2_text', '$stat3_text', '$stat4_text', '$stat5_text', '$com1_text', '$com2_text', '$com3_text', '$com4_text', '$com5_text')";
	
	// execute query 
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
     
    // print message with ID of inserted record 
    echo "New record inserted! <br/>";
    echo "<br/>";	
	echo "Work Order #: $wo_text <br/>";
	echo "Date Recieved: $date_text <br/>";
	echo "Customer: $cus_text <br/>";
	echo "Location: $loc_text <br/>";
	echo "Total Qty: $T_qty <br/>";
	echo "Remaining Qty: $R_qty <br/>";
    echo "<br/>";
    echo "<br/>";	
	echo "Cylinder #1: $cyl1_text <br/>";
	echo "Status: $stat1_text <br/>";
	echo "Comments: $com1_text <br/>";
    echo "<br/>";
    echo "<br/>";	
	echo "Cylinder #2: $cyl2_text <br/>";
	echo "Status: $stat2_text <br/>";
	echo "Comments: $com2_text <br/>";
    echo "<br/>";
    echo "<br/>";	
	echo "Cylinder #3: $cyl3_text <br/>";
	echo "Status: $stat3_text <br/>";
	echo "Comments: $com3_text <br/>";
    echo "<br/>";
    echo "<br/>";	
	echo "Cylinder #4: $cyl4_text <br/>";
	echo "Status: $stat4_text <br/>";
	echo "Comments: $com4_text <br/>";
    echo "<br/>";
    echo "<br/>";	
	echo "Cylinder #5: $cyl5_text <br/>";
	echo "Status: $stat5_text <br/>";
	echo "Comments: $com5_text <br/>";
    echo "<br/>";
    echo "<br/>";	
	
    // close connection 
    mysql_close($connection); 
} 
?>
I am not that great with code and it took me a while to get this to work...but i really need to beable to update it.

Thanks in advance.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sports Pick Em racingboy20 Script Requests 3 06-18-10 03:12 AM
PHP SQL - returning multiple arrays in one query Kruulos PHP 3 05-06-10 05:19 PM
Integrating paypal using PHP and SQL WillUK PHP 7 07-28-09 09:59 AM
Doubts in SQL and PHP reshma PHP 5 04-21-09 12:32 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 08:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.