Jump to content

JamesB

Members
  • Posts

    425
  • Joined

  • Last visited

Posts posted by JamesB

  1. Qestion 1 i want my all dept code from database in my dept_code combo box field means 1 2 and 3
    echo '<select>';$result = mysqli_query( "select dept_code from table" );while ($row = mysqli_fetch_array($result)){echo '<option>'.$row['dept_code'].'</option>';}echo '</select>';

    for question 2, if you want to use that query:

    select dept_name from table where dept_id = 1

    you will need to use ajax to send a request to php, and have php reply with the single dept name. alternatively you could avoid ajax by sending all dept names to the client before the form is submitted.

    • Like 1
  2. to check if a key exists in the array:

    if (isset($devices['samsung'])){}

    or to check if a value exists in the array:

    if (in_array('Samsung', $devices)){}

    also for the include path, you need to use 2 backslashes for each one. C:\\xampp\\.. (doesn't apply to forward slashes)

  3. one option would be to use:

    echo empty($rows[0]['name']) ? '' : $rows[0]['name'];

    or you could create array elements with blank values initially:

    $fieldCount = 5;for ($i=0; $i<$fieldCount; $i++) {  $rows[$i] = array( 'name' => '' );}

    but i think calling a function with the first option would be better.

    • Like 1
  4. to load all returned sql rows into an array:

    $sql = "select * from person where ###### = 'male' ";$result = mysql_query($sql); $rows = array();while ($row = mysql_fetch_array($result)) {  $rows[] = $row;}

    then to read the array:

    echo $rows[0]['name'];echo $rows[0]['age'];

    • Like 1
  5. to fix the shape from being centered to the mouse position, you could store the mouse-to-shape xy position offsets:

    function startMove() {$('.movable').on('mousemove', function(event) {var thisX = event.pageX + offsets.x,thisY = event.pageY + offsets.y; $('.movable').offset({left: thisX,top: thisY});});}$("#containerDiv").on('mousedown', function(event) {$(this).addClass('movable');offsets = {x: $(this).offset().left - event.pageX,y: $(this).offset().top - event.pageY};startMove();}).on('mouseup', function() {$(this).removeClass('movable');});

    also check here for the cursor icon:http://stackoverflow...-with-css-or-js

  6. It's probably meaning to remove any characters which are not these: A-Z a-z 0-9 . @You could loop around all characters in the email string, then if the character is valid, push the character on to the end of another string for the "cleaned" email.

  7. try this:

    document.body.style.background="url('"+cols[day]+"')";

    you could also store the month image urls in an array instead of using 12 parameters:

    var monthImages = [  '1.jpg',  '2.jpg',  ..];var url = monthImages[ day ];

  8. name=\"favorite1\"should bename=\"food\" andvalue=\"favorite1\"should bevalue=\"$favorite1\" in:

    echo "<input type=\"radio\" name=\"favorite1\" value=\"favorite1\"> $favorite1\n";

    the empty <select> is because of:

    <select name = "food" id = "food">

    and

    </select>

    for validating the color and food you can use in_array() as birbal said.http://php.net/manua...on.in-array.php you could put the $color and $food arrays in 1 file, then include that file from your current 2 files (to save duplicating them)http://php.net/manua...ion.include.php

    • Like 1
  9. if someone logs in, then they find out they have a virus or something on their computer, they might want to logout hoping it will force the hacker to relogin with username and password.if the logout didn't remove the server side token, the hacker would then still be able to send the token to the server directly and the server would find the token in the database and think the hacker is logged in, despite the real user clicking logout. if you were limited to removing the token from either the client or the server, it would be better to remove it from the server. (but remove it from all places when possible)

  10. i think it's currently getting evaluated as

    UPDATE images SET title = ('$title' AND category = '$style') WHERE id = '$image_id'

    try using a comma instead of AND to update multiple cells.

  11. you could use a function to fetch the checked radio element, then access it's value with .value

    <input type="button" value="Submit" onclick="sendVote()" />

    function getCheckedRadio(name) {	var radios = document.getElementsByName(name);	for (var i=0, j=radios.length; i<j; i++)		if (radios[i].checked)			return radios[i];	return false;} function sendVote() {	var radio = getCheckedRadio('vote'); // <input type=radio name=vote>		if (radio == false)		alert('no radio checked!');	else		alert(radio.value);}

    • Like 1
  12. this code:

    $style_id = $row['id'];

    comes before $row is assigned a value. also this:

    if ( $category LIKE %$style_id% )

    the LIKE and %'s are part of SQL, not PHP, they need to go in the query string sent to mysql_query.

  13. <html><head><script type="text/javascript">function onClickTrue() {	console.log('clicked true');	alert('clicked true');}function onClickFalse() {	window.close();}</script></head><body><div class="question"><h1>What is Your Name?</h1></div><div class="trueans" onclick='onClickTrue()'><h3>Owais</h3></div><div class="falseans" onclick='onClickFalse()'><h3>Zeeshan</h3></div><div class="falseans" onclick="onClickFalse()"><h3>Samad</h3></div><div class="falseans" onclick="onClickFalse()"><h3>Shehrose</h3></div></body></html>

×
×
  • Create New...