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

  • Home
  • SEARCH
  • 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 4325370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:15:27+00:00 2026-05-21T09:15:27+00:00

Ok, so im new in php and sql, and I have this form that

  • 0

Ok, so im new in php and sql, and I have this form that submits some names and cities into a database.

I managed to do it, but once a hit the submit button, i get an error:

“Error: 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’ at line 1”

but, when i check in phpmyadmin, the new record is there!!, so im not sure what’s wrong, thats the problem.

this is the code:

<?php
   mysql_connect("localhost", "name", "pass") or die(mysql_error());
   echo "Connection to the server was successful!<br/>";

   mysql_select_db("db_name") or die(mysql_error());
   echo "Database was selected!<br/>";



    $resultComuna = mysql_query("SELECT idComuna, nombre FROM comuna ORDER BY nombre ASC");
    $resultGiro = mysql_query("SELECT idGiro, nombre FROM giro ORDER BY nombre ASC");

?>

<html>
<head>
    <title>TEST</title>
</head>
<body>
    <br/><br/>
    <form name="form" method="POST" action="test_action.php">
        <div align="center">

    <!--/////////////////  input nombre ////////////////////////  -->
            NOMBRE CLIENTE:
            <input name="nombreCliente" type="text" maxlength="30" size="40"></>

    <!-- ///////////////////////////////////////////////////////////// -->

    <!-- ////////////////////drop box para giro ///////////////////// -->
            GIRO:
            <select name="giro">
            <?php
            while($row = mysql_fetch_assoc($resultGiro)){
                echo "<option value=\"".$row['idGiro']."\">".$row['nombre']."</option><br/>";
            }
            ?>      
            </select>
    <!-- ///////////////////////////////////////////////////////////// -->

    <!-- ////////////// dropbox para comunas //////////////////////// -->
            COMUNA:
            <select name="comunas">
            <?php
            while($row = mysql_fetch_assoc($resultComuna)){

                echo "<option value=\"".$row['idComuna']."\">".$row['nombre']."</option><br/>";
            }
            ?>      
            </select>
    <!-- ////////////////////////////////////////////////////////////// -->

        <input type="submit" value="Ingresar"> </>

        </div>
    </form>

</body>
</html>

and the test_action.php is:

<?php
    $con = mysql_connect("localhost", "name", "pass");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("data_base", $con);


$query = mysql_query("SELECT max(idNombre)+1 as id FROM nombre");
$row = mysql_fetch_array($query);
$idMax = $row['id'];


    $sql = mysql_query("INSERT INTO nombre VALUES ('".$idMax."','".$_POST['comunas']."',".$_POST['giro'].",'".$_POST['nombreCliente']."')");

    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "record added";

    mysql_close($con)
?>
  • 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-05-21T09:15:27+00:00Added an answer on May 21, 2026 at 9:15 am

    You’re inserting the ID in single quotes:

    $sql = mysql_query("INSERT INTO nombre VALUES ('".$idMax."','".$_POST['comunas']."',".$_POST['giro'].",'".$_POST['nombreCliente']."')");
    

    Can you provide the table structure? ID is an integer or a varchar there?

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

Sidebar

Related Questions

I have a new web app that is packaged as a WAR as part
I have found this example on StackOverflow: var people = new List<Person> { new
I have a script that appends some rows to a table. One of the
This is beyond both making sense and my control. That being said here is
I would like to update my SQL lite database with the native update-method of
I want to use a temp directory that will be unique to this build.
I have a project that adds elements to an AutoCad drawing. I noticed that
I'm trying to build a Chrome browser extension, that should enhance the way the
I am attempting to pull some information from my tnsnames file using regex. I
IE is giving me an undefined NAN when i try to view the calender...

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.