Values on browser are different as compared to the ones stored in database php
Values on browser are different as compared to the ones stored in database php
i generated a random number to use as a tracker but the random number generated is not the same as the one stored in the database.
Php Code:
<div class="form-group">
<label for="name-card" class="text-success"><strong><?php echo $NUMEROENVIO; ?></strong></label>
<?php
$qryEmpresa = mysql_query("SELECT * FROM company");
while($row = mysql_fetch_array($qryEmpresa)) {
$pre = $row["prefijo"];
$cons = $row["cons_no"];
}
mysql_free_result($qryEmpresa);
$pa=mysql_query("SELECT MAX(cons_no)as maximo FROM c_tracking");
if($row=mysql_fetch_array($pa)){
if($row['maximo']==NULL){
$cons_no=''.$cons.'';
}else{
$cons_no='100'.RAND(0,999999.99);
}
}
?>
how do i store the same random number generated to my database and not have two different numbers? Thank you!
@ArchitGoyal so this random number (IAS-10062438) for instance is generated on the text field but when i look into my db it is stored as (IAS-100523345). Another is (IAS-10043365) but it stored in my db as (IAS-100444702) it goes on and on.
– JONATHAN OKINE
Jun 29 at 18:37
Not sure I follow your logic. You are retrieving
MAX(cons_no)
from the DB. If nothing is found, if($row['maximo']==NULL)
, you use $cons
which comes from the company
table. If a row is found, you then generate a new random number, $cons_no='100'.RAND(0,999999.99);
. Should be: Use PHP to generate a random number. Store it in a variable. Save that number to the DB. Use that same number to display it to the user.– waterloomatt
Jun 29 at 19:14
MAX(cons_no)
if($row['maximo']==NULL)
$cons
company
$cons_no='100'.RAND(0,999999.99);
WARNING: If you're just learning PHP, please, do not learn the obsolete
mysql_query
interface. It's awful and has been removed in PHP 7. A replacement like PDO is not hard to learn and a guide like PHP The Right Way helps explain best practices. Make sure your user parameters are properly escaped or you will end up with severe SQL injection bugs.– tadman
Jun 29 at 19:53
mysql_query
This code never saves, it only generates.
– tadman
Jun 29 at 19:54
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you give multiple sample of the number generated and number entered to the db
– Archit Goyal
Jun 29 at 17:45