Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
Query failed: Unknown column 'uname' in 'where clause'
Finally, we found the cause of the problem! You do not have the fields set up (or not set up correctly) in your boyfight3 table. Can you set up the fields using DreamWeaver? How did you initially set up the database and the table?
 

barr08

macrumors 65816
Original poster
Aug 9, 2006
1,361
0
Boston, MA
I have a program that created the table:

http://nemo.mwd.hartford.edu/~bbarr/IIT310/Final/FinalPHPDB/createTable.php

Code:
<?php
	$server="localhost";
	$user="bbarr";
	$pass="******";
	$currentDB="bbarr";
	$testTable="boyfight3";

	$hookup=mysql_connect($server, $user, $pass) ;

	$dbNow=@mysql_select_db($currentDB, $hookup);
	
	$sql = "CREATE TABLE $testTable (ename varchar(30), email varchar(40), acnt varchar(4), cost varchar(10))";

	$result= @mysql_query($sql, $hookup) or die("Table not created." . mysql_error());

	if($result) {
		print "Table successfully created." ;
	}
?>
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
PHP:
$sql = "CREATE TABLE $testTable (ename varchar(30), email varchar(40), acnt varchar(4), cost varchar(10))";
If you look closely at the CREATE TABLE SQL command, you will notice that the field you created is called ename, not uname as you are trying to select. Change the select statement in your updateData.php file to:
PHP:
$query = "select * from $currentTable where ename = '$uname'";
and you will have to change it in the insert and update queries as well.
 

macfaninpdx

macrumors regular
Mar 6, 2007
198
0
Awesome! no errors, but it doesn't update the fields.
Now THAT problem does lie in the code. ;)
Here is your existing code (assuming you changed the uname to ename per above:
PHP:
else
{

    /* Update */
    $row = mysql_fetch_assoc($result);

    /* Get the old ID */
    $id = $row["id"];

    /* Create the update query */
    $update_query = "update $currentTable set ename = '$uname', email = '$email', acnt = '$acnt', cost = '$cost' where id = '$id'";

    $result = mysql_query($update_query);

}
But I'm afraid the bit about "Get the old ID" won't do anything, since you are not using an id field. So you can remove the $id line and it's comment. And you can remove the $row = ... bit as well. So the new else block should become:
PHP:
else
{
    /* Create the update query */
    $update_query = "update $currentTable set ename = '$uname', email = '$email', acnt = '$acnt', cost = '$cost' where ename = '$uname'";

    $result = mysql_query($update_query);

}
*Note the $update_query line was changed too.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.