-3

I am having a problem with sessions in php.

this is index.php

<form method="post" action="send.php">
No. HP Tujuan : <input type="text" name="nohp" value="+62"><br>
Pesan : <textarea name="msg"></textarea><br>
<input type="submit" name="submit" value="Kirim SMS">
</form>

and this send.php

<?php
mysql_connect("dbhost", "dbuser", "dbpass");
mysql_select_db("sms");

$noTujuan = $_POST['nohp'];
$message = $_POST['msg'];

$query = "INSERT INTO outbox (DestinationNumber, TextDecoded, CreatorID) VALUES ('$noTujuan', '$message', 'Gammu')";
$hasil = mysql_query($query);
if ($hasil) echo "SMS Success";
else echo "SMS Failed";

?>

I want to create a session, but I dont know how. I want send.php page to become accessible only if a user has already completed the form in index.php.

Alexis King
  • 43,109
  • 15
  • 131
  • 205
  • You don't need sessions to accomplish this. Simply verify if the variables of the form are set. `if (empty($_POST['nohp'])) { ehco "Please complete form"; }` or redirect them back to index.php. See http://stackoverflow.com/questions/15220704/how-to-detect-if-post-is-set – JConstantine Feb 11 '15 at 05:31

1 Answers1

0

solved, thanks guys

<?php
if (isset($_POST['nohp']) AND isset($_POST['msg']))
{
   $noTujuan=$_POST['nohp'];
   $message=$_POST['msg'];
}
else
{
   die("access this page from index.php");
}
  
if (!empty($noTujuan))
{
    echo "No. HP: $noTujuan <br /> Isi Pesan: $message";
}
else
{
   die(sorry, you must entry name");
}
?>