Jump to content

Help with another code please


JpGemo
Go to solution Solved by JpGemo,

Recommended Posts

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 :)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by JpGemo
Link to comment
Share on other sites

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.