473,738 Members | 6,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP MySQL query not displaying data

Hello!

I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.

Now, the problem that I am running into is that when I don't update the
primary key field (keyid) the page is running into the section where it
displays a message that the keyid already exists. This only happens
when the keyid on the previous page is not changed.

Upon troubleshooting the problem I found that the very first SELECT
statement does not seem to be returning any rows despite the fact that
the statement, when run on the SQL server, returns exactly one row. If
any could provide some assistance with this matter, I would be most
appreciative.

Regards;

Jayson Schultz

Code:
<?php
session_start() ;
header("Cache-control: private"); //IE 6 Fix

//continue if authenticated
if ($_SESSION['auth'] == 1)
{

//get variables from post
$keyid = $_POST['keyid'];
$username = $_POST['username'];
$corpid = $_POST['corpid'];
$usergroupname = $_POST['usergroupname'];
$oldkeyid = $_POST['oldkeyid'];
$oldcorpid = $_POST['oldcorpid'];
echo("Keyid: $keyid");

// Connect to MySQL
mysql_connect ("address.co m", "user", "pass")
or die ('I cannot connect to the database because: ' .
mysql_error());
//select database on server
mysql_select_db ("seniorproject ");

//SQL Statement
$sql = "SELECT keyid, corpid FROM users
WHERE keyid='".$keyid "'";

// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
echo mysql_result($r esult,0);

// Count number of matches and print to screen
$numrows = mysql_numrows( $result );
if ($numrows == 1)
{ echo(" SQL Query: $sql");
$result_ar = mysql_fetch_row ($result);
$result_ar = mysql_fetch_row ($result);
$dbkeyid = $result_ar['keyid'];
$dbcorpid = $result_ar['corpid'];
echo("<br> CorpID: $corpid <br>");
echo(" DBCorpid: $dbcorpid <br>");
echo(" DBKeyID: $dbkeyid <br>");
if($dbcorpid == $oldcorpid)
{
//If this condition is true, then KEYID has not changed. Execute
code

// Formulate the query

$sql = "UPDATE users
SET corpid = '".$corpid." ', username = '".$username."' ,
usergroup = '".$usergroupna me."', keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."' ";

// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );
// Formulate the query
$sql = "UPDATE accesslog
SET keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."' ";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );

// Formulate the query
$sql = "UPDATE aclusersdoors
SET user = '".$keyid."'
WHERE user = '".$oldkeyid."' ";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );

// Formulate the query
$sql = "UPDATE aclusersdoorgro ups
SET user = '".$keyid."'
WHERE user = '".$oldkeyid."' ";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );
//DB Modifcaiton Succeeded
echo("DB Modification Succeeded");
} //Terminates if from line 40

else{
$error = "New KeyID Already Exists";

die;

}//Terminates Else

}//Termiantes If
else{

//No Duplicate DoorID Exists... Can Proceed

//Check for valid door group
$sql = "SELECT * FROM usergroups
WHERE usergroup ='$usergroupnam e'";

// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );

// Count number of matches and print to screen
$numrows = mysql_numrows( $result );

if ($numrows == 1)
{
//DoorGroup is valid. Can Proceed.
// Formulate the query
echo("KeyID: $keyid");
$sql = "UPDATE users
SET corpid = '".$corpid." ', username = '".$username."' ,
usergroup = '".$usergroupna me."', keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."' ";
echo("Users: $sql");

// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );
// Formulate the query
$sql = "UPDATE accesslog
SET keyid = '".$keyid."'
WHERE keyid = '".$oldkeyid."' ";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error.");

// Formulate the query
$sql = "UPDATE aclusersdoors
SET user = '".$keyid."'
WHERE user = '".$oldkeyid."' ";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );

// Formulate the query
$sql = "UPDATE aclusersdoorgro ups
SET user = '".$keyid."'
WHERE user = '".$oldkeyid."' ";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( "General Error." );

echo("DB Modification Succeeded");

");
}
else{
$error = "Invalid Door Group";

die;
}
}
}
else{
echo("
//Display Restricted Area HTML Page
");
}

?>

Jul 17 '05 #1
2 3434
On 2005-03-25, jaysonsch <ja****@jaysons chultz.com> wrote:
Hello!

I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the new values are updated
in all corresponding tables (the function of the pages in question).
However, on the page that does the DB update, I also want to do some
checks on the data before performing the update.

[snip code]

Start scripts with:
ini_set('error_ reporting', E_ALL);
ini_set('displa y_errors', TRUE);

Append mysql_error() to your message in the die() function call.

Use mysql_real_esca pe_string before inputting it blindly in a query.
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #2


jaysonsch wrote:
Hello!

<snip>

Well, right off hand...

$sql = "SELECT keyid, corpid FROM users WHERE keyid='".$keyid . "'";
missing^
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2691
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ===================================
0
3944
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
6
1594
by: jfizer | last post by:
I'm trying to print out a table of mySQL data as XML. However, the performance I'm getting is REALY bad. Adding the header("Content-Type: $mime;charset=$charset"); statement triples the load time of the data for example. Can someone with more php experience then I look this over and tell me that I'm stupid and doing it wrong? define( "DATABASE_SERVER", "localhost" ); define( "DATABASE_USERNAME", "root" ); define( "DATABASE_PASSWORD", ""...
10
2645
by: Lloyd Harold | last post by:
I'm very new to PHP and attempting to put together a simple script for retrieving MySQL data of personal records. The MySQL table I'm using consists of: 0: id 1: name 2: location (an integer relating to a separate table of locations). 3: details
3
7403
by: printline | last post by:
Hello All I need a little help with a phph script to display some specific data from a mysql table. I have a mysql table with 4 columns and 10 rows. I want to display fx. data from row 4, 6, 8 and 10. I can display either the first row or all the rows using the below code: $row = mysql_fetch_array($result) or die(mysql_error()); echo $row. " - ". $row. " <img src=images/arlon.jpg /> ". $row. " - ". $row;
4
8156
by: foss | last post by:
HI all, I am able to upload the image as blob to mysql. but while displaying the image i cant display it properly . The code used for uploading image to mysql inserts data into mysql table.The uploading code is: MYSQL_CONNECT("localhost","root",""); mysql_select_db("sample"); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("INSERT INTO...
3
1678
by: thesmithman | last post by:
Well, actually, I'm sure it's my code... I have a basic nested query: $query="INSERT INTO items (blah, blah, blah) VALUES ('$blah', '$blahblah', NULL)"; $result=mysql_query($query) or die("There was an error: ". mysql_error()); if($result){ echo '<h1>Success</h1> <p>You have added this item to the database.</p>';
4
2348
by: bodhiSoma | last post by:
I've got this weird problem. I'm connecting to MySQL via PHP, querying a particular table, closing the connection then parsing and displaying the results. I then modify the table but when I reload the PHP page, the output does not reflect this change. Viz: -------- mysqlselect * from users; +----------+
9
5497
by: PI | last post by:
Hi Guys, I need some assistance with the following scenario please. I know this might be more of a MySQL post than a PHP one, but it is likely some developer has been here before and would be able to help out. I have some serialized data that I would like to store in a MySQL database. When viewed, the serialized data looks like this: O:4:\"cart\":4:{s:15:\"\0cart\0c_cart_id\";N;s:18:\"\0cart
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.