PHP Help?

I

IzRaPiDz

Guest
I'v decided to do a little php but i'm getting an error. I'v tried looking on the internet but no look.

Ok, i think i'm having a little problem connecting to the database, but i'v checked and everything seems to be alright.
PHP:
<?php
 
$username = $_POST['username'];
$password = $_POST['passowrd'];
 
if ($username&&$password)
{
 
$connect = mysql_connect("localhost","root","") or die("Couldn't Connect.")
msql_select_db("phplogin") or die("Couldn't find Db");
 
}
else
    die("Please enter the Username and Password.");
 
 
?>
When i login, i get "Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\login.php on line 10". Any ideas? thanks!
 

3lionz

Legions Developer
http://pastebin.com/AtpRAL1J

Couple of things improved:
Changed "passowrd" to "password".

On $connect line you forgot the ";".
Also removed single quotes (') from inside the strings by changing "couldn't" to could not. You need to use a backslash (\) before a single quote in a string, or it may cause an error.

For example
msql_select_db("phplogin") or die("Couldn\'t find Db");

(I think)
 
I

IzRaPiDz

Guest
http://pastebin.com/AtpRAL1J

Couple of things improved:
Changed "passowrd" to "password".

On $connect line you forgot the ";".
Also removed single quotes (') from inside the strings by changing "couldn't" to could not. You need to use a backslash (\) before a single quote in a string, or it may cause an error.

For example
msql_select_db("phplogin") or die("Couldn\'t find Db");

(I think)
Lionz, you are ze best! Fixed my problem. Thankyou ever so much mate!
 
I

IzRaPiDz

Guest
Oh one more thing, when i log in i get "Fatal error: Call to undefined function msql_select_db() in C:\xampp\htdocs\login.php on line 10", i have no idea why i'm getting this one...
 

Fissurez

Puzzlemaster
Oh one more thing, when i log in i get "Fatal error: Call to undefined function msql_select_db() in C:\xampp\htdocs\login.php on line 10", i have no idea why i'm getting this one...

well, i would start looking at line 10. what is at line 10?
 

Triad

Legions Developer
I don't recommend you trying to write your own login system with no coding experience unless you are willing to put in a ridiculous amount of hours to learn everything. Your code is extremely insecure right now, and you're probably unaware of that fact. Download something that's already coded by professionals, and modify it to your needs (like phpBB3). Let me know if you have any questions.
 
I

IzRaPiDz

Guest
I don't recommend you trying to write your own login system with no coding experience unless you are willing to put in a ridiculous amount of hours to learn everything. Your code is extremely insecure right now, and you're probably unaware of that fact. Download something that's already coded by professionals, and modify it to your needs (like phpBB3). Let me know if you have any questions.
Thanks, i'v got phpBB3 now and the reason i was making my own because i was following a tutorial so maybe i get to know php a little bit more.
 

Armageddon

Teapot
oh oh oh we have people here that know php.. I've got a hell of a bug with my join us script on my site.
The problem is the form data should be sent with the sendpm function to the leader or co-leaders PM inbox, sadly it does not. This is a heavily modified and translated version of ilch CMS (MilkCMS-German).
I know the db query called in sendpm has the word titel instead of title, but the row is named titel so it's not an error.

First one who fixes me up get a handy, my eyes hurt from working on it too long. Maybe a fresh set of eyes will see something i don't.


The application HTML data. {_lang_xxxxx} points to a language file, no errors with it.
HTML:
<center><table border="0" width="95%" cellpadding="3" cellspacing="0">
<tr>
<td>
<form action="index.php?joinus" method="POST">
<tr><td class="Chead" height="30"><label style="float:left; width:200px; ">{_lang_joininfo}</label>{_lang_plsfilloutallfields}</td></tr>
    <tr><td class="Cmite" height="30"><label style="float:left; width:200px; ">{_lang_name}</label><input name="name"{readonly} maxlength="15" value="{name}" /></td></tr>
    <tr><td class="Cnorm" height="30"><label style="float:left; width:200px; ">{_lang_age}</label><input type="text" name="age" value="{age}" /></td></tr>
    <tr><td class="Cmite" height="30"><label style="float:left; width:200px; ">{_lang_realname}</label><input type="text" name="realname" value="{realname}" /></td></tr>
    <tr><td class="Cnorm" height="30"><label style="float:left; width:200px; ">{_lang_hometown}</label><input type="text" name="hometown" value="{hometown}" /></td></tr>
    <tr><td class="Cmite" height="30"><label style="float:left; width:200px; ">{_lang_icqnumber}</label><input type="text" name="icqnumber" value="{icqnumber}" /></td></tr>
    <tr><td class="Cnorm" height="30"><label style="float:left; width:200px; ">{_lang_mail}</label><input type="text" name="mail" value="{mail}" /></td></tr>
    <tr><td class="Cnorm" height="30"><label style="float:left; width:200px; ">{_lang_skill}?</label><select name="skill">{skill}</select></td></tr>
    <tr><td class="Cmite" height="30"><label style="float:left; width:200px; ">{_lang_squad}</label><select name="squad">{squad}</select /></td></tr>
    <tr><td class="Cnorm" height="30"><label style="float:left; width:200px; ">{_lang_favmap}</label><input type="text" name="favmap" value="{favmap}" /></td></tr>
    <tr><td class="Cmite" height="30"><label style="float:left; width:200px; ">{_lang_ground}</label><textarea name="ground" cols="40" rows="5">{ground}</textarea></td></tr>
    <tr><td class="Chead" height="30"><label style="float:left; width:200px; ">{_lang_rules}</label>&nbsp;&nbsp;<input type="checkbox" name="rules" value="{_lang_yes}" />&nbsp;&nbsp; {_lang_rulzreaded}</td></tr>
    <tr><td class="Chead" height="30"><label style="float:left; width:200px; ">&nbsp;</label><input type="submit" name="sub" value="{_lang_formsub}" /></td></tr>
</form></td></tr>
</table></center>

the joinus.php file.

PHP:
<?php
 
defined ('main') or die ( 'no direct access' );
//-----------------------------------------------------------|
 
$title = $allgAr['title'].' :: Joinus';
$hmenu = 'Joinus';
$design = new design ( $title , $hmenu );
$design->header();
 
if ( 0 == db_count_query("SELECT COUNT(*) FROM prefix_groups WHERE show_joinus = 1") ) {
    echo $lang['noteamthere'];
    $design->footer();
    exit ();
}
 
$skill_ar = array (
  1 => $lang['verybad'],
  2 => $lang['bad'],
    3 => $lang['middle'],
    4 => $lang['good'],
    5 => $lang['verygood'],
);
 
$far = array (
        'name',
        'skill',
        'icqnumber',
        'favmap',
        'mail',
        'age',
        'hometown',
        'squad',
        'ground',
    'rules'
    );
$x = 0;
foreach ($far as $v) {
    if (!empty($_POST[$v])) {
        $$v = escape($_POST[$v], 'string');
        $x++;
    } else {
        $$v = '';
    }
}
 
$xname = escape_nickname($name);
$ch_name = false;
if (loggedin()) {
  $ch_name = true;
} elseif (isset($_POST['sub']) AND $name == $xname AND !empty($name)
  AND 0 == db_result(db_query("SELECT COUNT(*) FROM prefix_user WHERE name = BINARY '".$name."'"),0)) {
  $ch_name = true;
}
 
if (count($far) <> $x OR $ch_name == false OR !chk_antispam('joinus')) {
    $tpl = new tpl ( 'joinus.htm' );
    $skill  = arlistee ($skill, $skill_ar);
    $squad  = '<option value="0">choose</option>';
  $squad .= dblistee ($squad, "SELECT id,name FROM prefix_groups WHERE show_joinus = 1 ORDER BY pos");
  if (loggedin()) { $name = $_SESSION['authname']; }
  foreach($far as $v) {
        if ($x > 0 AND empty($_POST[$v])) {
            echo 'missing: '.$lang[$v].'<br />';
        }
        $tpl->set ($v, $$v);
    }
  if ($x > 0 AND $name != $xname) {
    echo $lang['wrongnickname'].'<br />';
  } elseif ($x > 0 AND $ch_name == false) {
    echo $lang['namealreadyinuse'].'<br />';
  }
  $name = $xname;
  $tpl->set('readonly', (loggedin()?' readonly': ''));
    $tpl->out(0);
    if ($allgAr['joinus_rules'] != 1) {
    $tpl->out(1);
  } else {
    $rules = '<h2>'.$lang['rules'].'</h2>';
    $rerg = db_query('SELECT zahl,titel,text FROM `prefix_rules` ORDER BY zahl');
    while ($rrow = db_fetch_row($rerg)) {
            $rules .= '<table width="100%" border="0" cellpadding="5" cellspacing="1" class="border">';
            $rules .= '<tr class="Cmite"><td><b>&sect;'.$rrow[0].'. &nbsp; '.$rrow[1].'</b></td></tr>';
            $rules .= '<tr class="Cnorm"><td>'.bbcode($rrow[2]).'</td></tr>';
            $rules .= '</table><br />';
    }
    $rules .= '<input type="checkbox" name="rules" value="'.$lang['yes'].'" />'.str_replace(array('<a target="_blank" href="index.php?rules">','</a>'),'',$lang['rulzreaded']).'<br />'; 
    $tpl->set_out('RULES',$rules,2);
  }
  $tpl->set('ANTISPAM', get_antispam('joinus', 100));
  $tpl->out(3);
} else { # eintragen
 
  $name = $xname;
    $userreg = $lang['no'];
  if (!loggedin() AND $allgAr['forum_regist'] <> 0) {
    $x = user_regist ($name,$mail,genkey(8));
    $userreg = $lang['yes'];
  }
 
  db_query("INSERT INTO prefix_usercheck (`check`,name,datime,ak,groupid) VALUES ('".genkey(8)."','".$name."',NOW(),4,$squad)");
 
  $squad = escape($squad, 'integer');
    $abf  = "SELECT `mod1`, `mod2`, `mod4`, name FROM prefix_groups WHERE id = ".$squad;
    $erg  = db_query($abf);
    $row  = db_fetch_assoc($erg);
  $rulz  = (isset($_POST['rules'])?$_POST['rules']:$lang['no']);
  $skill = $skill_ar[$skill];
 
  # bitte in der richtigen reihenfolge angeben, sonst das nicht gehen tun, kann.
  $mailtxt = sprintf ($lang['joinusprivmsg'],
    $name,
    $row['name'],
    $skill,
    $mail,
    $hometown,
    $age,
    $icqnumber,
    $favmap,
    $ground,
    $rulz,
    $userreg
  );
 
  # pm an den leader
    sendpm ($_SESSION['authid'], $row['mod1'], 'Joinus Anfrage',$mailtxt, -1);
  # Wenn Co Leader != Leader
    if ($row['mod2'] != $row['mod1']){
        sendpm ($_SESSION['authid'], $row['mod2'], 'Joinus Anfrage',$mailtxt, -1);
    }
    if ($row['mod4'] != $row['mod1'] AND $row['mod2'] != $row['mod4']){
        sendpm ($_SESSION['authid'], $row['mod4'], 'Joinus Anfrage',$mailtxt, -1);
    }
 
    if (!loggedin() AND $allgAr['forum_regist'] <> 0) {
        echo $lang['amailhasbeensenttoyouwithmailandpass'].'<br /><br />';
  }
  echo sprintf($lang['leaderofxalert'], $row['name']);
}
$design->footer();
?>

The function to send this info to a pm inbox.

PHP:
function sendpm ($sid,$eid,$ti,$te,$status = 0) {
  if (is_array($eid)) {
      db_query("INSERT INTO `prefix_pm` (`sid`,`eid`,`time`,`titel`,`txt`,`status`) ".
      "SELECT  ".$sid.",`prefix_user`.`id`,'".time()."','".$ti."','".$te."',".$status." FROM `prefix_user` WHERE `prefix_user`.`id` IN (" . implode(',', $eid) . ")");
  }
  else {
      //db_query("INSERT INTO `prefix_pm` (`sid`, `eid`, `time`, `titel`, `txt`, `status`) VALUES (".$sid.",".$eid.",'".time()."','".$ti."','".$te."', -1)");
    db_query("INSERT INTO `prefix_pm` (`sid`,`eid`,`time`,`titel`,`txt`,`status`) VALUES (".$sid.",".$eid.",'".time()."','".$ti."','".$te."',".$status.")");
  }
  }
 

Triad

Legions Developer
You need to debug your code with a debugger. I've used vim in the past, but that was on Ubuntu. You basically need to be able to set break points and step line by line through your code so you can see exactly what is happening. I don't have your database so I can't really debug this for you. I'm assuming you aren't getting errors so there is a logical error. You need to inspect the values of all those variables, such as the user's name/id to make sure they are correct before you query the database.
 
Top