Jump to content

[SOLVED] Simple help please


marklarah

Recommended Posts

My code;

<?php
mysql_connect("localhost", "***", "***") or die(mysql_error());
mysql_select_db("***") or die(mysql_error());
?>

<style type="text/css">
fieldset { border:1px solid green; padding: 1em;
  font:80%/1 sans-serif; }

legend {
  padding: 0.2em 0.5em;
  border:1px solid green;
  color:green;
  font-size:90%;
  text-align:left;
  }

label {
  float:left;
  width:25%;
  margin-right:0.5em;
  padding-top:0.2em;
  text-align:right;
  font-weight:bold;
  }
</style>

<script type="text/javascript">
function formgo(){

var cnum = document.lform.ops.length;

for (i = 0; i <cnum; i++) {
if (document.lform.ops[i].checked) {
var chkd = document.lform.ops[i].value
}
}


switch (chkd)
{


<?php
while ($row = mysql_fetch_array(mysql_query("SELECT * FROM logins ORDER BY label DESC"))){

//Maybe this bit is a bit iffy?
echo 'case "'.$row['name'].'":
  document.'.$row['name'].'.submit();
  break;';

}
?>


default:
  alert("");
}

alert(chkd);

}
</script>

<form name="lform">
  <fieldset>
  <legend>Login Forms</legend>
<?php

while ($row = mysql_fetch_array(mysql_query("SELECT * FROM logins ORDER BY label DESC"))){

echo '  <label for="ops">'.$row['label'].'</label> <input type="radio" name="ops" value="'.$row['name'].'">     <br />';
}
?>
<button type="button" onClick="formgo()">Submit</button>
  </fieldset>
</form>


<?php
while ($row = mysql_fetch_array(mysql_query("SELECT * FROM logins ORDER BY label DESC"))){
$info = explode("|", $row['info']);
$num = count($info);

if($num % 2 != 0){
echo 'Problem';
}else{

echo '<form name="'.$row['name'].'" action="'.$row['action'].'" method="post">';


$n = 0;
while ($n != ($num/2)){
$m = $n+1;
echo '<input type="hidden" name="'.$info[$n].'" value="'.$info[$m].'">';
$n++;
$n++;
}

echo '</form>

}


}
?>

 

Im sure I could fix this myself, except the page never actually stops loading for me to see what the problem is. If that IS the problem though, then I have no idea how to diagnose it.

 

My only guess would be the php in the middle of the javascript, but I've done the before, and it should work ???

 

Any ideas? Cheers - Mark

 

EDIT:

Sorry, just to let you know what this does is supposed to do, is when i got fed up of all the log in pages for different stuff, I wanted just one page, which uses POST (obviously) to get to other logins, without having to remember all the other the passwords or usernames. The use puts the info into the database. The info array works so if there are 3 fields, one hidden and two non (username and password eg), then they all get turned into hidden fields. You put the name of the field first, then the value, then repeat. so for example:

universe|uni18|username|joecool|password|darthvader123

 

Hope that makes sense...

 

Link to comment
https://forums.phpfreaks.com/topic/118238-solved-simple-help-please/
Share on other sites

The error is in the last echo of the file. You didn't put "</form>" within apostrophes/quotes, and more importantly, you didn't end the line with a semicolon, therefore it's trying to echo the end of your else and the end of your while, instead of ending the loops.

Personally, first thing I would do is change the way your SQL statements are set up.  Define your sql statements first, then call them as a var.

 

$query "SELECT * FROM users";

$sql = mysql_query($query) or die(mysql_error());

 

while ($results = mysql_fetch_assoc($sql))  {

  //code...

  }

 

Without the "or die(mysql_error())" portion of it, if mysql is kicking back errors, the while loop may never complete, hence infinite...

 

Imagine this:

 

while ($a < 10)  {

  $b++;

  }

 

That loop will never finish either, but after a while should get a TIMEOUT error...

Hmm. Ok, I did what you said (one way, i was just copying and pasting). IIt didn't help, but it made me think. Anyway, I found the error. Though now it displays one button, and the frame, it doesn't display the radios o_0?

 

My current code

<?php
mysql_connect("localhost", "....", "....") or die(mysql_error());
mysql_select_db("....") or die(mysql_error());
?>

<style type="text/css">
fieldset { border:1px solid green; padding: 1em;
  font:80%/1 sans-serif; }

legend {
  padding: 0.2em 0.5em;
  border:1px solid green;
  color:green;
  font-size:90%;
  text-align:left;
  }

label {
  float:left;
  width:25%;
  margin-right:0.5em;
  padding-top:0.2em;
  text-align:right;
  font-weight:bold;
  }
