PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old September 2nd, 2004, 03:01 AM
franches franches is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 16 franches User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy invalid data should not be accepted

I really need help with this code. The output is ok when the id is valid but when the id is not valid it did display the message but the data is still inserted into the database and also the station entered is deleted from the combo box list which should not happen.

hope you'll help me with this. this is what i'm assigned to do. i'm really new to php and esp. with programming but i really want to learn. i really don't know where in the code went wrong or maybe i still need some code for this.

i would really apprecialte it someone who could help me with the code. thanks.

here's the code for borrowingform.php


quote:





<?php

$db=mysql_connect("localhost","root");

mysql_select_db("mydatabase",$db);

if(isset($submit))
{ // Probably should be $_POST['submit']
if(isset($PIC))
{

//set up the query
$query ='SELECT * FROM staff WHERE PIC="' . $PIC . '"';

//run the query and get the number of affected rows
$result = mysql_query($query) or die('error making query: ' . mysql_error());
/*$affected_rows = mysql_num_rows($result); Useless var. */

//if there's exactly no result, the user is not validated.
if(mysql_num_rows($result) == 0)
{
print 'PIN number not valid';
}
}
if(isset($Station))
{

//set up the query
$query = 'DELETE FROM workstation WHERE station="' . $Station . '"';
mysql_query($query) or die('error making query: ' . mysql_error()); // Let's stick to one way of querying.
}
$query = 'INSERT INTO borrow(PIC, Station) VALUES ("' . $PIC . '", "' . $Station . '")';
mysql_query($query) or die('error making query: ' . mysql_error()); // This does not have to be assigned to a var since it returns true/false if anything

}
?>

<table boarder=0><tr><td align=right>
<font size=4 face=arial color=#330066>
<form method="post" action="<?php echo $PHP_SELF?>">
Borrower: <input type="text" name="PIC"><Br><Br>
Work Station:
<?
include ("stations.inc");
?>
<br><br>
<input type="submit" name="submit" value="add to database">
</form>
</td></tr></table>


here's the code for stations.inc



quote:

<?php
$db=mysql_connect("localhost","root");
mysql_select_db("mydatabase",$db);
$tablename = "workstation";
$query = "SELECT * FROM $tablename order by station ASC";
$result = mysql_query($query) or die(mysql_error());

echo "<select name=\"Station\" size=\"1\">";
while($row = mysql_fetch_array($result))
{
echo "<option>".$row['station'];
}
echo "</select>";

?>


Reply With Quote
  #2  
Old September 2nd, 2004, 07:58 AM
franches franches is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 16 franches User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
no need to answer this. it's done. thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > invalid data should not be accepted


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway