thewarchief Posted October 19, 2009 Share Posted October 19, 2009 Hello, my friends and I are attempting to write some PHP code. We have never done this before and are essentially teaching ourselves. We are trying to write: <form id="formTextBox1" name="form1TextBox1" method="post" action=""> <INPUT type="text" value="" name"txtInput" id="txtInput" /> <?php session_start(); extract($_POST); print($txtInput); $linkTextBox1 = mysql_pconnect("pdb2.awardspace.com", "albert123_lotto", "lotto") or die("pconnectfailed!" .mysql_error()); mysql_select_db("albert123_lotto", $linkTextBox1) or die("unable to select db" .mysql_error()); $sqlTextBox1 = "UPDATE store_'.$store_num.'_inv SET serialStart = '$txtInput' WHERE lottoName = '$selectResult'"; $resultTextBox1 = mysql_query($sqlTextBox1, $linkTextBox1); if(!$resultTextBox1){ echo mysql_error(); exit; } mysql_free_result($resultTextBox1); mysql_close(); ?> </SELECT> </FORM> and nothing will show up on the page. I am fairly certain that it has to do with this line: $sqlTextBox1 = "UPDATE store_'.$store_num.'_inv SET serialStart = '$txtInput' WHERE lottoName = '$selectResult'"; More specifically, I am unsure if we are able to use a variable in the middle of a table name. Thank you for any information given. Link to comment https://forums.phpfreaks.com/topic/178184-solved-can-i-do-this/ Share on other sites More sharing options...
btherl Posted October 19, 2009 Share Posted October 19, 2009 Yes you can use a variable in a table name but you should do it in one of these ways: $sqlTextBox1 = "UPDATE store_".$store_num."_inv SET serialStart = '$txtInput' WHERE lottoName = '$selectResult'"; $sqlTextBox1 = "UPDATE store_{$store_num}_inv SET serialStart = '$txtInput' WHERE lottoName = '$selectResult'"; The reason it won't work the same way as your other variables there is that the "_" character within the table name confuses php. The {} symbols protect the variable so it can be placed next to an underscore and not confuse php. BTW, having a table for each store number is almost certainly bad database design. It's usually better to have store number as a column in your table. Link to comment https://forums.phpfreaks.com/topic/178184-solved-can-i-do-this/#findComment-939483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.