Jump to content

Checking Input


Ratneer

Recommended Posts

So basically I have a site, and on that site, I have a page that submits a form and updates a database. I have it set up so that someone can enter in Multiple values into a textarea, one on each line, and it will submit each of those values as a new row in the database, but for the life of me, I cannot figure out how to check those values against the actual users.

 

It is basically a point system, where the staff can award points users of the site. But at the moment, a Staff member could enter in Jibberish, and it would insert that into the database, but I want it to check my users table to make sure the user exists before it inserts it into the database.

 

here is my code:

<?php
include 'global.php';

echo $headersidebar;


if ($_COOKIE['access'] == $accessstaff)
{





if(count($_POST))
{



$array = preg_split('/(\r?\n)+/', $_POST['studentname']);
foreach($array as $students)
   {
   
   $statusmsg = '<center><span style="background: #A6FF9E;">You have successfully submitted points to the database.</span></center>';
   
   mysql_query("INSERT INTO points (giver, receiver, points, category, reason, date, status) VALUES ('{$_COOKIE['username']}', '{$students}', '{$_POST['pointamt']}', '{$_POST['pointcat']}', '{$_POST['pointreason']}', '{$date}', 'Validating')");
   }
}


$addpointspage = $statusmsg . '



<form action="submit_points.php" method="post">



<table class="table" >



<tr>



<td colspan="10">



<h1><strong><center>Submit Points</center></strong></h1>



</td>



</tr>



<tr>



<td colspan="10" rowspan="100">



<center>Please remember to follow the house point limits when submitting house points.</center>



</td>



</tr>



</table>






<table class="table">






<tr>



<td style="width: 15%;" valign="top">



Student Name:<br> <span style="font-size: 60%;">(List as many as you want; One per Line)</span>



</td>



<td colspan="10">



<center><textarea name="studentname" cols="60" rows="10"></textarea></center>



</td>



</tr>






<tr>



<td style="width: 15%;" valign="top">



Amount of Points:



</td>



<td>



<input style="position: relative; left: 16px;" type="text" size="15" name="pointamt" />



</td>



<td>



Do not put anything that is not a number into this box.



</td>



</tr>






<tr>



<td style="width: 15%;" valign="top">



Point Category:



</td>



<td colspan="10">



<select name="pointcat" style="position: relative; left: 16px;">






<option SELECTED value="">-------</option>



<option>Class Work</option>



<option>Class Exam</option>



<option>Extra Work</option>



<option>Contests</option>



<option>Teacher\'s Assistant</option>



<option>Negative Points</option>






</select>



</td>



</tr>






<tr>



<td style="width: 15%;" valign="top">



Reason:



</td>



<td colspan="10">



<input style="position: relative; left: 16px;" name="pointreason" type="text" size="80" />



</td>



</tr>






<tr>



<td>



</td>



<td colspan="10">



<input style="position: relative; left: 16px;" type="submit" value="Submit Points" />



</td>



</tr>















</table



</form>



';

}

elseif (1==1)
{
$addpointspage = $accessdenied;
}



echo



'





<!-- start content -->





<div id="content">







<div class="post">









<div class="entry">











<p><strong>' . $addpointspage . '</p>











<p class="links">' . $addpointslink . '</p>









</div>







</div>





</div>





<!-- end content -->





<div style="clear: both;"> </div>



</div>



<!-- end page -->
</div>';








echo $footer;





?>

 

 

I am fairly new to PHP, so I would appreciate any help someone could give me; I am not too good with arrays and such, so this one has got me stumped.

Link to comment
Share on other sites

I tried run a SELECT query to return the row of my users from my database, and then if something like if ($row['username'] != $array['inputtedusername']) but it didn't do anything, I guess I did something wrong with the array. Someone Please help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.