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
https://forums.phpfreaks.com/topic/220776-database-modification-script-help/
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>

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.