Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate data from one table in a database to another table in a different database not working
    primarykey
    data
    text
    <p>I'm trying to create a script that updates data from a table in one database to a table in another database. I'm self-made and my abilities are very limited. I'm sure there's a better way of doing this but it might be out of my reach. Anyway, this is how I'm trying to do it.</p> <p>The first document selects the data from the table I want to get the information from. It contains a link that allows me to select the row I want to copy. This link basically creates a form with the information I want to copy into the second database. The idea is that when I press submit, it sends the information to the second database and it updates the fields. </p> <p>The problem I'm having is that, even though it says it has executed the query successfully, it simply doesn't update the second database.</p> <p>Can anyone see why this is not working?</p> <p>These are the scripts I'm using:</p> <p>TEST-DISPLAY.php</p> <pre><code>&lt;?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="db1"; // Database name $tbl_name="table1"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); ?&gt; &lt;table width="400" border="0" cellspacing="1" cellpadding="0"&gt; &lt;tr&gt; &lt;td&gt; &lt;table width="400" border="1" cellspacing="0" cellpadding="3"&gt; &lt;tr&gt; &lt;td colspan="4"&gt;&lt;strong&gt;List data from mysql &lt;/strong&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="center"&gt;&lt;strong&gt;Uid&lt;/strong&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;strong&gt;User Name&lt;/strong&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;strong&gt;Password&lt;/strong&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;strong&gt;Email&lt;/strong&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php while($rows=mysql_fetch_array($result)){ ?&gt; &lt;tr&gt; &lt;td&gt;&lt;? echo $rows['uid']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['user']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['password']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;? echo $rows['email']; ?&gt;&lt;/td&gt; // link to update.php and send value of id &lt;td align="center"&gt;&lt;a href="http://soundsurgery.co.uk/main/TEST5/TEST-EDIT.php?uid=&lt;? echo $rows['uid']; ?&gt;"&gt;update&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php mysql_close(); ?&gt; </code></pre> <p>TEST-EDIT.php</p> <pre><code>&lt;?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="db1"; // Database name $tbl_name="table1"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $uid=$_GET['uid']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE uid='$uid'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?&gt; &lt;table width="400" border="0" cellspacing="1" cellpadding="0"&gt; &lt;tr&gt; &lt;form name="form1" method="post" action="TEST-EXEC.php"&gt; &lt;td&gt; &lt;table width="100%" border="0" cellspacing="1" cellpadding="0"&gt; &lt;tr&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td colspan="3"&gt;&lt;strong&gt;Update data in mysql&lt;/strong&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt; &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt; &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt; &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="center"&gt;&amp;nbsp;&lt;/td&gt; &lt;td align="center"&gt;&lt;strong&gt;Uid&lt;/strong&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;strong&gt;User Name&lt;/strong&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;strong&gt;Password&lt;/strong&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;strong&gt;Email&lt;/strong&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td align="center"&gt; &lt;input name="uid" type="text" id="uid" value="&lt;? echo $rows['uid']; ?&gt;"&gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;input name="user" type="text" id="user" value="&lt;? echo $rows['user']; ?&gt;"&gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;input name="password" type="text" id="password" value="&lt;? echo $rows['password']; ?&gt;" size="15"&gt; &lt;/td&gt; &lt;td&gt; &lt;input name="email" type="text" id="email" value="&lt;? echo $rows['email']; ?&gt;" size="15"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt; &lt;input name="uid" type="hidden" id="uid" value="&lt;? echo $rows['uid']; ?&gt;"&gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;input type="submit" name="Submit" value="Submit"&gt; &lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/form&gt; &lt;/tr&gt; &lt;/table&gt; &lt;?php // close connection mysql_close(); ?&gt; </code></pre> <p>TEST-EXEC.php</p> <pre><code>&lt;?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="db2"; // Database name $tbl_name="table2"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET uname='$user', password='$password', email='$email' WHERE uid='$uid'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "&lt;BR&gt;"; echo "&lt;a href='TEST-DISPLAY2.php'&gt;View result&lt;/a&gt;"; } else { echo "ERROR"; } ?&gt;&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>TEST-DISPLAY2.php is the same as TEST-DISPLAY.php with the difference that it displays results for the second table.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload