Jump to content

07960

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

07960's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi I have wrote some code which when executed, it updates something in a database. When it has done this, it displays the message "database successfully updated". What I am having an issue with, is though it does update the db fine, if I enter an invalid case id number, instead of saying "invalid id" it displays the same "database successfully updated" message. Can anyone tell me the correct format to use to display the message ? The code I am using is : if($idhtml) { $sql= "UPDATE problem SET resolved = 'resolved' where id=$idhtml"; $rs = mysql_query($sql,$conn) or die ("Could not execute SQL query"); } //if the above is succesful then display message if ($rs) {$msg = "Database Successfully updated!!!"; echo $msg;} mysql_close($conn); ?> The update works fine on the correct case ref, just want it to display an error message if an invalid case id is typed in..
  2. I finally resolved this. The query was wrong : $sql = "select * from supported where (serial='$serial') or (licence = '$licence' )"; [/php} Should be [code=php:0] $sql = "select * from supported where (serial='$serial') and (licence = '$licence' )"; Thanks for the support !
  3. Hi No it still doesnt work :-S This is the code with the correct code tags :-P This is the code for html form : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" > <html lang="en"> <head> <title>Checker</title> </head> <body style="color:green; background:black;"> This form displays whether the hardware or software is supported. <br><br> Please type the HARDWARE serial number or SOFTWARE licence number below.. <br><br> <!--php checkscript needs to be named supported.php --> <form action="supported.php" method="get"> HARDWARE SERIAL NUMBER : <br> <input type="text" name="serial"> <br><br> SOFTWARE LICENCE NUMBER : <br> <input type="text" name="licence"> <br><br> <input type="submit" value="Submit"> </form> </body> </html> and this is the (now edited) code on the php code : <?php $serial = $_GET['serial']; $licence = $_GET['licence']; $referer = $_SERVER['HTTP_REFERER']; # if either form field is empty return 1st page if( ( !$serial ) and ( !$licence ) ) { header( "Location:$referer" ); exit(); } #connect to MySQL $conn=@mysql_connect( "localhost", "root", "" ) or die( "Could not connect" ); #select the specified database $rs = @mysql_select_db( "assignment", $conn ) or die( "Could not select database" ); #create the query (select all from table "supported" where values match the inputted data) //$sql = "select * from supported where serial=\"$serial\" or licence = \"$licence\" "; $sql = "select * from supported where (serial='$serial') or (licence = '$licence' )"; #execute the query $rs = mysql_query( $sql, $conn ) or die( "Could not execute query" ); #get number of rows that match query $num = mysql_num_rows( $rs ); #if there is a match the query produces a message if( $num != 0 ) {$msg = "<h3>Product is supported</h3>"; } else { $msg = "<h3> Product is NOT supported</h3>";} // header( "Location:$referer" ); exit(); mysql_close($conn); ?> <html> <head> <title>Product Supported</title> </head> <body style="color:green; background:black;"> <?php echo( $msg ) ?> </body> </html> Its not throwing back any errors, its just saying everything is supported when it should be either supported or not.
  4. It does partially work. If I only fill in one field (as it should be) on the html form, it returns product supported. But If I fill in both fields on the previous html form (serial & licence) then it returns product not supported...
  5. Hi I figured on adding else like your script, but Im nor sure where the first { is meant to close ? so I did this :- if( $num != 0 ) { $msg = "<h3>Product is supported</h3>"; } else {$msg = "<h3> Product is NOT supported</h3>";} but now its displaying the 1st message on all items ! Where a bouts would I enter the error reporting ? ini_set('display_errors',1); error_reporting(-1);
  6. Hi Yes I have error reporting switched on. I have changed the code as you suggested to not include $msg1. But now it is displaying every product as not supported whether it is or it isnt. Is the issue round this part ? : if( $num != 0 ) { $msg = "<h3>Product is supported</h3>"; $msg = "<h3> Product is NOT supported</h3>"; } And if so, what would I put in its place ?
  7. Hi Im very new to this forum and also to PHP in general - its a summer topic covered at my uni. I am trying to create a simple form for uni, which, when you type in a serial number or licence number, it checks mysql, and if the licence/serial is in the db it displays "product supported" and if its not in the db it displays "product not supported" My script below is not working and automatically displays "product supported" even when its not. Could anyone please help and point me in the right direction ? //code// <?php $serial = $_GET['serial']; $licence = $_GET['licence']; $referer = $_SERVER['HTTP_REFERER']; # if either form field is empty return 1st page if( ( !$serial ) and ( !$licence ) ) { header( "Location:$referer" ); exit(); } #connect to MySQL $conn=@mysql_connect( "localhost", "root", "" ) or die( "Could not connect" ); #select the specified database $rs = @mysql_select_db( "assignment", $conn ) or die( "Could not select database" ); #create the query (select all from table "supported" where values match the inputted data) $sql = "select * from supported where serial=\"$serial\" or licence =( \"$licence\" )"; #execute the query $rs = mysql_query( $sql, $conn ) or die( "Could not execute query" ); #get number of rows that match query $num = mysql_num_rows( $rs ); #if there is a match the query produces a message if( $num != 0 ) { $msg = "<h3>Product is supported</h3>"; } else if ($num != ); { $msg1 = "<h3> Product is NOT supported</h3>"; } // header( "Location:$referer" ); exit(); mysql_close($conn); ?> <html> <head> <title>Product Supported</title> </head> <body style="color:green; background:black;"> <?php echo( $msg ), //getting error relating to this line else echo ( $msg1); ?> </body> </html> //code ends// Additional Details Im Getting the error between this point: <?php echo( $msg ), //getting error relating to this line else echo ( $msg1); ?> I ve tried adding the array from where I set the variable for $msg1 but still it just displays the 1st echo $msg and errors $msg1 Any help is much appreciated!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.