Jump to content

Database modification script help


BrandonLayton

Recommended Posts

My first real attempt to mess with MySql.

Keep getting a syntax error and I am quite confused.

Error:

Parse error: syntax error, unexpected '}' in /home/a8152576/public_html/MemberSystem/install1.php on line 68

 

Here is my php code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <h2><center>Fill in the following info properly	to install required databases.</center></h2>
  <p>
    <label>Host:
      <input type="text" name="host" id="host" />
    </label>
  </p>
  <p>
    <label>Database User:
      <input type="text" name="dbUser" id="dbUser" />
    </label>
  </p>
  <p>
    <label>Database Password:
      <input type="text" name="dbPass" id="dbPass" />
    </label>
  </p>
  <p>
    <label>Desired Admin Username:
      <input type="text" name="adminName" id="adminName" />
    </label>
  </p>
  <p>
    <label>Desired Admin Password:
      <input type="text" name="adminPass" id="adminPass" />
    </label>
  </p>
  <p>
    <label>Email:
      <input type="text" name="adminEmail" id="adminEmail" />
    </label>
  </p>
  <p>
    <input type="submit" name="submitBtn" id="submitBtn" value="Submit" />
  </p>
</form>
<?php
if(isset($_POST['submit'])){
$hostName = $_POST['host'];
$dbUserName = $_POST['dbUser'];
$dbPassword = $_POST['dbPass'];
$adminUserName = $_POST['adminName'];
$adminPassword = $_POST['adminPass'];
$email = $_POST['adminEmail'];

$sqlLink = mysql_connect('$hostName','$dbUserName','$dbPassword');
if(!$sqlLink){
	die('Could not connect: ' .mysql_error());
	mysql_close();
} else {
	$queryCreate = 'CREATE DATABASE member_db';
	echo 'Connected successfully!';
	if(mysql_query($queryCreate,$link)){
		echo 'Created database!';
		mysql_select_db('member_db');
		$createAdminTable = "CREATE TABLE " .$adminUserName. " (`secLvl` tinyint(1) default NOT NULL,`rank` tinyint(2) default NOT NULL,`username` varChar(32) NOT NULL UNIQUE,`password` varChar(32) NOT NULL,`email` varChar(32) NOT NULL UNIQUE";
		$insertAdminInfoQuery = "UPDATE " .$adminUserName. " SET `secLvl` = '5', `rank` = '10', `username` = '$adminUserName', `password` = '$adminPassword', `email` = '$email' WHERE '$adminUserName' LIMIT 1";
		mysql_query($createAdminTable) or die("ERROR: " .mysql_error());
		mysql_query($insertAdminInfoQuery) or die("ERROR: " .mysql_error())
	} else {
		echo 'Error: '.mysql_error();
	}
}
}
?>
</body>
</html>

 

You can even see the error on this web page directly: http://www.ptcptc.info/MemberSystem/install1.php

 

Thanks,

Brandon :)

Link to comment
Share on other sites

Wow. Haha thanks.

I feel a little stupid now but it works :)

 

edit:

Well now it shows up, but when I try to submit everything just clears. Nothing echos to confirm or deny that it works and now database is created. So i am a little confounded :P

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Member System Install</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <h2><center>Fill in the following info properly	to install required databases.</center></h2>
  <p>
    <label>Host:
      <input type="text" name="host" id="host" />
    </label>
  </p>
  <p>
    <label>Database User:
      <input type="text" name="dbUser" id="dbUser" />
    </label>
  </p>
  <p>
    <label>Database Password:
      <input type="text" name="dbPass" id="dbPass" />
    </label>
  </p>
  <p>
    <label>Desired Admin Username:
      <input type="text" name="adminName" id="adminName" />
    </label>
  </p>
  <p>
    <label>Desired Admin Password:
      <input type="text" name="adminPass" id="adminPass" />
    </label>
  </p>
  <p>
    <label>Email:
      <input type="text" name="adminEmail" id="adminEmail" />
    </label>
  </p>
  <p>
    <input type="submit" name="submitBtn" id="submitBtn" value="Submit" />
  </p>
</form>
<?php
if(isset($_POST['submit'])){
$hostName = $_POST['host'];
$dbUserName = $_POST['dbUser'];
$dbPassword = $_POST['dbPass'];
$adminUserName = $_POST['adminName'];
$adminPassword = $_POST['adminPass'];
$email = $_POST['adminEmail'];

$sqlLink = mysql_connect('$hostName','$dbUserName','$dbPassword');
if(!$sqlLink){
	die('Could not connect: ' .mysql_error());
	mysql_close();
} else {
	$queryCreate = 'CREATE DATABASE member_db';
	echo 'Connected successfully!';
	if(mysql_query($queryCreate,$link)){
		echo 'Created database!';
		mysql_select_db('member_db');
		$createAdminTable = "CREATE TABLE " .$adminUserName. " (`secLvl` tinyint(1) default NOT NULL,`rank` tinyint(2) default NOT NULL,`username` varChar(32) NOT NULL UNIQUE,`password` varChar(32) NOT NULL,`email` varChar(32) NOT NULL UNIQUE";
		$insertAdminInfoQuery = "UPDATE " .$adminUserName. " SET `secLvl` = '5', `rank` = '10', `username` = '$adminUserName', `password` = '$adminPassword', `email` = '$email' WHERE '$adminUserName' LIMIT 1";
		mysql_query($createAdminTable) or die("ERROR: " .mysql_error());
		mysql_query($insertAdminInfoQuery) or die("ERROR: " .mysql_error());
	} else {
		echo 'Error: '.mysql_error();
	}
}
} 
?>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.