-
Posts
1,842 -
Joined
-
Last visited
Posts posted by marcus
-
-
You're putting single quotes around it.
[code=php:0]
$a = "$Player_$i";
[/code] -
[code=php:0]
if( ({time() - $user->last_activity)/60) > 20){
break;
}
[/code] -
Change mysql_num_rows($result) to mysql_num_rows($statz)
-
Yeah, what Jesirose said should do the trick, if not, replace
[code]
or die ("Couldn't execute");
[/code]
with
[code]
or die (mysql_error());
[/code] -
To use the date function to get hour/min/sec you do:
[code=php:0]
$date = date("h/i/s");
//if you want the 24-hour time syntax
$date = date("H/i/s");
[/code] -
There is only one query on that.
When it tries to execute the query is it saying Couldn't Execute or is it saying something else? -
[code=php:0]
$sql = "INSERT INTO `General_Stats` (`User_Name`,`Password`,`Email`,`Security_Number`,`F_Name`,`L_Name`,`Age`) VALUES ('username','password','email','s_number','fname','lname','age')";
[/code]
NOTE: If the field is an integer you can only insert numerals, meaning no dashes, spaces, etc.. and make sure the field lengths are greater than what you're trying to insert. -
I've been trying the best I could since you told me that like a couple months ago, haha.
-
Just do:
CREATE TABLE `users` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 255 ) NOT NULL ,
`password` VARCHAR( 255 ) NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`ip` VARCHAR( 255 ) NOT NULL ,
`confirm` INT NOT NULL DEFAULT '0' ,
`confirm2` INT ( 75 ) NOT NULL
) ENGINE = MYISAM ;
And then make a file called form.php //will store your form.
[code=php:0]
<?php
echo "<form name=register method=post action=register.php>\n
<table border=0 cellspacing=3 cellpadding=2>\n
<tr><td>
Username:</td>
<td><input type=text name=username></td>
</tr>
<tr><td>
Password:</td>
<td><input type=password name=pass1></td>
</tr>
<tr><td>
Confirm:</td>
<td><input type=password name=pass2></td>
</tr>
<tr><td>
Email:</td>
<td><input type=text name=email1></td>
</tr>
<tr><td>
Confirm:</td>
<td><input type=text name=email2></td>
</tr>
<tr><td colspan=2>
<input type=hidden name=act value=register>
<input type=submit value=Register>
</td></tr>
</table>
</form>";
?>
[/code]
Then we'll make register.php
[code=php:0]
<?php
$act = $_POST['act'];
if(!isset($act)){ //you could do empty($act)
include_once('form.php');
die();
}
if($act == register){
$username = $_POST['username'];
$password = md5($_POST['pass1']);
$confpwrd = md5($_POST['pass2'];
$email = $_POST['email1'];
$confemal = $_POST['email2'];
if(isset($username) && isset($password) && isset($confpwrd) && isset($email) && isset($confemal)){
//will check for password equaling
if($password != $confpwrd){
echo "<b>Your passwords did not match!</b><br><br>";
include_once('form.php');
die();
}
//will check length of pw
if(str_len($_POST['pass1']) < 6){
echo "<b>Your password was too short!</b><br><br>";
include_once('form.php');
die();
}
//will check for email equaliing (wont go into correct email syntax if they want to register then they shall confirm it
if($email != $confemal){
echo "<b>Your email addresses did not match!</b><br><br>";
include_once('form.php');
die();
}
//checking if user name exists
$sql = "SELECT `username` FROM `users` WHERE `username` ='$username'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 1){
echo "<b>The username $username is already in use!</b><br><br>";
include_once('form.php');
die();
}
//if does exist check length
if(str_len($username) < 4){
echo "<b>The username you entered was too short!</b><br><br>";
include_once('form.php');
die();
}
//will check if IP already exists
$sql = "SELECT `ip` FROM `users` WHERE `ip` ='$_SERVER[REMOTE_ADDR]'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 1){
echo "<b>Your IP Address is already in use!</b><br><br>";
include_once('form.php');
die();
}
//if everything is good then we will insert into the database
$rand = mt_rand(10,30);
$sql = "INSERT INTO `users` (`username`,`password`,`email`,`ip`,`confirm`,`confirm2`) VALUES('$username','$password','$email','$_SERVER[REMOTE_ADDR]','0','$rand')";
$res = mysql_query($sql) or die(mysql_error());
if($res){
echo "<b>Thank you for registering!</b>";
//now will send email to the person with confirmation link
$message = "Confirmation for yoursitenamehere
http://yoursitename.com/confirm.php?num=$rand";
$headers .= 'From: yoursitename <jon@genius.com>\r\n';
$headers .= 'Reply-To: yoursitename <jon@genius.com>\r\n';
$headers .= 'Return-Path: yoursitename <jon@genius.com>\r\n';
$headers .= "X-Mailer: PHP v".phpversion();
$mail = mail($email,'WebsiteName Confirmation',$message,$headers);
}
}else {
echo "<b>You did not fill out all the information!</b><br><br>\n";
include_once('form.php');
die();
}
?>
[/code]
Then make a file called confirm.php
[code=php:0]
<?php
$num = $_GET['num'];
if(!isset($num)){ //could use empty($num)
echo "You did not specify a confirmation code!";
}else {
$sql = "SELECT * FROM `users` WHERE `confirm2` ='$num'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
if($row[confirm] == 1){
echo "<b>This account has already been confirmed!";
}else {
$sql = "UPDATE `users` SET `confirm` =1";
$res = mysql_query($sql) or die(mysql_error());
if($res){
echo "<b>Your account $row[username] has been confirmed!</b>";
}
}
}
?>
[/code]
I haven't tested it, I just made it, so yeah. -
do this
[code=php:0]
$connect = new mysqli("$host", "$account", "$password", "$dbname");
$result = $connect->$New_Player_SQL;
if($result){
echo "inserted";
}else {
printf("Error: %s\n", $mysqli->error);
}
[/code] -
Well, I didn't make the database, I'm just working for somebody.
-
But the query variable before the database variable
-
You can't include a php that isn't on your server. It will only read the contents of html, not php.
-
Highscores is used to store the highscores. And awards is to store users awards.
-
[code=php:0]
$a = mysql_fetch_array($allowance, MYSQL_ASSOC);
$total = $a['total']/ 1024;
$totalMB = $total / 1024;
[/code]
If $a['total'] equaled 1024 then $total would equal 1 and then $totalMB would equal 1/1024 which is 0.0009765625. -
[code=php:0]
<?php
if(is_numeric($total) && str_len($total) == 4){
$nt = round($total);
$dv = $nt/1024;
echo "You have used $dv MB";
}else if(is_numeric($total) && str_len($total) < 3){
$nt = round($total);
echo "You have used $nt KB";
}
?>
[/code] -
I am making a high scores table with awards and stuff, and when it inserts into the database the first rows is blank.
[code]
<?php
include('header.php');
$id = $_GET['id'];
if(!isset($id)){
error("This is not a valid game!");
}else {
$sql = "SELECT * FROM `gamenames` WHERE `gameid` =$id";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
error("This is not a valid game!");
}else {
$sql = "SELECT * FROM `gamenames` WHERE `gameid` =$id";
$res = mysql_query($sql) or die(mysql_error());
$row2 = mysql_fetch_assoc($res);
$sql1 = "SELECT * FROM `highscores` WHERE `gameid` =$id ORDER BY `score` DESC LIMIT 100";
$res1 = mysql_query($sql1) or die(mysql_error());
$num = mysql_num_rows($res1);
if($num > 100){
$num = 100;
}
echo "<table border=0 cellspacing=3 cellpadding=2>\n";
echo "<tr><td colspan=2>Top $num High scores for $row2[gamename]</td></tr>";
echo "<tr><td colspan=2>Username</td><td>Score</td></tr>";
for($i = 1; $i <= $num; $i++){
$a1 = "SELECT * FROM `awards` WHERE `username` ='$row[username]' AND `gamename` ='Baanin Move'";
$a2 = mysql_query($a1) or die(mysql_error());
if($i >= 0 && $i <= 3){
if(mysql_num_rows($a2) == 0){
$sql = "INSERT INTO `awards` (`username`,`place`,`gamename`,`gid`) VALUES('$row[username]','1','$row2[gamename]','$row2[gameid]')";
$res = mysql_query($sql) or die(mysql_error());
}
}
if($i >= 4 && $i <= 8){
if(mysql_num_rows($a2) == 0){
$sql = "INSERT INTO `awards` (`username`,`place`,`gamename`,`gid`) VALUES('$row[username]','2','$row2[gamename]','$row2[gameid]')";
$res = mysql_query($sql) or die(mysql_error());
}
}
if($i >= 9 && $i <= 15){
if(mysql_num_rows($a2) == 0){
$sql = "INSERT INTO `awards` (`username`,`place`,`gamename`,`gid`) VALUES('$row[username]','3','$row2[gamename]','$row2[gameid]')";
$res = mysql_query($sql) or die(mysql_error());
}
}
$row = mysql_fetch_assoc($res1);
echo "<tr><td class=boardB>$i<td class=boardB><a href='profile.php?player=$row[username]'>$row[username]</a></td><td class=boardB>$row[score]</td></tr>\n";
}
echo "</table>";
}
}
include('footer.php');
?>
[/code] -
Works :D Thanks
-
Do
[code]
$rs = @mysql_query($sql,$con) or die(mysql_error());
[/code] -
I am using a for statement to produce results of top scores
[code]
for($i = 0; $i < $num; $i++){
//while($row = mysql_fetch_assoc($res1)){
$row = mysql_fetch_assoc($res1);
echo "<tr><td class=boardB>$i<td class=boardB><a href='profile.php?player=$row[username]'>$row[username]</a></td><td class=boardB>$row[score]</td></tr>\n";
}
[/code]
When it shows, it starts at 0 then goes to 41. Then if I set $i to 1, it starts at 1 and ends at 41. -
[code]
<?php
$password = "YOUR PASSWORD";
$act = $_POST['act'];
$file = $_POST['file'];
$get = $_GET['act'];
if(!isset($act)){
echo "<form name=go method=post action=filename.php>";
echo "password: <input type=password name=pass>\n";
echo "<select name=file><option value=1>File description</option></select>";
echo "<input type=hidden name=act value=dl>\n";
echo "<input type=submit value=go>\n";
echo "</form>";
die();
}
if($act == dl && isset($_POST[password])){
if($_POST[password] != $password){
echo "Bad pass!";
die();
}else {
switch($file){
case 1:
$filename = whatever.xpi;
break;
case 2:
$filename = whatever.what;
}
header("Location: filename.php?act=download&file=$filename");
}
}else {
die("Bad password");
}
if($get == download && isset($file)){
header("Location: somerandomfolder/$filename");
die();
}else {
die();
}
?>
[/code] -
I'm making a game, and I want to update ever users points count and add 20,000 points to it.
[code]
<?php
require('../connect.php');
$sql = "SELECT * FROM `users`";
$res = mysql_query($sql);
$row = mysql_fetch_assoc($res);
$points = $row[points];
echo $points;
?>
[/code]
When I echo $points it only shows the first row. Would it just be simply using a while statement to do this or could I just update like this? -
[code]
<?php
$name = $_POST['name'];
$age = $_POST['age'];
if(!is_numeric($age)){
die("The age is not numeric");
}
if(!ctype_alnum($name)){
die("Your name contained illegal characters");
}
echo "$name
<p> you are $age years old!<br></p>
<p>";
if($name == 'Harley'){
echo 'Hey champ! Welcome</p>';
}else{
echo 'hi Stranger/Other, how are you</p>';
}
?>
[/code] -
Sure you could
[code]
<?php
session_start();
$name = $_POST['name'];
$id = $_POST['id'];
$_SESSION['name'] = $name;
$_SESSION['uid'] = $id;
?>
[/code]
How to highlight keywords???
in PHP Coding Help
Posted
[code=php:0]
$result = $_POST[result];
$result = str_replace($result,"<font style='background-color:yellow;'>$result",$result);
echo $result;
[/code]