Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to input numbers into MySQL using php statement
    primarykey
    data
    text
    <p>I am working on a website where an administrator can edit a schedule that they already created. They can click on any item on the schedule to edit it. For example, they can click on the shift start time and then it directs them to a page where they can update the value.</p> <p>Unfortunately, I have not been able to get this to work for every value. It seems to be that the text values are working just fine, but I am getting a syntax error when it is a number.</p> <p>Here is what I am using to update:</p> <pre><code>$type = $_GET['type']; $value = $_GET['value']; $week = $_GET['week']; $newval = $_POST['newval']; if(strlen($newval) &gt; 0) { include '../dbinfo.php'; $type = $mysqli-&gt;real_escape_string($_POST['type']); $week = $mysqli-&gt;real_escape_string($_POST['week']); $tablename = $mysqli-&gt;real_escape_string("cs" . $_SESSION['squadron']); $newval = $mysqli-&gt;real_escape_string($newval); if((is_numeric($newval))) { $sql = "UPDATE $tablename SET $type=$newval WHERE week=$week"; } else { $sql = "UPDATE $tablename SET $type='$newval' WHERE week=$week"; } if($result = $mysqli-&gt;query($sql)) { echo "Your specififed changed was completed successfully!&lt;br&gt;"; echo "&lt;a href='edit.php?week=" . $week . "'&gt;Continue editing&lt;/a&gt;"; } else { echo mysqli_error($result); } } </code></pre> <p>Changing a string results in the sql statement: </p> <pre><code>UPDATE cs14 SET shift_1_name='Test' WHERE week=1 (this works) </code></pre> <p>Changing a number results in the sql statement: </p> <pre><code>UPDATE cs14 SET shift_ 1_starttime=940 WHERE week=1 (this doesn't work) </code></pre> <p>It is giving me the MySQL error: </p> <pre><code>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_starttime=940 WHERE week=1' at line 1 </code></pre> <p>I have already researched this error, and I have checked the syntax over and over again. It doesn't work in phpmyadmin either. I have no idea what to check next!</p> <p>Can anyone help me out with my syntax here??? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload