Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:03:20+00:00 2026-06-12T02:03:20+00:00

if(isset($_POST[‘id’])) { $id=$_POST[‘id’]; echo $id; $busnumber=$_POST[‘busnumber’]; $status=$_POST[‘status’]; $startpoint=$_POST[‘startpoint’]; $stop1=$_POST[‘stop1’]; $stop2=$_POST[‘stop2’]; } I want to

  • 0
if(isset($_POST['id'])) {
    $id=$_POST['id'];
    echo $id;

    $busnumber=$_POST['busnumber'];
    $status=$_POST['status'];
    $startpoint=$_POST['startpoint'];
    $stop1=$_POST['stop1'];
    $stop2=$_POST['stop2'];
}

I want to create dynamic $stop2=$_POST['stop2']; and mysql query:

$sql = mysql_query("
   UPDATE fromto 
   SET busNumber='$busnumber', status='$status', startPoint='$startpoint', 
     stop1='$stop1', stop2='$stop2', stop3='$stop3', stop4='$stop4', 
     stop5='$stop5', stop6='$stop6', stop7='$stop7'............... 
   WHERE id=$id
");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:03:21+00:00Added an answer on June 12, 2026 at 2:03 am

    You need to evaluate all variables to check which are valid SQL fields. In the most general case you might have POST names and SQL names not alike.

    At that point you do not even need to set the variables.

    I added an escape check because, were someone to send you, say,

    '; --
    

    as the value of busNumber, your query would become:

    UPDATE table SET busNumber=''; --', status=...
    

    and since “–” starts a comment, MySQL would see:

    UPDATE table SET busNumber=''; -- *all the rest ignored*
    

    which would then bork the busNumber column in the whole table. You so don’t want this to happen. PDO is a good alternative to mysql_* functions that would help prevent such problems.

    Anyway, you use mysql_*, so:

    $id = (int)$_POST['id'];
    
    $fields = array( // ALL FIELDS EXCEPT ID
       'status' => 'status',
       ...
    );
    
    $update = array();
    // Since we're not using PDO we have to do a small check ourselves
    foreach($fields as $sql => $post)
    {
        if (!isset($_POST[$post]))
            $value = 'NULL';
        else
        {
            // If you want to set the variable:
            // ${$post} = $value;
            // or
            // ${$sql} = $value;
    
            $value = mysql_real_escape($_POST[$post]);
            if (!is_numeric($value))
                $value = "'$value'";
        }
        $update[] = "$sql = $value";
    }
    
    $query = "UPDATE table SET " . implode(',', $update) . " WHERE id=$id";
    
    mysql_query($query);
    

    Moreover, it would be probably useful (performance-wise and maintenance-wise) to normalize the schema by removing the stop* columns and putting them in another table:

    CREATE TABLE busStops {
        id_bus    integer,
        active    boolean,
        seq_no    integer,
        name      varchar(200)
    };
    

    or even

    CREATE TABLE busStops {
        id        integer not null primary key auto_increment,
        name      varchar(200)
        // other geographical information
    };
    
    CREATE TABLE bus_has_stop {
        id_bus    integer,
        id_stop   integer,
        sequenc   integer,
    }
    

    so that if you e.g. renamed a stop from “Street 1 and Street 2” to “Streets 1-2”, the rename would affect automatically all buses with a stop there, and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code: if (isset($_POST['delete']) && isset($_POST['id'])) { $first = get_post('first'); $query =
I am trying to get the following code to work: if (isset($_POST['file'])){ if(file_exists($_POST['file'])){ echo
if (isset($_POST['login'])) { $query = mysql_query(" SELECT id FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."'
Whole code: <?php if (isset($_POST['usname']) && isset($_POST['pasw'])){ $username = mysql_ramznegar($_POST['usname'],$link); $password = mysql_ramznegar($_POST['pasw'],$link); $query
I have the following code presently: if(isset($_POST['Movie'])) { $check = $_POST['Movie']; echo (left angle
here is my scripts. if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo <h1> . File
In form validating,I find such codes if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') { echo CActiveForm::validate($model); Yii::app()->end(); }
if(isset($_POST['uname'])) { $query = SELECT * FROM user_info; $res = $mysqli->query($query); $num = $res->num_rows;
I have: if(isset($_POST['submit'])) { if (empty($name)) { echo'<span class=error>ERROR: Missing Name </span><br/>'; } else
I was wondering, whats the best practice on the example below. <?php if(isset($_POST['query'])){ $out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.