coding issue, Please help (resolved)

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Twilight
Posts: 58
Joined: Sat Mar 17, 2012 11:11 am

coding issue, Please help (resolved)

Post 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
Last edited by Twilight on Mon Oct 22, 2012 3:38 pm, edited 2 times in total.
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: coding issue, Please help

Post 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? ;)
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Twilight
Posts: 58
Joined: Sat Mar 17, 2012 11:11 am

Re: coding issue, Please help

Post 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
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: coding issue, Please help

Post 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']; 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Twilight
Posts: 58
Joined: Sat Mar 17, 2012 11:11 am

Re: coding issue, Please help

Post 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
Twilight
Posts: 58
Joined: Sat Mar 17, 2012 11:11 am

Re: coding issue, Please help

Post 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
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: coding issue, Please help

Post by Chris »

Fighting for peace is declaring war on war. If you want peace be peaceful.
Twilight
Posts: 58
Joined: Sat Mar 17, 2012 11:11 am

Re: coding issue, Please help

Post 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
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: coding issue, Please help

Post 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" />
Fighting for peace is declaring war on war. If you want peace be peaceful.
Twilight
Posts: 58
Joined: Sat Mar 17, 2012 11:11 am

Re: coding issue, Please help

Post 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">
Post Reply

Return to “Beginner Help and Support”