Page 1 of 1

coding issue, Please help (resolved)

Posted: Wed Mar 21, 2012 11:43 pm
by Twilight
Hi all

please help me I know I am doing something dumb but just can't see what it is.

I am trying to write the register user script but keep getting

could not query players table

Please see code for my register.php and reguser.php

Any help would be great.

Register.php

Code: Select all

<?php
include 'connect.php';

?>

<form method = "POST" action="reguser.php">
Type First Name Here: <input type="text" name="First" size="20"><br>
Type Last Name Here: <input type="text" name="Last" size="20"><br>
Type Password Here: <input type="text" name="password" size="20"><br>
Retype Password Here: <input type="text" name="password2" size="20"><br>
Type email address Here: <input type="text" name="email" size="60"><br>

<input type="submit" value="submit">

Reguser.php

<?php
include 'connect.php'
?>

<?php
$First=$_POST{'First'};
$Last=$_POST{'Last'};
$password=$_POST{'password'};
$password2=$_POST{'password2'};
$First=strip_tags($First);
$Last=strip_tags($Last);
$email=$_POST{'email'};
$email=strip_tags($email);

if ($email == "")
{
echo "You have not entered an email address!";
echo " <A href='Register.php'>Go back</a><br>";
exit;
}
if ($password==$password2)
{
$isFirst="SELECT * from players where name='$First'";
$isFirst2=mysql_query($isFirstname) or die ("could not query players table");
$isFirst3=mysql_fetch_array($isFirst2);
$isLast="select * from players where name='$Last'";
$isLast5=mysql_query($isLast) or die ("could not query players table");
$isLast6=mysql_fetch_array($isLast5);

if($_POST('password') || $_POST('password2'))
{
print " You did not enter a password";
echo "<a href='Register.php'>Go back</a><br>";
exit;
}
else if(($isFirst3 || strlen($First)>20 || strlen($First)<1) && ($isLast6 || strlen($Last)>20 || strlen($Last)<1))
{
print "there is already a player with that name or the name you entered is over 20 letters or less then 1 letter";
echo "<A href='Register.php'>Go back</a><br>";
exit;
}
else
{
$password=md5($password);

$SQL = "INSERT into players(First, Last, password, email) VALUES ('$First', '$Last', '$password', '$email')";
mysql_query($SQL) or die("could not register");

print "Thank you for registering";

}
}


else
{
print "Your password didn't match or you did not eneter a password";
echo "(A href='Register.php'>Go back</a><br>";
exit;
}
?>
Regards
Andy

Re: coding issue, Please help

Posted: Thu Mar 22, 2012 5:03 am
by 62896dude
$isFirst="SELECT * from players where name='$First'";
$isFirst2=mysql_query($isFirstname) or die ("could not query players table");

Shouldn't $isFirstname inthe second line of that just be $isFirst? ;)

Re: coding issue, Please help

Posted: Thu Mar 22, 2012 7:55 am
by Twilight
Hi

I have made this change but i am still getting the same error message. The code looks good to me.

Regards
Andy

Re: coding issue, Please help

Posted: Thu Mar 22, 2012 9:14 am
by Chris
See if you are getting any mysql errors. Use http://php.net/mysql_error

Replace:

Code: Select all

$isFirst2=mysql_query($isFirstname) or die ("could not query players table"); 
with:

Code: Select all

$isFirst2=mysql_query($isFirstname) or die ("could not query players table" . mysql_error() ); 
Also, I've never seen curly braces used like this before:

Code: Select all

$First=$_POST{'First'}; 
You should be using square ones:

Code: Select all

$First=$_POST['First']; 

Re: coding issue, Please help

Posted: Thu Mar 22, 2012 11:58 am
by Twilight
Hi Chris

Thanks for all you help.

I have change the {} to []. I was just finding it hard to see the coding in the video.

I have also added the code you suggested and I am getting the following error

could not query players table1Unknown column 'name' in 'where clause'

The DB is called game

The table is called players

The column is called First

Regards
Andy

Re: coding issue, Please help

Posted: Thu Mar 22, 2012 12:14 pm
by Twilight
Ok

I have found the error. and have now got it working.

I would like to say a big thankyou to all that helped me.

:D

Re: coding issue, Please help

Posted: Fri Mar 23, 2012 3:14 pm
by Chris

Re: coding issue, Please help

Posted: Mon Mar 26, 2012 3:55 pm
by Twilight
Hi All

I am going mad once again

I keep getting the follwoing error

Notice: Undefined index: Title in C:\wamp\www\game\create_ticket.php on line 8

The code continues and updates my table except the Title column. I have no idea why this is doing this as the code is the same for the last two lines and they work.

$First=$_POST['First'];
$Last=$_POST['Last'];
$Title=$_POST['Title'];
$Description=$_POST['Description'];
$Password=$_POST['Password'];

Regards
Andy

Re: coding issue, Please help

Posted: Mon Mar 26, 2012 7:32 pm
by Chris
It means that $_POST['Title'] doesn't exist.

Make sure the input field is called Title:

Code: Select all

<input type="text" name="Title" />

Re: coding issue, Please help

Posted: Mon Mar 26, 2012 8:05 pm
by Twilight
Hi Chris

I have the following code. Can't see anything wrong with it.

<?php
include 'connect.php';

?>

<form method = "POST" action="create_ticket.php">
Client First Name: <input type="text" name="First" size="20"><br>
Client Last Name: <input type="text" name="Last" size="20"><br>
Ticket Title:<input type="text" name="Title" size="60"><br>
Description of issue:<br> <input type="text" name="Description" size="600"><br>
Password (if needed): <input type="text" name="Password" size="20"><br>


<input type="submit" value="submit">