PHP Help

Place to talk about all that new hardware and decaying software you have.

Moderator: General Mods

Post Reply
Starman Ghost
Trooper
Posts: 535
Joined: Wed Jul 28, 2004 3:26 am

PHP Help

Post by Starman Ghost »

So I've created a script that dynamically creates a table when you input whatever mysql table you want to work with for class. It also dynamically creates a form so you can enter new values. This here is just part of it, but it's the part giving me the problem:

Code: Select all

for($i=0; $i<$fields_num; $i++)
{
	$field = mysql_fetch_field($result);
	if($work_table == 'student' && $i == 0)
	print "<td><input type=\"text\" name=\"{$field->name}\" value=\"input ignored\" /></td>";
	else
	print "<td><input type=\"text\" name=\"{$field->name}\" /></td>";
}
I can't seem to get the actual field name(from the db) to be dynamically inputed into the input field name. Any help?

Edit:Nevermind, I got it working. I instead used mysql_field_name() in the loop to get the field name into a variable then use that in the input name.
[code]<Guo_Si> Hey, you know what sucks?
<TheXPhial> vaccuums
<Guo_Si> Hey, you know what sucks in a metaphorical sense?
<TheXPhial> black holes
<Guo_Si> Hey, you know what just isn't cool?
<TheXPhial> lava?[/code]
Starman Ghost
Trooper
Posts: 535
Joined: Wed Jul 28, 2004 3:26 am

Post by Starman Ghost »

Ok new problem. For class I have a script that you create a username and password with rules. It checks them for validity, then checks them from a file list of usernames and passwords. If they don't exist and are valid they are entered into the file. Altough it works, I'm keep getting an the error:
Notice: Undefined offset: 1 in f:\ch6b.php on line 28

Here is the code:

Code: Select all

<html>
<head>
<title>Create a User Id</title>
</head>
<body>

<?php

if (!($_POST['userid']) || !($_POST['password']))
{
	print "You didn't enter all the information!";
}
else
{
	$userid = $_POST['userid'];;
	$password = $_POST['password'];
	$useridpattern = '^[a-z]([0-9]|[a-z]){2,}$';
	$passwordpattern = '([0-9]|[[:alpha:]]){6,}$';
	$filename = 'password.txt';
	$fileh = fopen($filename, 'a+');
	$ret = flock($fileh, LOCK_EX);
	$found = 0;

	while(!feof($fileh) && !($found))
	{
		$inline = fgets($fileh, 4096);
		//$inline = rtrim($inline, '\r\n');
		list($usid, $pass) = split(':', $inline);
		if($usid == $userid)
			$found = 1;
	}

	if (ereg($useridpattern, $userid) && !ereg('^(root|admin|operator)$', $userid) && !($found))
	{
		print "UserId is Valid!<br \>";

		if (ereg($passwordpattern, $password))
		{
			print "Password is Valid!";
			$put = "$userid:$password\r\n";
			fputs($fileh, $put);
			fclose($fileh);
		}
		else
		{
			print "Password is Invalid!";
		}
	}
	else
	{
		print "UserId is Invalid!";
	}
}
?>

</body>
</html>
Help? :)
[code]<Guo_Si> Hey, you know what sucks?
<TheXPhial> vaccuums
<Guo_Si> Hey, you know what sucks in a metaphorical sense?
<TheXPhial> black holes
<Guo_Si> Hey, you know what just isn't cool?
<TheXPhial> lava?[/code]
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

It helps to highlight the problematic code line.

My guess is this line:
$put = "$userid:$password\r\n";

You need to use . (a pair of dots) to properly concatenate said line.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
funkyass
"God"
Posts: 1128
Joined: Tue Jul 27, 2004 11:24 pm

Post by funkyass »

bad practice here.

for any and all variables passed via post or get, you should assign them to varibles as so:

Code: Select all

$username =$_REQUEST['user'];#replace with POST or GET here
then check to see if its actually there:

Code: Select all

if(!is_null($username))...

the above works better, and allows you to be more flexible.
Does [Kevin] Smith masturbate with steel wool too?

- Yes, but don’t change the subject.
Starman Ghost
Trooper
Posts: 535
Joined: Wed Jul 28, 2004 3:26 am

Post by Starman Ghost »

funkyass wrote:bad practice here.

for any and all variables passed via post or get, you should assign them to varibles as so:

Code: Select all

$username =$_REQUEST['user'];#replace with POST or GET here
then check to see if its actually there:

Code: Select all

if(!is_null($username))...

the above works better, and allows you to be more flexible.
If the variable doesn't exist in in $_POST, I will get an error when I try to assign to a local variable. I tried that and it doesn't work.

@Deathlike2
Lets say my user name is bob and my pass is villa. With that line I'm trying to write bob:villa into the file with carraige return. How would I concat this? Like this?:

Code: Select all

 $put = $userid.":".$password."\r\n"; 
But besdies, the problem is caused by this line

Code: Select all

list($usid, $pass) = split(':', $inline); 
[code]<Guo_Si> Hey, you know what sucks?
<TheXPhial> vaccuums
<Guo_Si> Hey, you know what sucks in a metaphorical sense?
<TheXPhial> black holes
<Guo_Si> Hey, you know what just isn't cool?
<TheXPhial> lava?[/code]
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
funkyass
"God"
Posts: 1128
Joined: Tue Jul 27, 2004 11:24 pm

Post by funkyass »

Starman Ghost wrote: If the variable doesn't exist in in $_POST, I will get an error when I try to assign to a local variable. I tried that and it doesn't work.
error_reporting must be enabled somewhere. its a notice, it shouldn't hinder the operation of the program.
Does [Kevin] Smith masturbate with steel wool too?

- Yes, but don’t change the subject.
Post Reply