Cannibal_Monkey Posted January 15, 2007 Share Posted January 15, 2007 We are having a problem with our program we have. The program is at the bottom of the post. Anyway, we are trying to create a table with this code:[code] CREATE TABLE a {1 VARCHAR(3),2 VARCHAR(3),3 VARCHAR(3),4 VARCHAR(3),5 VARCHAR(3),PRIMARY KEY(1) }[/code]And we are getting this error: [quote]Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{ 1 VARCHAR(3), 2 VARCHAR(3), 3 VARCHAR(3), 4 VARCHAR(3), 5 VARCHAR(3), PR' at line 1[/quote]We can't figure out what the problem is. The code we are using for the program is here. Sorry for the slopiness.[code]<html> <head><title>SQL Query Sender</title></head> <body> <?php $host="localhost"; $user="root"; $password=""; /* Section that executes query */ if(@$_GET['form'] == "yes") { mysql_connect($host,$user,$password); mysql_select_db($_POST['database']); $query = stripSlashes($_POST['query']); $result = mysql_query($query); echo "Database Selected: <b>{$_POST['database']}</b><br> Query: <b>$query</b><h3>Results</h3><hr>"; if($result == 0) echo "<b>Error ".mysql_errno().": ".mysql_error(). "</b>"; elseif (@mysql_num_rows($result) == 0) echo("<b>Query completed. No results returned. </b><br>"); else { echo "<table border='1'> <thead> <tr>"; for($i = 0;$i < mysql_num_fields($result);$i++) { echo "<th>".mysql_field_name($result,$i). "</th>"; } echo " </tr> </thead> <tbody>"; for ($i = 0; $i < mysql_num_rows($result); $i++) { echo "<tr>"; $row = mysql_fetch_row($result); for($j = 0;$j<mysql_num_fields($result);$j++) { echo("<td>" . $row[$j] . "</td>"); } echo "</tr>"; } echo "</tbody> </table>"; } //end else echo " <hr><br> <form action=\"{$_SERVER['PHP_SELF']}\" method=\"POST\"> <input type='hidden' name='query' value='$query'> <input type='hidden' name='database' value={$_POST['database']}> <input type='submit' name=\"queryButton\" value=\"New Query\"> <input type='submit' name=\"queryButton\" value=\"Edit Query\"> </form>"; unset($form); exit(); } // endif form=yes @$query=stripSlashes($_POST['query']); if (@$_POST['queryButton'] != "Edit Query") { $query = " "; } ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>?form=yes" method="POST"> <table> <tr> <td align=right><b>Type in database name</b></td> <td><input type="text" name="database" value=<?php echo @$_POST['database'] ?> ></td> </tr> <tr> <td align="right" valign="top"> <b>Type in SQL query</b></td> <td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea> </td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit Query"></td> </tr> </table> </form> </body></html> [/code] Link to comment https://forums.phpfreaks.com/topic/34340-problem-with-database-program-code/ Share on other sites More sharing options...
btherl Posted January 16, 2007 Share Posted January 16, 2007 CREATE TABLE uses round brackets "(" not curly brackets "{". I'm also not sure that you can use numbers for your column names. Try this:[code=php:0]CREATE TABLE a (c1 VARCHAR(3),c2 VARCHAR(3),c3 VARCHAR(3),c4 VARCHAR(3),c5 VARCHAR(3),PRIMARY KEY(c1) )[/code] Link to comment https://forums.phpfreaks.com/topic/34340-problem-with-database-program-code/#findComment-161782 Share on other sites More sharing options...
Cannibal_Monkey Posted January 16, 2007 Author Share Posted January 16, 2007 Thanks :) Link to comment https://forums.phpfreaks.com/topic/34340-problem-with-database-program-code/#findComment-162113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.