1

I'm expanding existing code to have an extra row in the database. I've added the row "Base" into the table. Everything but the new row shows up in the database whats going wrong here?

The new row is varchar. I've sniffed the data and all the post data including the base info is in the post data being sent..the problem seems to be in the MySQL query.

This is the old code to enter the data

    $query="INSERT INTO blah1 (UserID, Name, Date, Contact, Note, Izbrisan)
VALUES
('$_POST[userid]','$_POST[name]','$_POST[date]','$_POST[contact]','$_POST[note]',0)";

mysqli_query($query);

this is the new code

    $query="INSERT INTO blah1 (UserID, Name, Date, Contact, Note, Base, Izbrisan)
VALUES
('$_POST[userid]','$_POST[name]','$_POST[date]','$_POST[contact]','$_POST[base]','$_POST[note]',0)";

mysqli_query($query);

here is the form i use to enter the data but the "base" portion of the info never makes it into the database.. whats going wrong here?

<html>
<body>

<center>
<form action="adduser2.php" method="post">


<table border="1">

<td colspan = "2"> <center> Add User</td>

<tr>
<td>UserID:</td>
<td>  <input type="text" name="userid" value="<?php if(isset($_GET['Id'])) { echo $_GET['Id'];}?>" > </td>
</tr>

<tr>
<td>Name:</td>
<td>  <input type="text" name="name">   </td>
</tr>

<tr>
<td>Date(dd:mm:yy):</td>
<td>  <input type="text" name="date">  </td>
</tr>

<tr>
<td>Contact:</td>
<td>  <input type="text" name="contact"> </td>
</tr>

<tr>
<td>Note:</td>
<td>  <input type="text" name="note"> </td>
</tr>

<tr>
<td>Base:</td>
<td>  <input type="text" name="base"> </td>
</tr>

<tr>
<td colspan = "2"> <center> <input type="submit" value="Dodadi Korisnik"> </td>
</tr>

</table>





</form>

</body>
</html>
John Conde
  • 217,595
  • 99
  • 455
  • 496
wethecom
  • 9
  • 5

1 Answers1

1

You forgot the connection identifier for your mysql connection:

mysqli_query($link, $query);

See the documentation.

FYI, you are wide open to SQL injections

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • ^ upvoters too? :D (BTW: OP is using the `$_GET` variable in a if statement + index `Id` where i think he wants `userid` (``)) – Rizier123 Feb 15 '15 at 21:38
  • 1
    I am guessing they have an id in the querystring they are using to populate that variable which *shouldn't* affect what they are doing here. But without seeing more code I could be wrong. – John Conde Feb 15 '15 at 21:56
  • i edited the code i slipped up and put the same code in twice(old vs new)...and the sql injection i wasn't worried about because it is all in a user password secured area – wethecom Feb 15 '15 at 23:10
  • as for $link if thats the conection information i gave it a try $con used in my connection include ...same results ...base variables dose not go into the database.. – wethecom Feb 15 '15 at 23:27
  • what code are you looking to see? the only other code is connection information that worked fine and still works except the 1 base variable does not go into the database...my guess is maybe a setting about the variable in mysql is just making it null but its set to"Base" varchar(50) default none utf8_unicode_ci same as the majority of other variables – wethecom Feb 15 '15 at 23:33
  • ()) works fine and is not apart of the problem ,if the page script get called and there is a id in the $_GET['Id'] it auto fills it in – wethecom Feb 15 '15 at 23:40
  • here is some sample posted data captured by sniffing it userid=3421&name=wethecom&date=10.01.2015&contact=wethecom%40blah.com&note=+my+note&base=trtyy it has to do with mysql query or beyond the post data makes it threw – wethecom Feb 16 '15 at 00:09
  • im using a parallel scripts to do this in the form it is going to adduser.php when it should be going to adduser2.php...not sure why yet but that would answer alot of this – wethecom Feb 16 '15 at 00:23
  • the add user form was not properly updated and contained adduser.php instead of adduser2.php....is it possible to delete this question or should i leave it here ..this was entirely user error..the latest code never got put on the server – wethecom Feb 16 '15 at 00:30