Please Help! With this code

Codes here !

Moderators: macek, egami, gesf

sharmel4u
New php-forum User
New php-forum User
Posts: 3
Joined: Mon May 13, 2013 8:58 am

Please Help! With this code

Postby sharmel4u » Mon May 13, 2013 9:02 am

Please what is wrong with this code, the Javascript alert is not running. When user tried to make booking twice there was no alert message and the data went into the database

Please Help!

HERE IS THE CODE (Not all)



/**********************************************************************************************
Check the DB for records...
**********************************************************************************************/

// check for the Id already in the database...USE COUNT TO COUNT ARROUND THE EMAIL FIELD IN THE TABLE.
$query = "SELECT COUNT(national_id) FROM bookings WHERE national_id = 'thisNational_idField'";
if ($debug) echo "<br>SQL STATEMENTbr>".$query."<br><br>";

// result from the select query assign it to result variable
$result = mysql_query($query) or die("Invalid query (login): " . mysql_error());

// fetch the row in the database i.e the row that is affected

$row = mysql_fetch_row($result);

// it should not be greater than zero else the email is already in the databse
if ($row[0] > 0)
{
// an email aleady exists in the database, because the row count > 0...
?>
<script type="text/javascript">
alert("The ID <?php echo $_POST['thisNational_idField']; ?> is already registered.");
history.back();
</script>
<?php
}
else

// this query insert those fields gotten from the form with the REQUEST method into the database (bookings table)
$sqlQuery = "INSERT INTO bookings (national_id , fname , mname , lname , company , title , address1 , address2 , city , country , postal_code , phone , serviceReq , date )
VALUES ('$thisNational_id' , '$thisFname' , '$thisMname' , '$thisLname' , '$thisCompany' , '$thisTitle' , '$thisAddress1' , '$thisAddress2' , '$thisCity' , '$thisCountry' , '$thisPostal_code' , '$thisPhone' , '$thisService_Req' , '$thisDate' )";

// then give the output of the query to the variable result. then use mysql-query() funtion to execute it
$result = mysql_query($sqlQuery) or die("Invalid query: " . mysql_error() . "<br><br>". $sqlQuery);

?>

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Please Help! With this code

Postby johnj » Tue May 14, 2013 6:06 am

try something like this

Code: Select all

<script type="text/javascript">
var nat_id = '<?php echo $_POST['thisNational_idField']; ?>';
alert("The ID "+nat_id +"  is already registered.");
history.back();
</script>


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest