Jump to content

paul2463

Members
  • Posts

    955
  • Joined

  • Last visited

    Never

Posts posted by paul2463

  1. sorry for trying to mislead people there

     

    mysql_fetch_assoc

     

    (PHP 4 >= 4.0.3, PHP 5, PECL mysql:1.0)

     

    mysql_fetch_assoc — Fetch a result row as an associative array

     

     

    will only fetch one row of the array, thanks for pointing it out to me DarkWater I now stand corrected

  2. you could try and remove the while loop altogether and see what that does for you

     

    just use

     

    $row = mysql_fetch_assoc($query); // making $row the associative array it is and use the two foreach loops on it 
    

     

    remeberbering to also remove the while closing brace

  3. foreach ($row['product_vendor'] as $vendor)
    

     

    is NOT an array it is a single entity, $row is an associative array, but in a while loop it is only acting on one row at a time and the $row[product_vendor] is one specific key=>value not an array, I hope that makes sense

  4. you mean this??

     

    $Get = mysql_query("SELECT (strength+defence+speed+agility) As Total 
    FROM userstable WHERE Level >= $Level+5  ORDER BY Total DESC Limit 1")
    

     

    so it will pick rows that have a level that is greater than or equal to $level+5

     

    you will probably have to "order by level Desc" so you get the lowest level that is higher than $level+5 if that makes sense

  5. it spits out 0 for all the access keys because you have set up the variable inside the while loop, so every time the while loop runs it resets $i to equal 0

    <?
    include('db.php');
    $query = "SELECT * FROM news ORDER BY tstamp DESC LIMIT 8";
    
    $result=mysql_query($query);
    ?> <ol> <?
    $i = 0;
    
    while($row = mysql_fetch_array($result))
    {
    
    		print '<li accesskey="'.$i.'"><a href="/news/?id='.$row['id'].'">'.$row['subj'].'</a></li>';
    		$i++;
    
    
    }
    ?>
    </ol>
    

     

  6. just for your information chaps and chapesses, the mysql_error() code you get back tells you exactly where the problem lies, in your case

     

    Error:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from) VALUES ('4', 'et', '', 'demouser')' at line 1

     

    "from" is the problem, and we know this because the syntax error is always the first word after the near ', that is where the fault lies, all the rest of the line of code it gives you is so that you can easily find which word it is failing on.

     

  7. I code exactly like the person I plagarised from - oops did that come out loud???

     

    only joking by the way guys...

     

    I use method #2 I prefer all my braces to be vertically coincident so I can easily see which opening and closing braces match( obviously on small functions / code ), I write using PHPDesigner which places the matching braces under the opening one and I find it much better for me to debug my own crap that way. ( usually takes ages so it has to be easily read)

  8. I went a slightly different way as I assumed he already had the product table set up with the model names already filled in

     

    <?php
    $query = "SELECT * FROM product";
    $result = mysql_query($query) or die ("Error in query" . mysql_error());
    while($row = mysql_fetch_assoc($result))
    //for each entry in the product table
    {
     	//get the name of the model
     	$file = $row['model'];
     	//use that name and create a filename
    	$filename = "$file.txt";
    	// read into a string the file contents
    	$contents= file_get_contents($filename);
    	//write it back into the table in the description column - whatever it is called
    	$updateQuery = "UPDATE product SET description = '$contents' WHERE model = '$file'";
    	mysql_query($updateQuery) or die ("Error in UpdateQuery" . mysql_error());
    }	
    ?>
    

     

  9. change your user input form to a post form

     

    <?php
    if (isset($_POST['TEST'])) 
    {
    //remove all empty fields from the $_POST array and create a new array 
    foreach($_POST as $key => $var)
    {
    	if($var != "")
    	{
    		$address[$key] = $var;	//contains all the fields that were NOT empty
    	}
    }
    //start to create the header
    $header = "Location: http://localhost/userinput.php?";
    
    if(count($address)>0) //if the address array has 1 or more fields in it
    {
    	foreach($address as $key => $var)
    	{
    		$header.="$key=$var&"; //add each one to the header address
    	}
    	//remove the last ampersand
    	$header = substr($header, 0 , -1);
    }
    else
    {
    	 //otherwise just remove the "?" from the header address
    	$header = substr($header, 0 , -1);
    } 
    //send them to the new header with all the new $_GET variables attached                            
    header( $header ); //
    }
    ?>
    
    <form method="POST" action="">
    
    <input type="text" name="username">
    
    <input type="password" name="password">  <br>
    
    <input class="gray" type="submit" name="TEST"/>
    

     

    I know that alot of the stuff could be combined to make the code small in size, but its easier to explain the way I have typed it I think

     

  10. here we go... I am trying to help you....when i asked if you had tried something, i didnt ask if you had changed it and tried it, i asked if you had tried it....you said YES...can you explain to me then why you changed my code

     

    header( "Location: http://localhost/inputresult.php?username=".$_GET['username']."&password=".$_GET['password'] );
    

     

    to your code

     

    header( "Location: http://localhost/userinput.php?" . $_POST['username'] . "&" . $_POST['password'] ); 
    

     

    things wrong in your line of code:-

     

    1. you are not POST'ing anything you are still using GET

    2. If you dont tell it what to store the POST or GET variables as, you cannot pull them on the other side

     

    can you try the code i origonally sent you and see if that works for you - unchanged

    then we can move on from there

     

  11. because you are using the AND word......... you are asking it to delete any rows that ARE NOT groupmember 1 AND ARE NOT group_id 74... for this to be true they both have to BE NOT , as all rows are group_id 74 then all will fail because both items are not met

     

    if you change it

    DELETE FROM jos_group_groupmembers  WHERE groupmember_id != 1 AND group_id = 74
    

     

    this will delete rows 2 and three because it is now being asked to delete rows which ARE NOT groupmember 1 BUT ARE equal to group_id 74

     

    or you could change it

    DELETE FROM jos_group_groupmembers  WHERE groupmember_id != 1 OR group_id != 74
    

     

    this will do the same, it will delete rows 2 and 3 but it will also delete every row where the group_id IS NOT 74

     

    HTH

  12. if you dont have an action it goes back to itself, when that happens it sees that $_GET[test] has been set and then places the $_GET variables into the forwarding address and sends that page, your userinput page then recieves the address with the $_GET variables attached and does what you asked it to by echoing out the variables........works perfectly on my machine!!

     

    Did you try it before denouncing it???

  13. if you look closly at the error being reported, you will see that the last 120 does not have a closing single tick on it, then go and have a look at your query code you will also see that there is a closing single tick missing after the double ticks before the closing brace......try this

    $sql = "INSERT INTO   accounts (userid,name,description,expenses,profits,balance,starting) VALUES(
                         '" . $id   . "', '"
                         . $name. "', '"
                         . $description . "', '"
                         . 0 . "', '"
                         . 0 . "', '"
                         . $_POST['balance'] . "', '".$_POST['balance']."')";
                         mysql_query($sql) or die(mysql_error());
    

     

  14. try something like

    <?php        
    
    if (isset($_GET['TEST'])) {
    
    header( "Location: http://localhost/inputresult.php?username=".$_GET['username']."&password=".$_GET['password'] );
    
    
    
    }
    
    ?>
    
    
    
    
    
    <form method="GET" action="">
    
    <input type="text" name="username">
    
    <input type="password" name="password">  <br>
    
    <input class="gray" type="submit" name="TEST"/>
    

×
×
  • 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.