PHP / MYSQL update

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

LVL 6
NeoAshuraAsked:
Who is Participating?
 
pius_babbunConnect With a Mentor Commented:
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
 
dsmileConnect With a Mentor Commented:
Online 218, use this

header("location:mobilenum.php". $val);
0
 
dsmileCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
NeoAshuraAuthor Commented:
hi sadly that did not work.

 Notice: Undefined index: val in I:\EasyPHP-5.3.5.0\www\mobilenum.php on line 93
0
 
NeoAshuraAuthor Commented:
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
 
pius_babbunCommented:
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
 
NeoAshuraAuthor Commented:
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
 
pius_babbunCommented:
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
 
NeoAshuraAuthor Commented:
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
 
pius_babbunCommented:
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
 
NeoAshuraAuthor Commented:
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
 
NeoAshuraAuthor Commented:
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
 
NeoAshuraAuthor Commented:
You sir are a genius.

Thank you very much.
0
 
NeoAshuraAuthor Commented:
points awarded for contributing to dsmile.

full answer awarded 200 points to pius.
0
 
pius_babbunCommented:
thanks NeoAshura..great participating ....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.