Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2003, 08:52 AM
Authorized User
 
Join Date: Jul 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default cannot check data provided by a form

I have a file which processes the data submitted by the form. I want to check whether the data submitted is identical to the data in mysql database so that if it is not the user corrects the form and submits it again. Here is the code which cannot check the data in submitted form:

<?php
global $HTTP_POST_VARS;
if (isset($HTTP_POST_VARS['mybutton'])) {
$Host = "***";
$DBName = "***";
$TableName = "patientsform";
$Link = mysql_connect ($Host, '***', '***');
if ($Link==false) {
echo mysql_errno().": ".mysql_error()."<BR>\n";
}
mysql_select_db ($DBName, $Link);
$Query1 = "SELECT Forename FROM patients WHERE Forename = {$HTTP_POST_VARS['forename']} AND Surname = {$HTTP_POST_VARS['surname']}";
//The query to check the data submitted
$Query = "INSERT INTO $TableName VALUES ('0', '{$HTTP_POST_VARS['forename']}')";
//The query to put the submitted data into the table

if (mysql_query ($Query1, $Link)) {
print "The query1 was successfully executed!<BR>\n";

if (mysql_query ($Query, $Link)) {
print "The query was successfully executed!<BR>\n";
}
else {
print "The query could not be executed!<BR>\n";
echo mysql_errno().": ".mysql_error()."<BR>\n";
}

}
else {
print "The query1 could not be executed!<BR>\n";
echo mysql_errno().": ".mysql_error()."<BR>\n";
}

mysql_close($Link);
} //end of isset function

else {
echo "you must have come here from somewhere else.\n";
}


 
Old August 6th, 2003, 11:06 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

You're still not quoting your database strings. Which will likely cause an SQL syntax error.

"SELECT Forename FROM patients WHERE Forename = '{$HTTP_POST_VARS['forename']}' AND Surname = '{$HTTP_POST_VARS['surname']}'";

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for Duplicate Records in Data Entry Form roznix Access VBA 5 June 7th, 2012 08:53 AM
Check whether a form is already loaded madhukp VB How-To 1 September 8th, 2004 11:34 PM
Cant seem to compile (small with source provided) noob1 JSP Basics 1 September 20th, 2003 03:55 AM
Can't check data from a form. (Like password) scifo Beginning PHP 3 August 7th, 2003 01:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.