1 Replies - 821 Views - Last Post: 04 June 2014 - 04:15 AM Rate Topic: -----

#1 priyankaa121   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 23-May 14

Validating the form from redirecting it to next page in php

Posted 04 June 2014 - 01:55 AM

I have created a form where user enters a number and month. When the number and month entered is not stored in database it should display a alert box saying details is not valid. iF if the details matches it as to redirect it to next page.My code redirects to next page if the number matches and redirecting page(modifypay3.php) appears to be blank. Without the form. what is problem with the code.


username = "root";
$password = "";
$hostname = "localhost"; 
$db = "anthonys";

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
mysql_select_db($db,$dbhandle) or die('cannot select db');


   mysql_query("UPDATE payment SET uid='$uid',month ='$month', date='$date', amount='$amount' WHERE uid='$uid' and month='$month'") or die(mysql_error()); 

echo "<script>alert('Record Updated!!')</script>";

 $myData= mysql_query("SELECT * FROM payment where uid='$uid' and month='$month'")or die(mysql_error());

while($record = mysql_fetch_assoc($myData)) 



<section id="sheet"  style="background-color: Transparent;">

<div id="content_inner">

<header id="header_inner">St. Anthony's Parish Education Fund
<br /><b style="font-size:15px;">Bangalore 560 095</b><br /><img src="images/line1.jpg" alt="" /></header>

<div id="col2">
<h2>PAYMENT RECEIPT</h2><br /><br />
<table border="0px" style="border-collapse:collapse; width:810px;" align="center">

<form name="XIForm" id="XIForm" method="post" action="modifypay3.php">
<span style="float:right; width:500px;margin-top:-55px;">

<label type="text" name="uid" maxlength="50" size="30" class="label" >Membership No</label><br />
<input type="text" name="uid" value="<?php echo $record['uid'];?>"readonly><br /><br /></span>

<label type="text" name="month" maxlength="50" size="30" class="label">Month</label><br />
<input type="text" name="month"  class="input" size="40" value="<?php echo $record['month']; ?>"> <br /><br />

<label type="text" name="date" maxlength="50" size="30" class="label">Date</label><br />

<input type="text" name="date" class="input" style="width:370px;"  value="<?php echo $record['date']; ?>"><br /><br />

<label type="text" name="amount" maxlength="50" size="30" class="label">Amount Paid</label><br />
<input type="text" name="amount" class="input" size="39" value="<?php echo $record['amount']; ?>"> <br /><br />

<input type=hidden name=hidden value="<?php echo $record['uid'];?>"><br/><br/>

 <input type="submit" name="submit" value="UPDATE" class="button" />


<?php }?>



<div id="col1" align="center"><br />
    <form method="post" action="">
        <label type="text" name="name" maxlength="50" size="30" class="label">Enter the Membership Number which You want to edit</label><br />
        <input type="text" name='uid' placeholder="enter Membership Number" class="input" size="40"/><br />
        <span class="field">(* Required field)</span><br /><br />
        <label type="text" name="month" maxlength="50" size="30" class="label">Select Month in which u want to edit</label><br />
        <select name="month"  placeholder="" class="input"  style="width: 380px;" >
            <option value="January">January</option>
            <option value="February">February</option>
            <option value="March">March</option>
            <option value="April">April</option>
            <option value="May">May</option>
            <option value="June">June</option>
            <option value="July">July</option>
            <option value="August">August</option>
            <option value="September">September</option>
            <option value="October">October</option>
            <option value="November">November</option>
            <option value="December">December</option>
        <input type="submit" name="submit" value="SUBMIT" class="button"><br /><br /><br /><br />


if(isset($_POST['submit'])) {
    $uid= $_POST['uid'];

    if( ! ctype_alnum($uid) )
        die('invalid id');

    $query = "SELECT uid,month FROM `payment` WHERE uid ='$uid' and month='$month'";
    $run = mysql_query($query);

    if(mysql_num_rows($run)==1) {
        echo "<script>window.open('modifypay3.php?uid=".$uid."','_self')</script>";
    } else {
        echo "<script>alert('Membership No is Invalid!')</script>";

Is This A Good Question/Topic? 0
  • +

Replies To: Validating the form from redirecting it to next page in php

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2556
  • View blog
  • Posts: 10,266
  • Joined: 03-December 12

Re: Validating the form from redirecting it to next page in php

Posted 04 June 2014 - 04:15 AM

Looks like you have it set to only show the form while there is a record, but there is no way to show the record. You need to pass the variable to the new form, in a get or post array. Then you take the passed value to get the appropriate record for display.

Try echoing the variables you are attempting to pass to ensure you are getting what you expect.

Also, you will need prepared statements as this looks to be a production site. And please update your mysql_ code.

This post has been edited by astonecipher: 04 June 2014 - 04:18 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1