PHP - How To Check If Javascript Is Diabled?
I'd like to do a check if JavaScript is disabled in the user's browser, and based on that I'd like to do a if statement. How can I do that?
I appreciate any suggestions. Thanks. Similar TutorialsI have a javascript function that shows an alert message, but I only want it to show after a certain check is done by PHP/Mysql first. I can't get it to work, so I'm sure I'm doing something wrong. My code is below. I'm guessing I can't have Javascript inside PHP? If that's true, how would I go about doing something like this? Code: [Select] <?php $query = "SELECT paid from users WHERE userid={$_GET['userid']}"; $result = mysql_query($query, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { $paidinfo = mysql_fetch_array($result); if ($paidinfo['paid'] == "no") { ?> <SCRIPT LANGUAGE="JavaScript"> window.onload=deadBeat; </script> <?php } else { //do nothing } } ?> This is the function... Code: [Select] <SCRIPT LANGUAGE="JavaScript"> function deadBeat() { alert("You still owe money for your entry fee to this pool. Please pay Gary soon.") } </SCRIPT> I wasn't sure where to post this so I apologize if this is the wrong forum. I have a php page with over 50 numerical inputs on a form. A lot of the inputs are used to get data out of the mysql database so I want to be safe from sql injection. Is it safe to use a javascript onsubmit function that will not allow the form to be submitted if there is any non numeric data entered by the user? I've already written the function & it works fine but I'm not sure how much protection it gives me. Any feedback welcome. Hello their, I'm wanting to use PHP to check to see if a username and password match a remote RDP server. The reason I ask is because I want to verify that the information the user is giving is correct. I'm looking though LDAP but I have no idea what I'm looking for. To recap, I would like to login to a RDP server and return a result based on if it completed. Thank-you for reading Paul P.S Sorry for the bad English, I seemed to forgot how to spell some words and have had to replace them with longer sentences Suppose i have a table with around 10 entries in which one column contains the id and the second column contains a checkbox... If a checkbox a selected and the button (below the table) is pressed then i want to delete the columns corresponding the checked checkboxes.... I am not getting how sgould i pass the get variable on the link of the button??? -Pranshu Agrawal pranshu.a.11@gmail.com Hello, I have created a little voting script for my site. The insertion code into the MySQL databse when they vote is very simple: $ipaddress = addslashes($_POST['ipaddress']); $theid = addslashes($_POST['theid']); $gamert = addslashes($_POST['gamert']); $serveron = addslashes($_POST['serveron']); $db = mysql_connect("localhost", "username", "password"); mysql_select_db("thedb",$db); mysql_query ("INSERT INTO voting (theid,ipaddress,gamert,serveron2) VALUES ('$theid','$ipaddress','$gamert','$serveron') "); Obviously I only want them to be able to vote once. What is the best way to do a check of the IPs already in the database and check against theirs before submitting? Thanks. I am unable to execute mysql_num_rows properly in this program. Code: [Select] <?php $link=mysql_connect("localhost","root",""); $db = mysql_select_db("myDB",$link); $result = mysql_query("SELECT * FROM jobs WHERE jobType=abc"); $num = mysql_num_rows($result); echo "Found $num records"; ?> error is mysql_num_rows() expects parameter 1 to be resource ok so i can get this to work so i want to check if there is a video on inside my db if there is no video and nothing happens but if there is i want it to echo video Code: [Select] <?php if($video == ""){ }else{ echo "VIDEO"; } ?> Hi, I'd like to know what the most efficient code is for checking the first 2 digits of a string. eg a strings first 2 digits must equal '07' thanks, hi, im can someone help me out with a file upload? i want to say if filename=abc.csv then do abc else do nothing Problem - application produces MD5 PWs which are uppercase, code checks lowercase. Question- How to use uppercase check? Code: [Select] function checkPwd($x,$y) { //Checks if strings are empty if(empty($x) || empty($y) ) { //Strings were empty return false; } else if(strlen($x) < 4 || strlen($y) < 4) { //String length too short return false; } else if(strcmp($x,$y) != 0) { //Strings do not match return false; } else { //Password Determined valid return true; } } Question 2: Do I have to change it anywhere else, like PW generation? Code: [Select] function GenPwd($length = 7) { $password = ""; $possible = "0123456789bcdfghjkmnpqrstvwxyz"; //no vowels $i = 0; while ($i < $length) { $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); if (!strstr($password, $char)) { $password .= $char; $i++; } } return $password; } function GenKey($length = 7) { $password = ""; $possible = "0123456789abcdefghijkmnopqrstuvwxyz"; $i = 0; while ($i < $length) { $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); if (!strstr($password, $char)) { $password .= $char; $i++; } } return $password; } Thank you for reading how do i echo "checked=checked" for a checkbox? here is what i have: Code: [Select] <input type='checkbox' name='ip_automatic_login' id='ip_automatic_login' value='1' if($IPCheck == true) {/"checked=checked/" } /> this code will be echoed! Hello PHP World, I don't have access to the database yet for the project I am working on so I created a work around until I get full access to the mysql database. I Code: [Select] <?php $xml_file = "affiliate.xml"; // OPEN XML FILE ###################################################### if(!$xml=simplexml_load_file($xml_file)){ trigger_error('Error reading XML file',E_affiliate_ERROR); } if(!empty($_GET['add'])){ $u_name = stripslashes($_POST['name']); $u_company = stripslashes($_POST['company']); $u_address = stripslashes($_POST['address']); $u_city = stripslashes($_POST['city']); $u_state = stripslashes($_POST['state']); $u_phone = stripslashes($_POST['phone']); $u_email = stripslashes($_POST['email']); $u_desc = stripslashes($_POST['description']); $u_region = stripslashes($_POST['region']); // Generate new (appended) ID foreach($xml as $affiliate){ $last_id = $affiliate->uid; } $id = $last_id+1; // Add node $x = $xml->addChild("affiliate"); $x->addChild("uid",$id); $x->addChild("name",$u_name); $x->addChild("company",$u_company); $x->addChild("address",$u_address); $x->addChild("city",$u_city); $x->addChild("state",$u_state); $x->addChild("phone",$u_phone); $x->addChild("email",$u_email); $x->addChild("description",$u_desc); $x->addChild("region",$u_region); $xml->asXML($xml_file); } ?> html form Code: [Select] <br /> <br /> <h1>Affiliate </h1> <form name="xml_writing" method="post" action="?add=t"> <table width="393"> <tr><td width="56"> Name:<br /></td><td width="206"> <input type="text" name="name" width="150"/></td> <td>Region:</td> <td><select name="region" value="options"> <option value="resellerNE">NorthEast</option> <option value="resellerSE">SouthEast</option> <option value="resellerC">Central</option> <option value="resellerNE">NorthWest</option> <option value="resellerNE">SouthWest</option> <option value="resellerNE">International</option> </select></td> </tr> <tr> <td> Company:<br /></td><td> <input type="text" name="company" width="150" /></td> </tr> <tr><td> Address:<br /></td><td> <input type="text" name="address" width="150"/></td> </tr> <tr><td height="45"> City:<br /></td><td> <input type="text" name="city" width="150"/></td> <tr><td> State:<br /></td><td> <input type="text" name="state" width="150"/></td> <tr><td> Phone:<br /></td><td> <input type="text" name="phone" width="150"/></td> <tr><td> Email:<br /></td><td> <input type="text" name="email" width="150"/></td> </tr> <tr><td colspan="2"> Short description of yourself, your practice, your services, and other information of interest to potential clients or collaborators.<br /></td> <tr><td colspan="2"> <textarea name="description" style="width: 406px; height: 136px;"></textarea></td> </tr> <tr><td></td><td> <input type="submit" value="Submit" /></td> </tr> </table></form> What I am trying to do is have on submit check against the email node in the xml file to see if email exist. if exist string already a member else insert. if you can help with code or point to something that will help. "Everyone needs a mentor to lead them into success." Quote by Shelby Poston Hi, I have no knowledge about coding. But I have very little knowledge in creating or editing simple web pages. How do you create a web page that checks user account name and password of a website in batch mode to see if they are valid. For example: I can put account details in an empty form in a "username:password" format and submit to check if they are valid. The "username:password" will be checked one by one in a fashion of "http://username:password@www.(name of site).com". It basically connects to the site's URL with a "username:password@" attached to it and see if it redirects to either "Members Area" or "Access Denied". Example: I put TestUser:TestPass in the form and submit. Now it will connect to "http://TestUser:TestPass@www.(name of site).com" When the checking is done a result page will come showing the valid ones. How can all this be done? Thanks Hey guys, I've set up a database with a login and logout script for my site.. There is a TINYINT value called admin and it either equals 1 or 0 depending on whether the user is an admin or not.. The registration script works perfectly to create the table value and the login script works fine for the site.. The question I had was if I wanted to add a link to the bottom of every page that said: Go to Administration Panel and make it only viewable by ADMINS I figured this little script would work.. Here would be the end of the page: Code: [Select] <br /> <center>Copyright © 2010 <a href="http://www.website.com">www.WEBSITE.com</a></center> <?php include('includes/start_admincheck.php'); ?> <center><a href="<?php echo $homedir .'admin.php'; ?>">Go to Administration Panel</a></center> <?php include('includes/end_admincheck.php'); ?> </body> </html> Inside start_admincheck.php I have: (NOTE: $cUsername refers to a setcookie and $cAdmin does as well.. They are defined on my Variable page included at the top.) Code: [Select] <?php include('variables/variables.php'); ?> <?php mysql_connect("$mysql_hostname", "$mysql_username", "$mysql_password") or die(mysql_error()); mysql_select_db("$mysql_database") or die(mysql_error()); if(isset($cUsername)) { $check = mysql_query("SELECT * FROM users WHERE username = '$cUsername'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if (($cAdmin == 1) && ($info['admin'] == 1)) { ?> And this is the end_admincheck.php Code: [Select] <?php include('variables/variables.php'); ?> <?php } else die(); } } else die(); ?> ?> I get this Parse error thrown at the bottom of the page: Code: [Select] Parse error: syntax error, unexpected $end in /*******/includes/start_admincheck.php on line 15 Naturally I would checkout line 15 in start_admincheck.php, but normally when I get an $end error it is the last line of the code and leaves me lost.. Something I'm missing guys? As always, thanks in advance I am new to PHP. I developed this class, I wonder if there's anything wrong or that I can improve. I could not test it because I'm in school. Thanks in advance. Code: [Select] <? class user { var $userID, $schoolID, $userName, $userPass, $dbHost, $dbUser, $dbName, $dbPass, $dbUserTable; $dbSchoolTable; function dbInfo() { $this->dbHost = 'localhost'; $this->dbUser = ''; $this->dbName = ''; $this->dbPass = ''; $this->dbUserTable = ''; $this->dbSchoolTable = ''; } function registerUser($userName, $userPass) { $dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass); if(!$dbLink) die("Could not connect to database: " . mysql_error()); mysql_select_db($this->dbName); $query = "INSERT INTO $this->dbUserTable VALUES (NULL, \"$userName\", \"$userPass\")"; $result = mysql_query($query); if(!$result) { echo "Fail."; } else { $this->userID = mysql_insert_id(); } mysql_close($dbLink); $this->userName = $userName; $this->userPass = $userPass; } function registerSchool($schoolName) { $dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass); if(!$dbLink) die("Could not connect to database: " . mysql_error()); mysql_select_db($this->dbName); $query = "INSERT INTO $this->dbSchoolTable VALUES (NULL, \"$schoolName\")"; $result = mysql_query($query); if(!$result) { echo "Fail."; } else { $this->schoolID = mysql_insert_id(); } mysql_close($dbLink); $this->schoolName = $schoolName; } function userLogin() { $dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass); if(!$dbLink) die("Could not connect to database: " . mysql_error()); mysql_select_db($this->dbName); $query = "SELECT * FROM $this->dbUserTable WHERE userName = \"$this->userName\" AND userPass = \"$this->userPass\" LIMIT 1"; $result = mysql_query($query); if(!$result) { echo "Fail."; } else { while($row = mysql_fetch_array($result)) { session_start(); $_SESSION['userID'] = $row['userID']; session_write_close(); } } mysql_close($dbLink); } function changePass($newPass) { $dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass); if(!$dbLink) die("Could not connect to database: " . mysql_error()); mysql_select_db($this->dbName); $query = "SELECT * FROM $this->dbUserTable WHERE userName = \"$this->userName\" LIMIT 1"; $result = mysql_query($query); if(!$result) { echo "Fail."; } else { $query = "UPDATE $this->dbUserTable SET userPass = \"$newPass\" WHERE userName = \"$this->userName\""; $result = mysql_query($query); if(!$result) { echo "Fail"; } else { $this->userPass = $newPass; } } mysql_close($dbLink); } } ?> I am writing a script, but keep getting a 500 error page. I've tried various tricks to isolate the problem to no avail. My old system would always send me an email to report the error, but since my new box, it isn't working The major change from my old setup is that I am now using fast CGI I rememeber that there is a log that records errors but I havn't been able to find it if there is one... Or I am looking in the wrong places. Can anyone nudge me in the right direction on this? Thanks, David could anyone please help me with the code which is i have already displayed data from two table as a drop-down list and a multi select list but now i need to select one from drop-down list and one or more from multi select list the insert into another database table. here is the coding. it shows no error message( blank page after submit) and nothing inserted on the take able <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } error_reporting(E_ALL); ini_set('display_errors', 1); mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]" multiple="multiple" size="10">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">' . $row['CourseName'] . '</option>'; } echo '</select>'; // ---------------- $result = mysql_query("SELECT * FROM student") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name="sid">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['StudentID'] . '">' . $row['StudentName'] . '</option>'; } echo '</select>'; mysql_close($con); ?> <form id="form1" name="form1" method="post" action="update_result.php"> <label> <input type="submit" name="Submit" value="Submit" /> </label> </form> </body> </html> update_result.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); if (!empty($_POST['sid']) && !empty($_POST['cid'])) { foreach ($_POST['cid'] as $key => $course) { $courses .= $course."-"; } $courses = rtrim($courses,"-"); $student = $_POST['sid']; $sql = "INSERT INTO test (StudentID, CourseID) VALUES('".mysql_real_escape_string($student)."','".mysql_real_escape_string($courses)."')"; $query = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error()); if (mysql_affected_rows() > 0) { echo mysql_affected_rows() . ' rows added.'; } } mysql_close($con); ?> </body> </html> Code: [Select] <table border="1"> <tr> <th>ID</th> <th>Image</th> </tr> <?php for($i=0; $i<=100; $i++) { $url = 'http://localhost/images/icon_'.$i.'_64x64.jpg'; echo "<tr><td>".$i."</td><td><img src='".$url."' /></td></tr>"; } ?> </table> So after testing this script, I get empty cells in the table if the image doesn't exist. Can someone show me how to make it display only the images that exists in that folder ? basically this is a search function <form method="post" action="test1.php"> <input type = "hidden" name="submitted" value ="true" /> <label>TYPE: <select name="field"> <option value = "sid">StudentID</option> <option value = "sname">StudentName</option> </select> </label> <label>WORD: <input type="text" name="searchword" /> </label> <input type="submit" /> </form> ------------- <?php if (isset($_POST['submitted'])){ $con = mysql_connect("localhost","root",""); mysql_select_db("uni", $con); $field= $_POST['field']; $searchword = $_POST['searchword']; $query = "SELECT* FROM student WHERE $field = '$searchword'"; $result = mysqli_query($con,$query) or die ('error data'); //-----------> error line echo"<table>"; echo "<tr><th>StudentID</th><th>StudentName</th></tr>"; while($row = mysqli_fetch_array($result)){ echo "<tr><td>"; echo "$row ['sid']"; echo "</td><td>"; echo "$row ['sname']"; echo "</td></tr>"; } echo"</table>"; } mysql_close($con); ?> NB: the error message "Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\wamp\www\test1.php on line 21 error data" |