Solved

PHP / MYSQL update

Posted on 2011-03-15
15
245 Views
Last Modified: 2012-05-11
Hi Experts,

Im in need of some help desperately.

I have a page where you can edit "notes" and also edit "last spoken to" and you can edit these by typeing in the boxes at the bottom of the page. The customer is selected using a variable but when i try to navigate back to the page the variable for the customer is obviously lost. is there a way of fixing this? ive attached code many thanks.


// mobile num.php // 

<?php
session_start();
ob_start();
?>
<?
error_reporting(E_ALL);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

    
<title>Talk Business Solutions</title>

        <link id="css_default" href="unity_scm.css" 
rel="stylesheet" type="text/css">
    </head><body>
        <div class="fullpage">
            <div class="topbar">
                <div class="topbar_left"></div>
            </div>

            <div class="secondbar">
            </div>

            <div class="header">
              <div align="center"><span class="secondbar"><img src="index_files/unity_scm_images/header.gif" width="970" height="140" alt="headerimage" /></span></div>
            </div>
            <div class="leftcol">

	      <div class="bar">&nbsp;</div>
				<div class="titleimage">
                	<div align="center"><img src="/test.gif" alt="navgif">
              	  </div>
				</div>
				<div class="bar">&nbsp;</div>

                <div align="center"><a name="sitenav"></a>
                  <ul class="navbar">
                    <li><a 
href="logout.php" accesskey="1">Logout</a></li>
                    <li><a href="link2.php" accesskey="2">Link2</a></li>
                    <li><a href="link3.php" accesskey="3">Link3</a></li>
                    <li><a href="link4.php" accesskey="4">Link4</a></li>
                    <li><a href="link5.php" accesskey="5">Link5</a></li>
                    <li><a href="link6.php" accesskey="6">Link6</a></li>
                    <li><a href="link7.php" accesskey="7">Link7</a></li>
                    
                    
                    
                    
                  </ul>
                  </ul>
                </div>
                <div class="sidebarbottom">&nbsp;</div>
            </div>
            <div class="mainarea">
            
    <div align="center">

    </div>
          <div class="pagearea">
                    <div align="center"><a name="content"></a>
                      
                    </div>
            <h2 align="center">Talk Business Solutions</h2>

<p align="center" style="font-size: 0.8em; border-color: rgb(221, 221, 221);"><em>Here is a list of all customers in relation to the company selected..</em></p>

<h3 align="center" class="banner">Customers</h3>
<p align="center"></p>


<title></title>
<div align="center">
  <body>
  
  
  <body bgcolor="#c9cfef" link="#000000" vlink="#000000">
  
</div>
<tr>
</div>
<td width="100" valign="top"></td>
<td width="100" nowrap><div align="center"><br />
  
  
</div></td>
<p align="center">
<?php 
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];
$sql = "SELECT * FROM customer WHERE customer_name = '" . $val . "'";
$result = mysql_query($sql) or die(mysql_error() . " IN $sql"); 
$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
   echo"<table>";
   echo "<tr><td>Company:</td><td>".$row['customer_name']."</td></tr>";
    echo "<tr><td>Account Number:</td><td><a href=\"account.php?val=".$row['account_number']."\">".$row['account_number']."</a></td></tr>";
	 echo "<tr><td>Contact Name:</td><td>".$row['contact_name']."</td></tr>";
	 echo "<tr><td>Telephone Number:</td><td>".$row['telephone_number']."</td></tr>";
	 echo "<tr><td>Fax:</td><td>".$row['fax']."</td></tr>";
	 echo "<tr><td>Contact Mob Number:</td><td>".$row['contact_mobile']."</td></tr>";
	 echo "<tr><td>Address:</td><td>".$row['full_address']."</td></tr>";
	 echo "<tr><td>Network:</td><td>".$row['network']."</td></tr>";
	 echo "<tr><td>Last Spoke To:</td><td>".$row['last_spoke_to']."</td></tr>";
	 echo "<tr><td>Notes:</td><td>".$row['notes']."</td></tr>";
	 echo "<tr><td>Kit Fund Level:</td><td>".$row['kit_fund_level']."</td></tr>";
   echo"</table>";
}
   ?> 
<?php 
$query=" SELECT * FROM customer";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
$last_spoke_to=mysql_result($result,$i,"last_spoke_to");
$notes=mysql_result($result,$i,"notes");
++$i;
}
?>

