content management system - Don't want to repeat a rand after reloding page (PHP) -


i have created form should submit content in database. make random numberstring , when submit want content insert database. before submit random numbers repeated , got new one. how eliminate that?

<?php  include_once('../includes/connection.php');  $random = rand(1000, 2000)  $dedu = $pdo->prepare("update users set user_password ='$random'");  $password = $_post['password'];  $query = $pdo->prepare("select * users user_password = ?");  $query->bindvalue(1, $password);  $dedu->execute(); $query->execute(); $num = $query->rowcount();  if ($num == 1) {  if (isset($_post['title'], $_post['content'])) { $title = $_post['title']; $content = nl2br($_post['content']);  if (empty($title) or empty($content)) {  $error = 'all fields requried'; } else {   $query = $pdo->prepare('insert articles (article_title, article_content) values    (?, ?)');  $query->bindvalue(1, $title); $query->bindvalue(2, $content);   $query->execute();  $msg = 'you added following article!';   }  }      } else {  $error = 'incorrect details!'; }     ?>    <html>   <head>   <title>dwa</title>   <link rel="stylesheet" type="text/css" href="../assets/stylesheet.css"> </head>  <body>   <div class="container">    <a href="index.php" id="logo">cms</a>     <br />   <h4>add article</h4>  <?php if (isset($error)) { ?> <div class="error">   <small style="color:#aa0000;"><?php echo $error; ?></small>   </div>    <?php } ?>    <form action="test.php" method="post" autocomplete="off">   <input type="text" name="title" placeholder="title" /><br />   <textarea rows="15" cols="50"  placeholder="content" name="content"></textarea><br />   <input type="submit" value="add article" />   <input type="password" name="password" />    </form>         <?php if (isset($msg)) { ?>   <div class="msg">   <small style="color:orange"><?php echo $msg;?> <br /><h3>   <?php echo $title; ?></h3><h5><?php echo $content; ?></h5></small>   </div><?php } ?>       </div>   </body>    </html> 

not sure if understand correctly want achieve try putting

$random = rand(1000, 2000)

after

$query->execute();


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -