dflow Posted September 2, 2009 Share Posted September 2, 2009 im trying to update 2 tables the POST works the query is sound but the db is not updated :'( <?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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/ Share on other sites More sharing options...
mikesta707 Posted September 2, 2009 Share Posted September 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/#findComment-911027 Share on other sites More sharing options...
dflow Posted September 2, 2009 Author Share Posted September 2, 2009 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 ?!? Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/#findComment-911044 Share on other sites More sharing options...
mikesta707 Posted September 2, 2009 Share Posted September 2, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/#findComment-911047 Share on other sites More sharing options...
dflow Posted September 3, 2009 Author Share Posted September 3, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/#findComment-911500 Share on other sites More sharing options...
trq Posted September 3, 2009 Share Posted September 3, 2009 when i submit i see the value in the $print but instead of the value i get 0 Pardon? Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/#findComment-911510 Share on other sites More sharing options...
dflow Posted September 3, 2009 Author Share Posted September 3, 2009 when i submit i see the value in the $print but instead of the value i get 0 Pardon? the POSTED values are printed on screen but the value isnt updated for some reason and a 0 is echoed in the form text fields Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/#findComment-911520 Share on other sites More sharing options...
Mark Baker Posted September 3, 2009 Share Posted September 3, 2009 I didn't even know you could update two tables with a single update statement. Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/#findComment-911527 Share on other sites More sharing options...
dflow Posted September 3, 2009 Author Share Posted September 3, 2009 I didn't even know you could update two tables with a single update statement. yeah this query works fine what is wrong then with this script layout? Quote Link to comment https://forums.phpfreaks.com/topic/172857-no-idea-what-the-problem-is/#findComment-912052 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.