<title></title>
<body>
<form name="register" method="post" action="edituploadednotes.php">
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  <tr>
    <td colspan="14" bgcolor="#ffffff"><strong>Edit Notes</strong></td>
  </tr>
  <tr>
    <td width="249" bgcolor="#ffffff">Last spoke to</td>
    <td width="7" bgcolor="#ffffff">:</td>
   <td width="393" bgcolor="#ffffff"><textarea name="last_spoke_to" cols="40" rows="10">
Enter your last spoke to here....
</textarea>
      <br /></td>
  </tr>
  <tr>
    <td width="249" bgcolor="#ffffff">Notes</td>
    <td width="7" bgcolor="#ffffff">:</td>
    <td width="393" bgcolor="#ffffff"><textarea name="notes" cols="40" rows="10">
Enter your notes here....
</textarea>
      <br /></td>
  </tr>
  <td wdith="1298" bgcolor="#ffffff"><input type="submit" name="Submit" value="Update" /></td>
  </tr>
</table></td>
</form>


</p>

<th>&nbsp;</th> 
  <td>&nbsp;</td>
  <div align="center"><br/>
    <img src="" width="" height="
                              ">
    
    
  </div>
<div align="center">
  </div>
  </div>
  
</div>
<div class="spacer"></div>

         
            <div class="footer">
            	<div class="secondbar_bottom">
            	  <div align="center">
            	    <?php //echo 'Welcome ' .''. $_SESSION['myusername'];?>
          	    </div>
            	</div>
            	<div class="bottombar">
            	  <div align="center">Talk Business Solutions</div>
            	</div>
            </div>
        <div align="center">
              </div>
    </div>
</body></html>

/// EDITUPLOADEDNOTES.PHP THIS IS THE PAGE IT EXECUTES TO /// 

<?php
session_start();
ob_start();
?>
<?php 
error_reporting(E_ALL);

$last_spoke_to = $_POST['last_spoke_to'];
$notes = $_POST['notes'];
$val = $_GET['val'];


include 'myphp.php';


//update the database with the set variables recoverd from the form from the other page. 

$query = "UPDATE customer SET last_spoke_to = '$last_spoke_to', notes = '$notes'";


$result=mysql_query($query);

 if($result){
	header("location:mobilenum.php");
}
else{
	echo "ERROR";
}
mysql_close();

?>

Open in new window

0
Comment
Question by:NeoAshura
  • 8
  • 5
  • 2
15 Comments
 
LVL 13

Assisted Solution

by:dsmile
dsmile earned 50 total points
Comment Utility
Online 218, use this

header("location:mobilenum.php". $val);
0
 
LVL 13

Expert Comment

by:dsmile
Comment Utility
header("location:mobilenum.php?val=". $val);

Explanation: since you use $_GET['val'] as the input for your query, you have to pass it to the url again when you redirect the page.
0
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
hi sadly that did not work.

 Notice: Undefined index: val in I:\EasyPHP-5.3.5.0\www\mobilenum.php on line 93
0
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
for example when i click update the url goes to the following.

http://127.0.0.1:8888/mobilenum.php

and obviously unsets the variable.

When it should just refer back to its previous variable of...

http://127.0.0.1:8888/mobilenum.php?val=Mrs%20Anna%20Norris
0
 
LVL 3

Expert Comment

by:pius_babbun
Comment Utility
dsmile's explanation is best answer.. any how if you need all the values to your page.....

Please try this


Change this code as follwoing

$last_spoke_to = $_POST['last_spoke_to'];
$notes = $_POST['notes'];
$val = $_GET['val'];


$last_spoke_to  = $_REQUEST['last_spoke_to'];
$notes               = $_REQUEST['notes'];
$val                        = $_REQUEST['val'];


And change this line

header("location:mobilenum.php");
 
header("location:mobilenum.php?val=".$val."&last_spoke_to=".$last_spoke_to."&note=".$notes);
0
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
thats for the reply,

This return the following, url

http://127.0.0.1:8888/mobilenum.php?val=

as you can see it misses out the val of the customer.

thanks for the reply any more ideas?
0
 
LVL 3

Expert Comment

by:pius_babbun
Comment Utility
Instead of this

$_GET['val']

Try request method


$_REQUEST['val']


or

in the page

just print the values that are sent

using

print_r($_GET); exit;

or

print_r($_REQUEST); exit;
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
hi pius thanks for reply,

