JpGemo Posted September 11, 2014 Share Posted September 11, 2014 This code is to change the result in one of my tables but the result won't change This is the form to submit the values to the processing page <?php //connect include 'connect.php'; //head include 'head.php'; //colour table $form = $_POST['selform']; $sql = "SHOW TABLES FROM $db_name"; $result = mysqli_query($con,$sql); echo '<form id="form1" name="form1" method="post" action="/BYO/modifyproc.php">'; echo '<table width="75%" border="0">'; echo '<tr>'; echo '<td>Table</td>'; echo '<td>'; echo '<select name = "table" id = "table" >'; //list tables while ($row = mysqli_fetch_array($result)) { echo '<option>'.$row[0].'</option>'; } //formtable 2 echo '</select>'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td>Column</td>'; echo '<td><input name="column" type="text" id="column" size="50" value=""/></td>'; echo '</tr>'; echo '<tr>'; echo '<td>Result</td>'; echo '<td><input name="colour" type="text" id="colour" size="50" value=""/></td>'; echo '</tr>'; echo '<tr>'; echo '<td> </td>'; echo '<td><input type="submit" name="Submit" value="Register"/></td>'; echo '</tr>'; echo '</table>'; echo '</form>'; ?> This page receives the form data and update the table <?php //connect include 'connect.php'; //head include 'head.php'; //recieve posts $_POST["table"]; $_POST["column"]; $_POST["colour"]; //convert posts $tablename=$_POST["tablename"]; $column=$_POST["column"]; $colour=$_POST["colour"]; //add to table mysqli_query($con,"UPDATE $tablename SET $column='$colour'"); echo 'table', $_POST["table"]; echo 'column', $_POST["column"]; echo 'result', $_POST["colour"]; ?> All of the results echo to the page, and the page source doesn't show any incorrect values, but the table isn't updating with the new value Any suggestions would be great Quote Link to comment https://forums.phpfreaks.com/topic/290987-help-with-another-code-please/ Share on other sites More sharing options...
mac_gyver Posted September 11, 2014 Share Posted September 11, 2014 in your previous thread, it was suggested to use mysqli_error($con) to display query errors. what worked before, can work again. you would be getting a query error at or right after the $tablename portion of the query because you are using a non-existent $_POST variable to provide the value for the $tablename variable. you would also be getting a php undefined index error where you referenced that non-existent $_POST variable. Quote Link to comment https://forums.phpfreaks.com/topic/290987-help-with-another-code-please/#findComment-1490702 Share on other sites More sharing options...
JpGemo Posted September 11, 2014 Author Share Posted September 11, 2014 (edited) the $tablename is in the submission '<select name = "table" id = "table" >'; $_POST["table"]; $tablename=$_POST["tablename"]; mysqli_query($con,"UPDATE $tablename SET $column='$colour'"); echo 'table', $_POST["table"]; and the final echo, echo's the result I submit from the first form. Sorry, I see my error in this code Edited September 11, 2014 by JpGemo Quote Link to comment https://forums.phpfreaks.com/topic/290987-help-with-another-code-please/#findComment-1490708 Share on other sites More sharing options...
Solution JpGemo Posted September 11, 2014 Author Solution Share Posted September 11, 2014 Very sorry, the only error in the code was $tablename=$_POST["tablename"]; where it should of been $tablename=$_POST["table"]; once that was corrected, the script worked, sorry, still getting used to error checking PHP Quote Link to comment https://forums.phpfreaks.com/topic/290987-help-with-another-code-please/#findComment-1490710 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.