user defined table and fields - unfinished
Posted: Mon Jun 09, 2003 9:36 pm
Hello all,
I am quite new to PHP and kinda suck at it. I have just thrown together this code that I am using for my father's company to help their company aid other companies.
In my code, I am trying to open the server, then check if the table inputted already exists and if it doesnt, create the new table in mysql.
Next, I am taking the inputted data from the user and storing it on the database with the newly made table and its fields.
The $storenumber variable is used as an input from the user and also for means of creating the new table. I also want to use the newly inputted $storenumber as a field in mysql. I seem to be plagued with errors. I was able to get the code working a while back, but it didnt create a table or any of the fields. I think i screwed it up even more since then.
Code is as follows:
<HTML>
<body>
<form method="post" action="<?php print $PHP_SELF ?>">
<BR>Enter the Taco Bell Store Number
<BR><input type="text" name="storenumber">
<BR>Enter Your Name
<BR><input type="text" name="name">
<BR>Enter The Size
<BR><input type="text" name="size">
<BR>Enter Your Phone Number
<BR><input type="text" name="phone">
<input type="submit" value="Load Store">
<input type="reset">
</form>
<?php
if( isset ( $storenumber) isset ( $name) isset ( $size) isset ( $phone)) {
$user = "oprods";
$pass = "breakin";
$db = "storedbtest";
$link = mysql_connect("localhost", "$user", "$pass");
if ( ! $link ) {
$dberror = "Couldn't connect to MySQL server";
return false;
mysql_select_db($db);
}
$tbl_exists = mysql_query("DESCRIBE $storenumber");
if ($tbl_exist) {
print "Store Already exists";
} elseif (! $tbl_exist) {
mysql_query("CREATE TABLE $storenumber (storenumber INT, name VARCHAR, size VARCHAR, phone
VARCHAR)");
//query goes here
print "Store database Created";
} else {
printf ("Error creating database: %s\n", mysql_error());
}
if ( ! mysql_select_db( $db, $link ) ) {
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO $storenumber ( storenumber, name, size, phone )//table stuff
values( '$storenumber', '$name', '$size', '$phone')";
if ( ! mysql_query( $query, $link ) ) {
$dberror = mysql_error();
return false;
}else {
mysql_query($query, $link);
print "<BR>Database info complete";
}
?>
</body>
</html>
Thank you,
and please help the new programmer in dispair.
STC7OUTLAW
I am quite new to PHP and kinda suck at it. I have just thrown together this code that I am using for my father's company to help their company aid other companies.
In my code, I am trying to open the server, then check if the table inputted already exists and if it doesnt, create the new table in mysql.
Next, I am taking the inputted data from the user and storing it on the database with the newly made table and its fields.
The $storenumber variable is used as an input from the user and also for means of creating the new table. I also want to use the newly inputted $storenumber as a field in mysql. I seem to be plagued with errors. I was able to get the code working a while back, but it didnt create a table or any of the fields. I think i screwed it up even more since then.
Code is as follows:
<HTML>
<body>
<form method="post" action="<?php print $PHP_SELF ?>">
<BR>Enter the Taco Bell Store Number
<BR><input type="text" name="storenumber">
<BR>Enter Your Name
<BR><input type="text" name="name">
<BR>Enter The Size
<BR><input type="text" name="size">
<BR>Enter Your Phone Number
<BR><input type="text" name="phone">
<input type="submit" value="Load Store">
<input type="reset">
</form>
<?php
if( isset ( $storenumber) isset ( $name) isset ( $size) isset ( $phone)) {
$user = "oprods";
$pass = "breakin";
$db = "storedbtest";
$link = mysql_connect("localhost", "$user", "$pass");
if ( ! $link ) {
$dberror = "Couldn't connect to MySQL server";
return false;
mysql_select_db($db);
}
$tbl_exists = mysql_query("DESCRIBE $storenumber");
if ($tbl_exist) {
print "Store Already exists";
} elseif (! $tbl_exist) {
mysql_query("CREATE TABLE $storenumber (storenumber INT, name VARCHAR, size VARCHAR, phone
VARCHAR)");
//query goes here
print "Store database Created";
} else {
printf ("Error creating database: %s\n", mysql_error());
}
if ( ! mysql_select_db( $db, $link ) ) {
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO $storenumber ( storenumber, name, size, phone )//table stuff
values( '$storenumber', '$name', '$size', '$phone')";
if ( ! mysql_query( $query, $link ) ) {
$dberror = mysql_error();
return false;
}else {
mysql_query($query, $link);
print "<BR>Database info complete";
}
?>
</body>
</html>
Thank you,
and please help the new programmer in dispair.
STC7OUTLAW