with print_r($_get);EXIT;

i get the following..

Array ( [val] => )

with

$val= $_REQUEST['val'];
print_r($_REQUEST); exit;

i get

Array ( [val] => [last_spoke_to] => Enter your last spoke to here.... [notes] => Enter your notes here.... [Submit] => Update )

as you can see the only variable not being set is val.... i need this to be able to send the header back to my origonal page.. all i need to do is somehow pass my val to the next page and then pass it back again.

0
 
LVL 3

Expert Comment

by:pius_babbun
Comment Utility
NeoAshura....

ok fine form which page you are sending val ? val does not have values to request or get....

assign some value for val and  check
0
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
VAL is set and comes from this page here

Please See line 4.


<?php 
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];
$sql = "SELECT * FROM customer WHERE customer_name = '" . $val . "'";
$result = mysql_query($sql) or die(mysql_error() . " IN $sql"); 
$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
   echo"<table>";
   echo "<tr><td>Company:</td><td>".$row['customer_name']."</td></tr>";
    echo "<tr><td>Account Number:</td><td><a href=\"account.php?val=".$row['account_number']."\">".$row['account_number']."</a></td></tr>";
	 echo "<tr><td>Contact Name:</td><td>".$row['contact_name']."</td></tr>";
	 echo "<tr><td>Telephone Number:</td><td>".$row['telephone_number']."</td></tr>";
	 echo "<tr><td>Fax:</td><td>".$row['fax']."</td></tr>";
	 echo "<tr><td>Contact Mob Number:</td><td>".$row['contact_mobile']."</td></tr>";
	 echo "<tr><td>Address:</td><td>".$row['full_address']."</td></tr>";
	 echo "<tr><td>Network:</td><td>".$row['network']."</td></tr>";
	 echo "<tr><td>Last Spoke To:</td><td>".$row['last_spoke_to']."</td></tr>";
	 echo "<tr><td>Notes:</td><td>".$row['notes']."</td></tr>";
	 echo "<tr><td>Kit Fund Level:</td><td>".$row['kit_fund_level']."</td></tr>";
   echo"</table>";
}
   ?> 
<?php 
$query=" SELECT * FROM customer";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
$last_spoke_to=mysql_result($result,$i,"last_spoke_to");
$notes=mysql_result($result,$i,"notes");
++$i;
}
?>

<title></title>
<body>
<form name="register" method="post" action="edituploadednotes.php">
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  <tr>
    <td colspan="14" bgcolor="#ffffff"><strong>Edit Notes</strong></td>
  </tr>
  <tr>
    <td width="249" bgcolor="#ffffff">Last spoke to</td>
    <td width="7" bgcolor="#ffffff">:</td>
   <td width="393" bgcolor="#ffffff"><textarea name="last_spoke_to" cols="40" rows="10">
Enter your last spoke to here....
</textarea>
      <br /></td>
  </tr>
  <tr>
    <td width="249" bgcolor="#ffffff">Notes</td>
    <td width="7" bgcolor="#ffffff">:</td>
    <td width="393" bgcolor="#ffffff"><textarea name="notes" cols="40" rows="10">
Enter your notes here....
</textarea>
      <br /></td>
  </tr>
  <td wdith="1298" bgcolor="#ffffff"><input type="submit" name="Submit" value="Update" /></td>
  </tr>
</table></td>
</form>

Open in new window

0
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
p.s page attached is called mobilenum.php and need the variable passing to edituploadednotes.php which is sent for by the form.

then when on edituploadednotes.php the val then needs to be sent back... to mobilenum.php to display

mobilenum.php?val=var here
0
 
LVL 3

Accepted Solution

by:
pius_babbun earned 450 total points
Comment Utility
Just add a hidden feild after the form tag as below and check if it is helpful

<form name="register" method="post" action="edituploadednotes.php">
<input type="hidden" value="<?php echo $_GET['val']; ?>" name="val" >
0
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
You sir are a genius.

Thank you very much.
0
 
LVL 6

Author Closing Comment

by:NeoAshura
Comment Utility
points awarded for contributing to dsmile.

full answer awarded 200 points to pius.
0
 
LVL 3

Expert Comment

by:pius_babbun
Comment Utility
thanks NeoAshura..great participating ....
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress syntax error 1 27
Php Array Diff 3 26
html input clean up 3 28
Creating a slider 12 31
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now