Register | Login | |||||
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
| |
0 users currently in Programming. |
Acmlm's Board - I3 Archive - Programming - PHP Error | New poll | | |
Add to favorites | Next newer thread | Next older thread |
User | Post | ||
Dario Red Paragoomba Since: 06-08-06 From: USA Virginia Last post: 6433 days Last view: 6433 days |
| ||
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. |
|||
Tatrion <_<; Since: 11-17-05 Last post: 6427 days Last view: 6426 days |
| ||
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 Red Paragoomba Since: 06-08-06 From: USA Virginia Last post: 6433 days Last view: 6433 days |
| ||
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. | |||
Randy53215 Melon Bug Since: 11-17-05 From: Greenfield, Wisconsin (U.S.A) Last post: 6427 days Last view: 6426 days |
| ||
Why not just use PHPMyAdmin? | |||
Metal Man88 Gold axe It appears we have been transported to a time in which everything is on fire! Since: 11-17-05 Last post: 6426 days Last view: 6426 days |
| ||
Yeah, use PHPMyadmin. It's insanely powerful. Even people like me who don't know PHP can use it to continue PHP databases effectively. | |||
Dario Red Paragoomba Since: 06-08-06 From: USA Virginia Last post: 6433 days Last view: 6433 days |
| ||
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. |
|||
Randy53215 Melon Bug Since: 11-17-05 From: Greenfield, Wisconsin (U.S.A) Last post: 6427 days Last view: 6426 days |
| ||
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. |
Add to favorites | Next newer thread | Next older thread |
Acmlm's Board - I3 Archive - Programming - PHP Error | | |