Sean Ford Sean Ford - 1 year ago 59
PHP Question

PHP newbie unsure of mistake. Might be my INSERT?

I am new to PHP. For me PHP was always a plugin or script I could find, but now I have reasons to actually learn it. Anyways. I have this system built for a league on a certain game I like to play, and I have created a page that allows you to create teams. The form functions, and tells me the team is made, but in my database it is nowhere to be seen. I am sure I have messed something up, possibly my INSERT.

Here's a SS of the database tables;

Here's some code;

//insert the row into the database
$query = mysqli_query("INSERT INTO team (Name, Abbreviation) VALUES('$teamname', '$TeamAbbrev')");

//display the success message
successMsg("Team added");
logActivity(onlineUser(), "Added", '$TeamID');


<form method="post" action="<?php echo $PHP_SELF;?>">

<label>Team Name</label><br />
<input type="text" class="text small" name="Name" />

<label>Team Abbreviation</label><br />
<input type="text" class="text small" name="Abbreviation" />

<BR />
<div class="tableactions">
<input type="submit" name="AddTeam" class="submit mid" value="Add Team" />
</div> <!-- .tableactions ends -->


</div> <!-- .block_content ends -->

Answer Source

To query using mysqli you have to pass the connection varible into the mysqli_query function

$link = mysqli_connect("", "my_user", "my_password", "my_db"); 

$query = mysqli_query($link,"INSERT INTO team (Name, Abbreviation) VALUES('$teamname', '$TeamAbbrev')");

Note: learn some security stuff in the web , if you don't sanitize data before inserting it . it will be easy to use sql injection in your script.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download