</style>

<script type="text/javascript">
function formgo(){

var cnum = document.lform.ops.length;

for (i = 0; i <cnum; i++) {
if (document.lform.ops[i].checked) {
var chkd = document.lform.ops[i].value;
}
}


switch (chkd)
{

<?php

$query = mysql_query("SELECT * FROM logins ORDER BY label DESC") or die(mysql_error());

while ($row = mysql_fetch_array($query)){

echo 'case "'.$row['name'].'":
  document.'.$row['name'].'.submit();
  break;';
}
?>



default:
  alert("");
}

alert(chkd);

}
</script>

<form name="lform">
  <fieldset>
  <legend>Login Forms</legend>
<?php

while ($rows = mysql_fetch_array($query)){
//this here doesn't work ?
echo '  <label for="ops">'.$rows['label'].'</label> <input type="radio" name="ops" value="'.$rows['name'].'">     <br />';
}
?>
<button type="button" onClick="formgo()">Submit</button>
  </fieldset>
</form>


<?php
while ($row = mysql_fetch_array($query)){
$info = explode("|", $row['info']);
$num = count($info);

if($num % 2 != 0){
echo 'Problem';
}else{

echo '<form name="'.$row['name'].'" action="'.$row['action'].'" method="post">';


$n = 0;
while ($n < ($num/2)){
$m = $n+1;
echo '<input type="hidden" name="'.$info[$n].'" value="'.$info[$m].'">';
$n++;
$n++;
}

echo '</form>';

}


}
?>

 

I took the code where it displays the radios, along with the connection info, and it works fine, but not here. Maybe its conflicting with something?

 

Not necessarily. You might have had an unfinished line that didn't show. Attitude won't get you far on this board.

 

have you tried mysql_num_rows to see if there are actually rows for there to be radio buttons?

 

----------------

Now playing: Enter Shikari - Acid Nation

via FoxyTunes

Can you please replace the radio button with this:

 

while ($rows = mysql_fetch_array($query)){

print_r($rows);

}

 

and tell me what you get there?

 

----------------

Now playing: Enter Shikari - Return To Energiser (Zane Lowe BBC Session)

via FoxyTunes

 <?php
connect stuff here
?>

<style type="text/css">
fieldset { border:1px solid green; padding: 1em;
  font:80%/1 sans-serif; }

legend {
  padding: 0.2em 0.5em;
  border:1px solid green;
  color:green;
  font-size:90%;
  text-align:left;
  }

label {
  float:left;
  width:25%;
  margin-right:0.5em;
  padding-top:0.2em;
  text-align:right;
  font-weight:bold;
  }
</style>

<script type="text/javascript">
function formgo(){

var cnum = document.lform.ops.length;

for (i = 0; i <cnum; i++) {
if (document.lform.ops[i].checked) {
var chkd = document.lform.ops[i].value;
}
}


switch (chkd)
{

<?php

$query = mysql_query("SELECT * FROM logins ORDER BY label DESC") or die(mysql_error());

while ($row = mysql_fetch_array($query)){

echo 'case "'.$row['name'].'":
  document.'.$row['name'].'.submit();
  break;

';
}
?>



default:
  alert("");
}

alert(chkd);

}
</script>

<form name="lform">
  <fieldset>
  <legend>Login Forms</legend>
<?php


while ($rows = mysql_fetch_array($query)){
print_r($rows);
}


// echo mysql_num_rows($query);
while ($rows = mysql_fetch_array($query)){

print '  <label for="ops">'.$rows['label'].'</label> <input type="radio" name="ops" value="'.$rows['name'].'">     <br />';
}
?>
<button type="button" onClick="formgo()">Submit</button>
  </fieldset>
</form>


<?php
while ($row = mysql_fetch_array($query)){
$info = explode("|", $row['info']);
$num = count($info);

if($num % 2 != 0){
echo 'Problem';
}else{

echo '<form name="'.$row['name'].'" action="'.$row['action'].'" method="post">';


$n = 0;
while ($n < ($num/2)){
$m = $n+1;
echo '<input type="hidden" name="'.$info[$n].'" value="'.$info[$m].'">';
$n++;
$n++;
}

echo '</form>';

}


}
?>

 <?php
/**connect stuff here**/

$query = mysql_query("SELECT * FROM logins ORDER BY label DESC") or die(mysql_error());

while ($row = mysql_fetch_assoc($query)){
print_r($row);
}

 

What does that output?

 

----------------

Now playing: Flyleaf - All Around Me

via FoxyTunes

Archived

This topic is now archived and is closed to further replies.

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