Changing data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
glenn
Forum Newbie
Posts: 18
Joined: Fri Apr 19, 2002 7:42 am
Location: London, England (UK)

Changing data

Post by glenn »

I have I script that when the user inputs a number it will go away and change another rows data, e.g. you enter 1234 and in the other row will change from 'no' to 'yes'. The problem is that the script i have made will let you input anything, even a empty filled it will come back with 'DONE' and not my error message saying that the number entered is not in the DB.

Where is the script i have been using :

$username = "USERNAME";
$password = "PASSWORD";
$database = "DATABASENAME";

$db = mysql_connect("localhost", "$username", "$password");

mysql_select_db("$database",$db);

$result = mysql_query("SELECT * from inputform",$db);

$QUERY01 = "update inputform set invoice='yes' where jobid='$button'";

while ($row = mysql_fetch_array($result)) $in_db[] = $row["jodid"];


if (in_array($button, $in_db)) {

if (mysql_db_query ($database, $QUERY01, $db)) {

print ("<BR><BR>Q1 DONE<BR><BR>");

}

} else { print ("Job Number Not In Database"); }

-----END OF SCRIPT----------
nahp
Forum Newbie
Posts: 7
Joined: Mon Apr 22, 2002 3:24 am

Post by nahp »

you could try this:

Code: Select all

if( is_int( $button ) )
&#123;
  $query = "update inputform set invoice='yes' where jobid " . $button ;
  mysql_query( $query ) or die( $query . "<br>" . mysql_error() ) ;
  if( mysql_affected_rows() == 0 )
  &#123;
    echo "no matching jobid" ;
  &#125;
&#125;
else
&#123;
  echo "invalid id<br>" ;
&#125;
glenn
Forum Newbie
Posts: 18
Joined: Fri Apr 19, 2002 7:42 am
Location: London, England (UK)

Post by glenn »

Thanks for the help.

Its sort of working, it prints "invalid id" whatever i input, even when i input a number in my db, but when i do input a number from my db it does change, but still prints invalia id.


but thanks iam looking into what the 'is_int' function can do

Glenn
glenn
Forum Newbie
Posts: 18
Joined: Fri Apr 19, 2002 7:42 am
Location: London, England (UK)

Post by glenn »

It's ok now thanks for the code nahp, I have changed the code and it now works 100%

Thanks Glenn
Post Reply