Jump to content

Recommended Posts

im trying to update 2 tables

the POST works

the query is sound

but the db is not updated  :'( :wtf::confused:

<?php require_once('../Connections/international.php'); ?>
<form action="<?php echo $update_tables_action; ?>" method="post" enctype="multipart/form-data" name="form2">
  <label>StatusID
  <input name="StatusID" type="text" id="StatusID" value="<?php echo $row_RsProposal['StatusID']; ?>">
  </label>
  <?php echo $row_RsProposal['StatusID']; ?>
  <p>
    <label>RequestID
    <input name="RequestID" type="text" id="RequestID" value="<?php echo $row_RsProposal['RequestID']; ?>">
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="button" id="button" value="Submit">
    </label>
  </p>
</form>

<?php
$StatusID = $_POST['StatusID'];
$ProposalID = $_GET['PropID'];
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("international", $con);
$query="UPDATE proposals, contact_form
     SET contact_form.StatusID = '$StatusID', proposals.StatusID= '$StatusID'
        WHERE proposals.RequestID = contact_form.RequestID
        AND proposals.ProposalID = '$ProposalID'";
print($query); die ;
$update_tables_action = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR);



mysql_close($con);


?>

Link to comment
https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/
Share on other sites

this

print($query); die ;
$update_tables_action = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR);

 

should be this

 

print($query) or die ;
$update_tables_action = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR);

 

you are exiting your script after you print the query, so it never actually runs

this

print($query); die ;
$update_tables_action = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR);

 

should be this

 

print($query) or die ;
$update_tables_action = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR);

 

you are exiting your script after you print the query, so it never actually runs

 

 

thanks

 

now the problem is that when i update and echo the value from the proposals table in the text field i get a 0 from nowhere ?!?

you're going to have to explain a little better or post some code. "get a 0 from nowhere" means nothing to me. Which value are you echoing? what text field?

 

ok here is the code i added some validation and redirect now when i submit i see the value in the $print but instead of the value i get 0, i use the dreamweaver recordset just for echoing the values in the text fields

here is the code

<?php require_once('../Connections/international.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_RsProposal = "-1";
if (isset($_GET['PropID'])) {
  $colname_RsProposal = $_GET['PropID'];
}
mysql_select_db($database_international, $international);
$query_RsProposal = sprintf("SELECT * FROM proposals WHERE ProposalID = %s", GetSQLValueString($colname_RsProposal, "int"));
$RsProposal = mysql_query($query_RsProposal, $international) or die(mysql_error());
$row_RsProposal = mysql_fetch_assoc($RsProposal);
$totalRows_RsProposal = mysql_num_rows($RsProposal);
?>
<head></head>
<body>

<form action="<?php echo $update_tables_action; ?>" method="post" enctype="multipart/form-data" name="form2">
  <label>StatusID
  <input name="StatusID" type="text" id="StatusID" value="<?php echo $row_RsProposal['StatusID']; ?>">
  </label>
  <?php echo $row_RsProposal['StatusID']; ?>
  <p>
    <label>RequestID
    <input name="RequestID" type="text" id="RequestID" value="<?php echo $row_RsProposal['RequestID']; ?>">
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="button" id="button" value="Submit">
    </label>
  </p>
</form>

</body>
<?php
$StatusID = $_POST['StatusID'];
$ProposalID = $_GET['PropID'];
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("international", $con);
$query="UPDATE proposals, contact_form
     SET contact_form.StatusID = '$StatusID', proposals.StatusID= '$StatusID'
        WHERE proposals.RequestID = contact_form.RequestID
        AND proposals.ProposalID = '$ProposalID'";
print($query); 


if (isset($_POST['Submit'])) {

$update_tables_action = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR);
header("Location: update_2tables.php?'.$ProposalID'");

}
else {
print ("no value entered");

}


mysql_close($con);



mysql_free_result($RsProposal);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.