Ch0cu3r Posted September 6, 2014 Share Posted September 6, 2014 You are not generating the <option>'s correctly. It should be while ($row = mysqli_fetch_array($result)) { echo '<option>'.$row[0].'</option>'; } Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 6, 2014 Share Posted September 6, 2014 and please use the forum's bbcode tags (the edit form's <> button) around code when posting it in the forum. Quote Link to comment Share on other sites More sharing options...
JpGemo Posted September 6, 2014 Author Share Posted September 6, 2014 (edited) well when I echo the $_POST['selform'] from the processing page, it echo's the value I submitted from the form, regardless which option I choose it echo's the result I intend it to, so it should be how I have written the option code Edited September 6, 2014 by JpGemo Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 6, 2014 Share Posted September 6, 2014 Do a view source to your browser: $row[0] = 'head'; echo "<select>"; echo '("<option value="'; echo ($row[0]),'</br>'; echo '</br>">'; echo ($row[0]),'</br>'; echo '</option>")'; echo "</select>"; Result of value is: "head</br></br>" Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 6, 2014 Share Posted September 6, 2014 programming is an exact science. the values you are producing in your <option > tags are not just the table name, they contain html <br> tags as part of the value. when you echo <br> tags to a browser what do you see? white-space, specifically a new-line. people with thousands of posts and years of experience wouldn't have told you that the form has a problem if it didn't. Quote Link to comment Share on other sites More sharing options...
JpGemo Posted September 6, 2014 Author Share Posted September 6, 2014 (edited) alright, I changed my option tags and that has removed the </br> tags from the posting form, but the </br> is there in the processing script, how can I remove that then EDIT: The </br> isn't appearing, however the data from the tables isn't appearing either Edited September 6, 2014 by JpGemo Quote Link to comment Share on other sites More sharing options...
JpGemo Posted September 6, 2014 Author Share Posted September 6, 2014 (edited) This is how the script looks now, this is the form script <?php //connect include 'connect.php'; //head include 'head.php'; //list table process $form = $_POST['selform']; $sql = "SHOW TABLES FROM $db_name"; $result = mysqli_query($con,$sql); //formtable echo '<form id="form1" name="form1" method="post" action="/BYO/formprocessing.php"> <table> <tr> <td><select name = "selform" id = "selform">'; //list tables while ($row = mysqli_fetch_array($result)) { echo '<option>'.$row[0].'</option>'; } //formtable 2 echo '</select>'; echo '</td> </tr> <tr> <td><input type="submit" name="Submit" value="Register"/> </td> </tr> </table>'; ?> this is the processing script <?php //connect include 'connect.php'; //head include 'head.php'; //processing $table = $_POST["selform"]; $sql = 'SELECT * FROM '.$table ; echo $sql; $result = mysqli_query($con,$sql); if(!$result) echo("Error result: " . mysqli_error($con)); exit; while ($row = mysqli_fetch_array($result)) echo $row['value1']; echo $row['value2']; ?> the error message has disappeared now, however the table data isn't being echo'd either Edited September 6, 2014 by JpGemo Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 6, 2014 Share Posted September 6, 2014 Using the code suggested by me earlier will not submit any <br />'s only the table name will be submitted. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 6, 2014 Share Posted September 6, 2014 (edited) Try, while ($row = mysqli_fetch_array($result,MYSQLI_NUM)) { echo "<option value=$row[0]>".$row[0]."</option>"; } Edited September 6, 2014 by jazzman1 Quote Link to comment Share on other sites More sharing options...
Solution JpGemo Posted September 6, 2014 Author Solution Share Posted September 6, 2014 That worked Ch0cu3r Thank You everyone, the code is working exactly the way I wanted it to now, Sorry for being so much of a Noob, I have spotty internet here, and noone I know, knows anything to do with web design, so I have to teach myself everything, so I often have to spend hours on my codes getting to work correctly, but I likely never wouldve worked this one out without everyones help. Thanks against Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 6, 2014 Share Posted September 6, 2014 the while(){} loop in your code is - a) incomplete, it is only echoing the first line. you should always use opening and closing { } in conditional statements. b) it's unlikely that you have a column named value1, value2.. if your purpose is to loop over any/all columns that the query selected, you would do just that. $row is an array. use a foreach(){} loop to loop over and echo each element in the array. Quote Link to comment Share on other sites More sharing options...
JpGemo Posted September 6, 2014 Author Share Posted September 6, 2014 Yer, mac, I worked out the {} part in the code, after changing my result code back to what was suggested at the start of the forum, and those changes fixed it (and yer, value1 and value2 is what I set the columns to for the purpose of getting my script right) but the script is working completely the way I was aiming for it to work, so thanks everyone Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.