Jump to content

Help with code.


Oedwards

Recommended Posts

I am trying to get this script to run but i get the error

 

Parse error: syntax error, unexpected $end in /home/pdgeman/public_html/Register.php on line 18

 

I have tried all sorts of stuff.. please help me!

 

Here is the code:

<?
$DBhost = "localhost";
$DBuser = "";
$DBpass = "";
$DBName = "";
$table  = "";
$uname = $_POST['uname'];
$pass = $_POST['pass']; 

mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName");

$query = mysql_num_rows(mysql_query("SELECT * FROM usernames WHERE username='$uname'"));
if(username == '$uname');
    {
    die();
$result = mysql_query($query);
?>

Link to comment
https://forums.phpfreaks.com/topic/184504-help-with-code/
Share on other sites

<?
$DBhost = "localhost";
$DBuser = "";
$DBpass = "";
$DBName = "";
$table  = "";
$uname = $_POST['uname'];
$pass = $_POST['pass']; 

mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName");

$query = mysql_num_rows(mysql_query("SELECT * FROM usernames WHERE username='$uname'"));
if(username == '$uname')
die();
else
$SQL = "INSERT INTO $table (Username, Password) VALUES ('$uname' , '$pass')";
$result = mysql_query($query);
?>

 

this is my current code, it doesn't display an error but it doesn't add anything to the database either... I am so lost.

 

Someone told me this code wouldn't work but didn't explain why.. does anybody know?

Link to comment
https://forums.phpfreaks.com/topic/184504-help-with-code/#findComment-974003
Share on other sites

I would just like to say logical errors right code would be

 

<?php
$DBhost = "localhost";
$DBuser = "";
$DBpass = "";
$DBName = "";
$table  = "";


mysql_connect($DBhost,$DBuser,$DBpass) or die('Cannot connect to database');
mysql_select_db($DBName) or die('Cannot select database');

$uname = isset($_POST['uname']) ? mysql_real_escape_string($_POST['uname']) : '';
$pass = isset($_POST['pass']) ? mysql_real_escape_string($_POST['pass']) : '';


$result = mysql_query("SELECT * FROM usernames WHERE username='$uname'") or die('Cannot Execute Query:'.mysql_error());
$rows = mysql_num_rows($result);
if($rows > 0) {
   die('Username already exists');
}
else {
   $query = "INSERT INTO $table (Username, Password) VALUES ('$uname' , '$pass')";
   $result = mysql_query($query);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/184504-help-with-code/#findComment-974008
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.