(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-17-24 11:58 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - PHP Error
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
Randy53215
Posts: 711/726
How skilled would you say you are? I hope you know how to secure things really well.

I still think PHPMyAdmin is better, practicing skills or not... I will look into this code when I am not half asleep tohugh.
Dario
Posts: 56/57
Well... how do you create a database in PHPMyAdmin?
Besides, the point of this script isn't to be useful; I want to exercise my mad PHP SKILLZ.
Metal Man88
Posts: 657/701
Yeah, use PHPMyadmin. It's insanely powerful. Even people like me who don't know PHP can use it to continue PHP databases effectively.
Randy53215
Posts: 710/726
Why not just use PHPMyAdmin?
Dario
Posts: 55/57
Ok, I fixed that, now it just says either a syntax error or it doesn't make a table at all... Better go check my syntax.
Tatrion
Posts: 2456/2467
I believe all you need to do is remove the single quotes from $_POST['value1'] in line 24. Removing the subsequent single quotes from the similar lines right after it will prevent further problems from happening.
Dario
Posts: 54/57
Hey guys, I was coding a 'quick' PHP script that would allow one to create a database in MySQL based on the value of a certain text-field. I finished that, and decided to make one that could create a table in a database specified from a drop-down menu. I got to the point of being able to make a table, but then I realized that tables need values, so I did that. However, when I tried to run it, it gave me this error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in blahblahblah\newmysqldb.php on line 24.
Here is my code (yes I used someone else's code for listing all MySQL Databases):

<?php
$con = mysql_connect("hostname","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

// Create database
if ($_POST['newdb'] != "") {
if (mysql_query("CREATE DATABASE $_POST[newdb]",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
}

if ($_POST['ttable'] != "" && $_POST['stable'] != "") {
mysql_select_db($_POST['stable'],$con);
if (mysql_query(
"CREATE TABLE $_POST[ttable] (
$_POST['value1'], // this is line 24!
$_POST['value2'],
$_POST['value3'],
$_POST['value4'],
$_POST['value5'],
$_POST['value6'],
$_POST['value7'],
$_POST['value8'])"
)) {
echo 'Table created.';
} else {
echo 'Error creating table: ' . mysql_error();
}
}

?>
<h3>Create a database:</h3>
<form method="post" action="newmysqldb.php">
Name: <input type="text" name="newdb" />
<input type="submit" value="Make Database!" name="submit" />
<h3>Create a table</h3>
Name: <input type="text" name="ttable" /><br />
With values: <input type="text" name="value1" /><input type="text" name="value2" /><input type="text" name="value3" /><input type="text" name="value4" /><input type="text" name="value5" /><input type="text" name="value6" /><input type="text" name="value7" /><input type="text" name="value8" /><br />
In database: <select name="stable">
<option value="" SELECTED>Select a database</option>
<?php
// FILENAME: LIST_MYSQL_DBS.PHP
// ----------------------------

define( 'NL', "\n" );
define( 'TB', ' ' );

// connecting to MySQL.
$conn = @mysql_connect( 'localhost', 'root', 'legionare103' )
or die( mysql_errno().': '.mysql_error().NL );

// attempt to get a list of MySQL databases
// already set up in my account. This is done
// using the PHP function: mysql_list_dbs()
$result = mysql_list_dbs( $conn );

// Output the list

///* USING: mysql_fetch_object()
// ---------------------------
while( $row = mysql_fetch_object( $result ) ):
echo '<option value="' . $row->Database . '">'.$row->Database.'</option>';
endwhile;
//*/

/* USING: mysql_fetch_row()
// ------------------------
while( $row = mysql_fetch_row( $result ) ):
echo TB.'<li>'.$row[0].'</li>'.NL;
endwhile;
//*/

/* USING: mysql_fetch_assoc()
// --------------------------
while( $row = mysql_fetch_assoc( $result ) ):
echo TB.'<li>'.$row['Database'].'</li>'.NL;
endwhile;
//*/

// Free resources / close MySQL Connection
mysql_free_result( $result );
mysql_close( $conn );
?>
</select>
</form>
?>

Any help would be greatly appreciated.
Acmlm's Board - I3 Archive - Programming - PHP Error


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.002 seconds; used 352.40 kB (max 395.22 kB)