Jump to content

How can I fix this code/


JpGemo
Go to solution Solved by JpGemo,

Recommended Posts

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 by JpGemo
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by JpGemo
Link to comment
Share on other sites

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 by JpGemo
Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.