Page 1 of 1

Updating Table With Information From A Form

Posted: Mon Apr 19, 2010 9:40 pm
by august
This is probably a really simple error, but I just can't work out where I'm going wrong, and hoping someone can help!


This script pulls lead information from MySQL, leads are searched for using TransferID which brings up the lead etc, the script at the top is for a calender selections box, just so you know ... this all seems to work fine, very basic atm:

Code: Select all


<script type="text/javascript" src="calendarDateInput.js">

</script>

<?php

include_once '../agentlogin/connect.php';
session_start();


if (isset($_SESSION['user']))
{
  $user=$_SESSION['user'];
}
else
{
 echo "<br><br><A href='../agentlogin/login.php'>Login</a>";
  exit;
}



?>

<?php
$transferid=@$_GET['transferid'] ;
$dminfo="SELECT * from debtmanagement WHERE transferid='$transferid'";
$dminfo2=mysql_query($dminfo) or die("could not get lead information!");
$dminfo3=mysql_fetch_array($dminfo2);


$rows_per_page = 1;
$sql = "SELECT * FROM debtmanagement WHERE repname='$user' LIMIT 0, 10" ;
$result = mysql_query($sql, $db);
$total_records = mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);
?>


<?php


if (!isset($screen))
  $screen = 0;
$start = $screen * $rows_per_page;
$sql = "SELECT * FROM debtmanagement WHERE repname='$user'";
$sql .= "LIMIT $start, $rows_per_page";
$result = mysql_query($sql, $db);
$rows = mysql_num_rows($result);
for ($i = 0; $i < $rows; $i++) {
  $description = mysql_result($result, $i, 0);
  
 
?>






<table>
<td>












<?php






echo "Search Transfer ID:";
?>


<form name="form" action="leads.php" method="get">
  <input type="text" name="transferid" size="4" />
  <input type="submit" name="Submit" value="Find" />
</form>
<br></td>


</td><tr>
<td>






<?php

echo "Transfer ID:<td> " . $dminfo3['transferid'] . "<br></td>";
?>

</td><tr>
<td>

<?php
echo "Rep Name:<td> " . $user . "</td><br><br>";  
?>
</td></tr>
</table>
<p>








<table align="center">
<td>
<?php
echo "<h2>Lead</h2>";
?>
</td>
<tr>
<td>
<?php

echo "" . $dminfo3['title'] . " ";
echo ""  . $dminfo3['firstname'] . " ";
echo ""  . $dminfo3['lastname'] . "";
?>
</td>



<tr>
<td>
<?php


echo "" . $dminfo3['address'] . "";
?>
</td>



<tr>
<td>
<?php

echo "" . $dminfo3['postcode'] . "";
?>
</td>



<tr>
<td>
<?php


echo "" . $dminfo3['homenumber'] . "<br>";
echo "" . $dminfo3['mobilenumber'] . ""; 
}
?>
<br />
<br />
</td>
</table>

<table align="center" valign="center">

<form name="form" action="updatelead.php" method="post">
<input type="hidden" name="transferid2" size="4" value="<?php echo "". $dminfo3['transferid'] . "";?>" />

<tr>
<td>
Notes:</td> <td> <textarea rows="5" cols="20" name="debtinfo">
 </textarea><br /><br />
  </td>
  <tr>
<td>Struggling:</td> <td> <input type="checkbox" name="struggling" size="4" />
  </td>
  <tr>
<td>




B&C Renewel:</td> <td><script>DateInput('orderdate', true, 'DD-MON-YYYY')</script><input type="hidden" name="bandc" onClick="alert(this.form.orderdate.value)">
</td>
  <tr>

<td>Car/Van Renewal:</td> <td><script>DateInput('orderdate', true, 'DD-MON-YYYY')</script><input type="hidden" name="carvaninsurance" onClick="alert(this.form.orderdate.value)">
</td>
  <tr>
<td>Utilities Quote:</td> <td><input type="checkbox" name="gaselectricquotes" size="4" />
  </td>
  <tr>
<td>Outcome:</td> <td><select name="outcome">
<option value="1">Blow Out</option>
<option value="2">Pitch And Miss</option>
<option value="3">Not Required Person</option>
<option value="4">Wrong Number</option>
<option value="5">Call Back Arranged</option>
<option value="6">Not In Debt</option> 
<option value="7">Already In Debt Management</option> 
<option value="8">Not Struggling / Not In Debt</option>
<option value="9">Sale</option></select>
  </td>
  <tr>
<td>Transfered To:</td> <td><select name="transferedto">
<option value="1">Baines and Ernst</option>
<option value="2">Debt Connect</option>
<option value="3">Debt Recycle</option>
<option value="4">Integrity</option>
<option value="5">Refresh</option></select>
</td>
  <tr>
<td>Agent:</td> <td><input type="text" name="agent" size="15" />
 </td><tr><td><td> <input type="submit" name="Submit" value="Update" />
</form>



</table>









The parser for this is:

Code: Select all

<?php


include_once '../agentlogin/connect.php';
session_start();


if (isset($_SESSION['user']))
{
  $repname=$_SESSION['user'];

$debtinfo=$_POST['debtinfo'];
$struggling=!empty($_POST["struggling"]) ? 'yes' : 'no';
$bandc=$_POST['bandc'];
$carvaninsurance=$_POST['carvaninsurance'];
$gaselectricquotes=!empty($_POST["gaselectricquote"]) ? 'yes' : 'no';
$outcome=$_POST['outcome'];
$transferedto=$_POST['transferedto'];
$agent=$_POST['agent'];
$transferid2=$_POST['transferid2'];


  $updatelead="update debtmanagement set `$repname`,`$debtinfo`,`$struggling`,`$bandc`,`$carvaninsurance`,`$gaselectricquotes`,`$outcome`,`$transferedto,`$agent` WHERE transferid='$transferid2'";
  mysql_query($updatelead) or die("Could not update lead");
 echo "You have successfully updated the lead. <br><A href='leads.php'>Go Back</a>";

}
	?>
Each time I press update on the first page, I get "Could Not Update Lead" on the parser page. I have check my tables, twiddled with my coded, tried various 'update debtmanagement set ' , INSERT, etc etc... but that doesn't seem to change a thing.

I know its probably something I'm overlooking, my limited knowledge of PHP frustrates me!

Hope someone can help!

PS: I know its not a game, but this is where I learnt PHP so I'd imagine the way I've wrote it would be more easily troubleshooted here!

Re: Updating Table With Information From A Form

Posted: Tue Apr 20, 2010 1:18 pm
by OldRod

Code: Select all

$updatelead="update debtmanagement set `$repname`,`$debtinfo`,`$struggling`,`$bandc`,`$carvaninsurance`,`$gaselectricquotes`,`$outcome`,`$transferedto,`$agent` WHERE transferid='$transferid2'";
Don't you need to provide a value you are setting those fields to? Like "set `$repname`=somevariable", etc.?

Re: Updating Table With Information From A Form

Posted: Tue Apr 20, 2010 9:48 pm
by Torniquet
OldRod wrote:

Code: Select all

$updatelead="update debtmanagement set `$repname`,`$debtinfo`,`$struggling`,`$bandc`,`$carvaninsurance`,`$gaselectricquotes`,`$outcome`,`$transferedto,`$agent` WHERE transferid='$transferid2'";
Don't you need to provide a value you are setting those fields to? Like "set `$repname`=somevariable", etc.?
yeah, you need to tell mysql what field to update, and what to update it to.

Code: Select all

$sql = "UPDATE `table` SET `fieldA` = $varA', `fieldB` = '$varB' WHERE xny='$a2z' ";